pub trait Bifunctor<F, A, B>where
F: HKT2<T<A, B> = Self>,{
// Required method
fn bimap<A2, B2, FA, FB>(self, fa: FA, fb: FB) -> F::T<A2, B2>
where FA: F1<A, Ret = A2>,
FB: F1<B, Ret = B2>;
// Provided methods
fn lmap<A2, FA>(self, fa: FA) -> F::T<A2, B>
where Self: Sized,
FA: F1<A, Ret = A2> { ... }
fn rmap<B2, FB>(self, fb: FB) -> F::T<A, B2>
where Self: Sized,
FB: F1<B, Ret = B2> { ... }
fn join(self) -> Join<F, Self, A>
where Self: Sized,
F: HKT2<T<A, A> = Self> { ... }
}
Expand description
A Bifunctor provides a map
function for types with 2 parameters,
allowing you to act on both types at once.
Additionally, Bifunctor provides lmap
and rmap
which allow you to
unambiguously map only one of the types.
use std::io;
use std::path::PathBuf;
use naan::prelude::*;
fn get_some_meaningful_filepath() -> io::Result<String> {
}
// in one shot we turn `Result<String, io::Error>` into `Result<PathBuf, String>`.
get_some_meaningful_filepath().bimap(|ok| PathBuf::from(ok), |err| format!("{err:?}"));
Required Methods§
Provided Methods§
sourcefn lmap<A2, FA>(self, fa: FA) -> F::T<A2, B>where
Self: Sized,
FA: F1<A, Ret = A2>,
fn lmap<A2, FA>(self, fa: FA) -> F::T<A2, B>where Self: Sized, FA: F1<A, Ret = A2>,
Map the left type in the Bifunctor
In Result, this maps the “Ok” type and is equivalent to map
.