1pub trait IterUtilsExt: Iterator {
2 fn ex_find_map<F, R>(&mut self, mut f: F) -> Option<R>
5 where
6 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
20 F: FnMut(Self::Item) -> Option<R>,
21 Self: DoubleEndedIterator,
22 {
23 while let Some(elt) = self.next_back() {
24 if let result @ Some(_) = f(elt) {
25 return result;
26 }
27 }
28 None
29 }
30}
31
32impl<I> IterUtilsExt for I where I: Iterator {}