Trait Functor

Source
pub trait Functor<A, B>: Lift<A, B> {
    // Required method
    fn map<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
       where F: Fn(A) -> B;
}
Expand description

A Functor lets you change the type parameter of a generic type.

A Functor defines a method map on a type F<_>: Functor which converts an F<A> to F<B> using a function Fn(A) -> B applied to the As inside it.

You can also use this just to modify the values inside your container value without changing their type, if the mapping function returns a value of the same type. This is called an “endofunctor.”

Required Methods§

Source

fn map<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
where F: Fn(A) -> B,

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> Functor<A, B> for Option<A>

Source§

fn map<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
where F: Fn(A) -> B,

Source§

impl<A, B> Functor<A, B> for BinaryHeap<A>
where A: Ord, B: Ord,

Source§

fn map<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
where F: Fn(A) -> B,

Source§

impl<A, B> Functor<A, B> for BTreeSet<A>
where A: Ord, B: Ord,

Source§

fn map<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
where F: Fn(A) -> B,

Source§

impl<A, B> Functor<A, B> for LinkedList<A>

Source§

fn map<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
where F: Fn(A) -> B,

Source§

impl<A, B> Functor<A, B> for VecDeque<A>

Source§

fn map<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
where F: Fn(A) -> B,

Source§

impl<A, B> Functor<A, B> for Vec<A>

Source§

fn map<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
where F: Fn(A) -> B,

Source§

impl<A, B, C, D> Functor<(A, B), (C, D)> for BTreeMap<A, B>
where A: Ord, B: Ord, C: Ord, D: Ord,

Source§

fn map<F>(self, f: F) -> <Self as Lift<(A, B), (C, D)>>::Target1
where F: Fn((A, B)) -> (C, D),

Source§

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

Source§

fn map<F>(self, f: F) -> <Self as Lift<(A, B), (C, D)>>::Target1
where F: Fn((A, B)) -> (C, D),

Source§

impl<A, B, E> Functor<A, B> for Result<A, E>

Source§

fn map<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
where F: Fn(A) -> B,

Source§

impl<A, B, S> Functor<A, B> for HashSet<A, S>
where A: Hash + Eq, B: Hash + Eq, S: BuildHasher + Default,

Source§

fn map<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
where F: Fn(A) -> B,

Implementors§