Skip to main content

Functor

Trait Functor 

Source
pub trait Functor<'a, A> {
    type Target<T>;

    // Required method
    fn fmap<B, F>(self, f: F) -> Self::Target<B>
       where F: Fn(A) -> B + 'a;
}
Expand description

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

A Functor defines a method fmap 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 Associated Types§

Source

type Target<T>

Required Methods§

Source

fn fmap<B, F>(self, f: F) -> Self::Target<B>
where F: Fn(A) -> B + 'a,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<A, E> Functor<'_, A> for Result<A, E>

Source§

type Target<T> = Result<T, E>

Source§

fn fmap<B, F>(self, f: F) -> Self::Target<B>
where F: Fn(A) -> B,

Source§

impl<A> Functor<'_, A> for LinkedList<A>

Available on crate feature std only.
Source§

type Target<T> = LinkedList<T>

Source§

fn fmap<B, F>(self, f: F) -> Self::Target<B>
where F: Fn(A) -> B,

Source§

impl<A> Functor<'_, A> for Option<A>

Source§

type Target<T> = Option<T>

Source§

fn fmap<B, F>(self, f: F) -> Self::Target<B>
where F: Fn(A) -> B,

Source§

impl<A> Functor<'_, A> for Vec<A>

Available on crate feature std only.
Source§

type Target<T> = Vec<T>

Source§

fn fmap<B, F>(self, f: F) -> Self::Target<B>
where F: Fn(A) -> B,

Source§

impl<A> Functor<'_, A> for VecDeque<A>

Available on crate feature std only.
Source§

type Target<T> = VecDeque<T>

Source§

fn fmap<B, F>(self, f: F) -> Self::Target<B>
where F: Fn(A) -> B,

Implementors§

Source§

impl<'a, A: 'a, E: 'a> Functor<'a, A> for IO<'a, A, E>

Source§

type Target<T> = IO<'a, T, E>

Source§

impl<'a, A> Functor<'a, A> for Effect<'a, A>
where A: 'a,

Source§

type Target<T> = Effect<'a, T>