[][src]Trait funlib::Applicative

pub trait Applicative<B>: Functor<B> {
    fn pure_(value: B) -> Self::M
    where
        Self: HKT<B, A = B>
;
fn ap<F>(&self, f: Self::M) -> Self::M
    where
        F: Fn(&Self::A) -> B,
        Self: HKT<F>
; }

Applicative type class

Required methods

fn pure_(value: B) -> Self::M where
    Self: HKT<B, A = B>, 

Lift values into the context of the Functor

Examples

use funlib::Applicative;
let s1 = Option::<i8>::pure_(10);
let s2 = Option::pure_("hi");
let v = Vec::pure_(1);

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

Apply function is almost the same as Functor map. but the function isn't A => B but A<F => B>

Examples

use funlib::Applicative;
fn double(i: &i32) -> i32 { i * 2  }
let f: &dyn Fn(&i32) -> i32 = &|x| x * 2;
assert_eq!(Some(4), Some(2).ap(Some(f)));
assert_eq!(Some(4), Some(2).ap(Some(&double)));
Loading content...

Implementations on Foreign Types

impl<A, B> Applicative<B> for Option<A>[src]

impl<A, B> Applicative<B> for Box<A>[src]

impl<A, B> Applicative<B> for Rc<A>[src]

impl<A, B> Applicative<B> for Vec<A>[src]

Loading content...

Implementors

Loading content...