1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::prelude::Applicative;

impl<'a, A> Applicative<'a, A> for Vec<A>
where
    A: Clone + 'a,
{
    type PureT<T> = Vec<T> where T: 'a ;

    fn pure(a: Self::PureT<A>) -> Self::Type<Self::PureT<A>> {
        vec![a]
    }

    fn app<F, B>(self, f: Self::Type<F>) -> Self::Type<B>
    where
        F: Fn(A) -> B + 'a,
        B: 'a,
    {
        f.into_iter()
            .flat_map(|f| self.clone().into_iter().map(f))
            .collect::<Self::Type<B>>()
    }
}