Skip to content

Commit

Permalink
Itertools::find_position: use find
Browse files Browse the repository at this point in the history
`find` usually rely on `try_fold` so this change should improve performance for iterators specializing `find/try_fold`.

Co-Authored-By: Marcel Hellwig <[email protected]>
Co-Authored-By: phimuemue <[email protected]>
  • Loading branch information
3 people committed Jan 10, 2024
1 parent c5a1b16 commit fac3294
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1910,12 +1910,7 @@ pub trait Itertools: Iterator {
where
P: FnMut(&Self::Item) -> bool,
{
for (index, elt) in self.enumerate() {
if pred(&elt) {
return Some((index, elt));
}
}
None
self.enumerate().find(|(_, elt)| pred(elt))
}
/// Find the value of the first element satisfying a predicate or return the last element, if any.
///
Expand Down

0 comments on commit fac3294

Please sign in to comment.