pub trait Invariant<B>: Higher {
// Required method
fn imap<F, G>(self, f: F, g: G) -> Self::Target<B>
where F: FnMut(Self::Param) -> B,
G: FnMut(B) -> Self::Param;
}
Expand description
Invariant functor (also known as exponential functor).
Required Methods§
sourcefn imap<F, G>(self, f: F, g: G) -> Self::Target<B>where
F: FnMut(Self::Param) -> B,
G: FnMut(B) -> Self::Param,
fn imap<F, G>(self, f: F, g: G) -> Self::Target<B>where F: FnMut(Self::Param) -> B, G: FnMut(B) -> Self::Param,
Transform a Self<A>
into a Self<B>
by providing a transformation from A
to B
and one from B
to A
.
Examples
use rust2fun::prelude::*;
let x = Some("1".to_string());
let actual = x.imap(|s| s.parse::<i32>().unwrap(), |i| i.to_string());
assert_eq!(Some(1), actual);