Trait Invariant

Source
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§

Source

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);

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.

Implementations on Foreign Types§

Source§

impl<A, B> Invariant<B> for PhantomData<A>

Source§

fn imap<F, G>(self, _f: F, _g: G) -> PhantomData<B>
where F: FnMut(A) -> B, G: FnMut(B) -> A,

Source§

impl<A, B, K: Hash + Eq> Invariant<B> for HashMap<K, A>

Source§

fn imap<F, G>(self, f: F, _g: G) -> HashMap<K, B>
where F: FnMut(A) -> B, G: FnMut(B) -> A,

Source§

impl<B, T> Invariant<B> for Option<T>

Source§

fn imap<F, G>(self, f: F, _g: G) -> Self::Target<B>
where F: FnMut(Self::Param) -> B, G: FnMut(B) -> Self::Param,

Source§

impl<B, T> Invariant<B> for Box<T>

Source§

fn imap<F, G>(self, f: F, _g: G) -> Self::Target<B>
where F: FnMut(Self::Param) -> B, G: FnMut(B) -> Self::Param,

Source§

impl<B, T> Invariant<B> for LinkedList<T>

Source§

fn imap<F, G>(self, f: F, _g: G) -> Self::Target<B>
where F: FnMut(Self::Param) -> B, G: FnMut(B) -> Self::Param,

Source§

impl<B, T> Invariant<B> for VecDeque<T>

Source§

fn imap<F, G>(self, f: F, _g: G) -> Self::Target<B>
where F: FnMut(Self::Param) -> B, G: FnMut(B) -> Self::Param,

Source§

impl<B, T> Invariant<B> for Vec<T>

Source§

fn imap<F, G>(self, f: F, _g: G) -> Self::Target<B>
where F: FnMut(Self::Param) -> B, G: FnMut(B) -> Self::Param,

Source§

impl<B, T, E> Invariant<B> for Result<T, E>

Source§

fn imap<F, G>(self, f: F, _g: G) -> Self::Target<B>
where F: FnMut(Self::Param) -> B, G: FnMut(B) -> Self::Param,

Source§

impl<B: Ord, T> Invariant<B> for BinaryHeap<T>

Source§

fn imap<F, G>(self, f: F, _g: G) -> Self::Target<B>
where F: FnMut(Self::Param) -> B, G: FnMut(B) -> Self::Param,

Source§

impl<B: Ord, T> Invariant<B> for BTreeSet<T>

Source§

fn imap<F, G>(self, f: F, _g: G) -> Self::Target<B>
where F: FnMut(Self::Param) -> B, G: FnMut(B) -> Self::Param,

Source§

impl<B: Hash + Eq, T> Invariant<B> for HashSet<T>

Source§

fn imap<F, G>(self, f: F, _g: G) -> Self::Target<B>
where F: FnMut(Self::Param) -> B, G: FnMut(B) -> Self::Param,

Implementors§

Source§

impl<B, T> Invariant<B> for NEVec<T>

Source§

impl<B, T, E> Invariant<B> for Validated<T, E>