higher_cat/
extend.rs

1use crate::Functor;
2use higher::Lift;
3
4/// `Extend` is the opposite of `Bind`.
5pub trait Extend<A, B>: Functor<A, B> + Sized {
6    fn extend<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
7    where
8        F: Fn(Self) -> B;
9}
10
11impl<A, B> Extend<A, B> for Vec<A>
12where
13    A: Clone,
14{
15    fn extend<F>(self, f: F) -> <Self as Lift<A, B>>::Target1
16    where
17        F: Fn(Self) -> B,
18    {
19        (0..self.len())
20            .map(|index| f(self.iter().skip(index).cloned().collect()))
21            .collect()
22    }
23}