Skip to content

Commit a6e9713

Browse files
Merge #366
366: partition_map: loosened Fn to FnMut; replaced `for` by `for_each` r=jswrenn a=danielhenrymantilla - the `Fn` bound was not necessary; - `.for_each` and internal iteration can be more efficient than `for` loops with, for instance, `.chain`ed iterators. Co-authored-by: Daniel Henry-Mantilla <[email protected]>
2 parents 40cf58c + 521938f commit a6e9713

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/lib.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1997,21 +1997,19 @@ pub trait Itertools : Iterator {
19971997
/// assert_eq!(successes, [1, 2]);
19981998
/// assert_eq!(failures, [false, true]);
19991999
/// ```
2000-
fn partition_map<A, B, F, L, R>(self, predicate: F) -> (A, B)
2000+
fn partition_map<A, B, F, L, R>(self, mut predicate: F) -> (A, B)
20012001
where Self: Sized,
2002-
F: Fn(Self::Item) -> Either<L, R>,
2002+
F: FnMut(Self::Item) -> Either<L, R>,
20032003
A: Default + Extend<L>,
20042004
B: Default + Extend<R>,
20052005
{
20062006
let mut left = A::default();
20072007
let mut right = B::default();
20082008

2009-
for val in self {
2010-
match predicate(val) {
2011-
Either::Left(v) => left.extend(Some(v)),
2012-
Either::Right(v) => right.extend(Some(v)),
2013-
}
2014-
}
2009+
self.for_each(|val| match predicate(val) {
2010+
Either::Left(v) => left.extend(Some(v)),
2011+
Either::Right(v) => right.extend(Some(v)),
2012+
});
20152013

20162014
(left, right)
20172015
}

0 commit comments

Comments
 (0)