1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
use crate::traits::Applicative;
impl<'a, A> Applicative<'a, A> for Option<A>
where
A: 'a,
{
type PureT<T> = T where T: 'a ;
fn pure(a: Self::PureT<A>) -> Self::Type<Self::PureT<A>> {
Some(a)
}
fn app<F, B>(self, f: Self::Type<F>) -> Self::Type<B>
where
F: Fn(A) -> B,
{
f.and_then(|f| self.map(f))
}
}