1
2pub trait IterUtilsExt : Iterator {
3 fn ex_find_map<F, R>(&mut self, mut f: F) -> Option<R>
6 where F: FnMut(Self::Item) -> Option<R>
7 {
8 for elt in self {
9 if let result @ Some(_) = f(elt) {
10 return result;
11 }
12 }
13 None
14 }
15
16 fn ex_rfind_map<F, R>(&mut self, mut f: F) -> Option<R>
19 where F: FnMut(Self::Item) -> Option<R>,
20 Self: DoubleEndedIterator,
21 {
22 while let Some(elt) = self.next_back() {
23 if let result @ Some(_) = f(elt) {
24 return result;
25 }
26 }
27 None
28 }
29}
30
31impl<I> IterUtilsExt for I where I: Iterator { }