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