Trait Functor

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

Functor type class

Required Methods§

Source

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

Functor map

§Examples
use funlib::Functor;
let n = Some(1).fmap(|i| i * 4);
assert_eq!(Some(4), n);

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§