File tree Expand file tree Collapse file tree 1 file changed +4
-9
lines changed Expand file tree Collapse file tree 1 file changed +4
-9
lines changed Original file line number Diff line number Diff line change @@ -1742,18 +1742,13 @@ pub trait Itertools : Iterator {
1742
1742
/// assert_eq!(numbers.iter().find_or_last(|&&x| x > 2), Some(&3));
1743
1743
/// assert_eq!(std::iter::empty::<i32>().find_or_last(|&x| x > 5), None);
1744
1744
/// ```
1745
- fn find_or_last < P > ( mut self , predicate : P ) -> Option < Self :: Item >
1745
+ fn find_or_last < P > ( mut self , mut predicate : P ) -> Option < Self :: Item >
1746
1746
where Self : Sized ,
1747
1747
P : FnMut ( & Self :: Item ) -> bool ,
1748
1748
{
1749
- #[ inline]
1750
- fn check < T > ( mut predicate : impl FnMut ( & T ) -> bool ) -> impl FnMut ( Option < T > , T ) -> Result < Option < T > , T > {
1751
- move |_, x| {
1752
- if predicate ( & x) { Result :: Err ( x) } else { Result :: Ok ( Some ( x) ) }
1753
- }
1754
- }
1755
-
1756
- self . try_fold ( None , check ( predicate) ) . unwrap_or_else ( Some )
1749
+ let mut prev = None ;
1750
+ self . find_map ( |x| if predicate ( & x) { Some ( x) } else { prev = Some ( x) ; None } )
1751
+ . or ( prev)
1757
1752
}
1758
1753
/// Returns `true` if the given item is present in this iterator.
1759
1754
///
You can’t perform that action at this time.
0 commit comments