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

Implementations on Foreign Types§

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,

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 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<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<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<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 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: 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, 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, 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, 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,

Implementors§

source§

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

source§

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