pub trait Apply<A, B>: Functor<B> {
// Required method
fn ap(self, fa: Self::Target<A>) -> Self::Target<B>
where Self::Param: FnMut(A) -> B;
}
Expand description
Weaker version of Applicative has apply but not pure.
Required Methods§
sourcefn ap(self, fa: Self::Target<A>) -> Self::Target<B>where
Self::Param: FnMut(A) -> B,
fn ap(self, fa: Self::Target<A>) -> Self::Target<B>where Self::Param: FnMut(A) -> B,
Apply a function in a context to a value in a context.
Examples
use rust2fun::prelude::*;
let ff = Some(|x: i32| x.to_string());
assert_eq!(Some("1".to_string()), ff.ap(Some(1)));
assert_eq!(Some("2".to_string()), ff.ap(Some(2)));
let ff = vec![|x| x + 1, |x| x + 2];
let fa = vec![3, 4];
let actual = ff.ap(fa);
assert_eq!(actual, [4, 5, 5, 6]);