From fac329470af67707c8924eb9dd4c1d369b1d4e83 Mon Sep 17 00:00:00 2001 From: Philippe-Cholet Date: Wed, 10 Jan 2024 14:40:38 +0100 Subject: [PATCH] `Itertools::find_position`: use `find` `find` usually rely on `try_fold` so this change should improve performance for iterators specializing `find/try_fold`. Co-Authored-By: Marcel Hellwig Co-Authored-By: phimuemue <157728+phimuemue@users.noreply.github.com> --- src/lib.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 211827ff2..b2641d19d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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. ///