[−][src]Trait funlib::Applicative
Applicative type class
Required methods
fn pure_(value: B) -> Self::M where
Self: HKT<B, A = B>,
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>,
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)));