Bifunctor

Trait Bifunctor 

Source
pub trait Bifunctor<A, B, C, D>: Bilift<A, B, C, D> {
    // Required method
    fn bimap<L, R>(
        self,
        left: L,
        right: R,
    ) -> <Self as Bilift<A, B, C, D>>::Target
       where L: Fn(A) -> C,
             R: Fn(B) -> D;
}
Expand description

A Bifunctor lets you change the types of a generic type with two type parameters.

A Bifunctor works just like a Functor, but for types with two type parameters. It will convert a F<_, _>: Bifunctor from F<A, B> to F<C, D> using two functions, one Fn(A) -> C and the other Fn(B) -> D.

Required Methods§

Source

fn bimap<L, R>(self, left: L, right: R) -> <Self as Bilift<A, B, C, D>>::Target
where L: Fn(A) -> C, R: Fn(B) -> D,

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, C, D> Bifunctor<A, B, C, D> for Result<A, B>

Source§

fn bimap<L, R>(self, left: L, right: R) -> <Self as Bilift<A, B, C, D>>::Target
where L: Fn(A) -> C, R: Fn(B) -> D,

Source§

impl<A, B, C, D> Bifunctor<A, B, C, D> for BTreeMap<A, B>
where A: Ord, C: Ord,

Source§

fn bimap<L, R>(self, left: L, right: R) -> <Self as Bilift<A, B, C, D>>::Target
where L: Fn(A) -> C, R: Fn(B) -> D,

Source§

impl<A, B, C, D, S> Bifunctor<A, B, C, D> for HashMap<A, B, S>
where A: Eq + Hash, C: Eq + Hash, S: BuildHasher + Default,

Source§

fn bimap<L, R>(self, left: L, right: R) -> <Self as Bilift<A, B, C, D>>::Target
where L: Fn(A) -> C, R: Fn(B) -> D,

Implementors§