Skip to main content

orx_iterable/transformations/
filter_mapped.rs

1use crate::Iterable;
2
3/// Wraps an `Iterable` and creates a new `Iterable` which filters-and-maps the elements
4/// of the original iterable.
5pub struct FilterMapped<I, M, U>
6where
7    I: Iterable,
8    M: Fn(I::Item) -> Option<U> + Copy,
9{
10    pub(crate) it: I,
11    pub(crate) filter_map: M,
12}
13
14impl<I, M, U> Iterable for FilterMapped<I, M, U>
15where
16    I: Iterable,
17    M: Fn(I::Item) -> Option<U> + Copy,
18{
19    type Item = U;
20
21    type Iter = core::iter::FilterMap<I::Iter, M>;
22
23    fn iter(&self) -> Self::Iter {
24        self.it.iter().filter_map(self.filter_map)
25    }
26}