orx_iterable/transformations/mapped_while.rs
1use crate::Iterable;
2
3/// Wraps an `Iterable` and creates a new `Iterable` which maps the elements of
4/// the original iterable as long as the map-while condition is satisfied.
5pub struct MappedWhile<I, M, U>
6where
7 I: Iterable,
8 M: Fn(I::Item) -> Option<U> + Copy,
9{
10 pub(crate) it: I,
11 pub(crate) map_while: M,
12}
13
14impl<I, M, U> Iterable for MappedWhile<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::MapWhile<I::Iter, M>;
22
23 fn iter(&self) -> Self::Iter {
24 self.it.iter().map_while(self.map_while)
25 }
26}