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

/// `Extend` is the opposite of `Bind`.
pub trait Extend<A, B>: Functor<A, B> + Sized {
    fn extend<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
    where
        F: Fn(Self) -> B;
}

impl<A, B> Extend<A, B> for Vec<A>
where
    A: Clone,
{
    fn extend<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
    where
        F: Fn(Self) -> B,
    {
        (0..self.len())
            .map(|index| f(self.iter().skip(index).cloned().collect()))
            .collect()
    }
}