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>
fn imap<F, G>(self, f: F, g: G) -> Self::Target<B>
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);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.