keepops/
keep_map_single_iterator.rs1use crate::keep_map_single::KeepMapSingle;
2use crate::tuple_family::RunSingle;
3
4#[derive(Clone)]
5pub struct KeepMap<I, F> {
6 pub(crate) iter: I,
7 f: F,
8}
9
10impl<B, I: Iterator, F> Iterator for KeepMap<I, F>
11where
12 F: FnMut(&I::Item) -> B,
13{
14 type Item = RunSingle<I::Item, B>;
15 fn next(&mut self) -> Option<Self::Item> {
16 self.iter.next().keep_map(&mut self.f)
17 }
18}
19
20pub trait KeepMapSingleIteratorExtension: Iterator {
21 fn keep_map<F, B>(self, f: F) -> KeepMap<Self, F>
22 where
23 F: FnMut(&Self::Item) -> B,
24 Self: Sized,
25 {
26 KeepMap { iter: self, f }
27 }
28}
29
30impl<I: Iterator> KeepMapSingleIteratorExtension for I {}