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 <ghpub@cookiesoft.de>
Co-Authored-By: phimuemue <157728+phimuemue@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 10, 2024
1 parent c5a1b16 commit cd6bd87
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/lib.rs
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 cd6bd87

Please sign in to comment.