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

Applicative type class

Required methods

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);

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)));

Implementations on Foreign Types

Implementors