1use super::*;
2
3pub trait FilterFn {
4 type Input;
5 type Output;
6 fn map(&self, input: Self::Input) -> Option<Self::Output>;
8}
9
10pub struct FilterWrap<F: FilterFn>(pub F);
11
12impl<F: FilterFn> FlatMapFn for FilterWrap<F> {
13 type Input = F::Input;
14 type OutputList = Option<F::Output>;
15 fn map(&self, input: Self::Input) -> Self::OutputList {
16 self.0.map(input)
17 }
18}
19
20pub trait Filter: ListFn {
21 fn filter<F: FilterFn<Input = Self::Item>>(self, f: F) -> FlatMapList<Self, FilterWrap<F>> {
22 self.flat_map(FilterWrap(f))
23 }
24}
25
26impl<L: ListFn> Filter for L {}