1pub trait IterUtilsExt: Iterator {
2/// Return the first element that maps to `Some(_)`, or None if the iterator
3 /// was exhausted.
4fn ex_find_map<F, R>(&mut self, mut f: F) -> Option<R>
5where
6F: FnMut(Self::Item) -> Option<R>,
7 {
8for elt in self {
9if let result @ Some(_) = f(elt) {
10return result;
11 }
12 }
13None
14}
1516/// Return the last element from the back that maps to `Some(_)`, or
17 /// None if the iterator was exhausted.
18fn ex_rfind_map<F, R>(&mut self, mut f: F) -> Option<R>
19where
20F: FnMut(Self::Item) -> Option<R>,
21Self: DoubleEndedIterator,
22 {
23while let Some(elt) = self.next_back() {
24if let result @ Some(_) = f(elt) {
25return result;
26 }
27 }
28None
29}
30}
3132impl<I> IterUtilsExt for I where I: Iterator {}