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