Trait Functor

Source
pub trait Functor<U>: HKT<U> {
    // Required method
    fn fmap<F>(&self, f: F) -> Self::T
       where F: Fn(&Self::C) -> U;
}
Expand description

§Functor

Formally, a functor describes the morphisms between categories.

A functor is a type that when mapped over, preserves the structure of the type while applying a function to the values within the type. Functors are useful for modeling the functional effects on values of parameterized data types.

Required Methods§

Source

fn fmap<F>(&self, f: F) -> Self::T
where F: Fn(&Self::C) -> U,

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<T, U> Functor<U> for Option<T>

Source§

fn fmap<F>(&self, f: F) -> Option<U>
where F: Fn(&T) -> U,

Source§

impl<T, U> Functor<U> for Box<T>

Source§

fn fmap<F>(&self, f: F) -> Box<U>
where F: Fn(&T) -> U,

Source§

impl<T, U> Functor<U> for Rc<T>

Source§

fn fmap<F>(&self, f: F) -> Rc<U>
where F: Fn(&T) -> U,

Source§

impl<T, U> Functor<U> for Arc<T>

Source§

fn fmap<F>(&self, f: F) -> Arc<U>
where F: Fn(&T) -> U,

Source§

impl<T, U> Functor<U> for Vec<T>

Source§

fn fmap<F>(&self, f: F) -> Vec<U>
where F: Fn(&T) -> U,

Implementors§