Skip to content

Commit

Permalink
partition_map: loosened Fn to FnMut; replaced for by for_each
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhenrymantilla committed Aug 29, 2019
1 parent 40cf58c commit 521938f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1997,21 +1997,19 @@ pub trait Itertools : Iterator {
/// assert_eq!(successes, [1, 2]);
/// assert_eq!(failures, [false, true]);
/// ```
fn partition_map<A, B, F, L, R>(self, predicate: F) -> (A, B)
fn partition_map<A, B, F, L, R>(self, mut predicate: F) -> (A, B)
where Self: Sized,
F: Fn(Self::Item) -> Either<L, R>,
F: FnMut(Self::Item) -> Either<L, R>,
A: Default + Extend<L>,
B: Default + Extend<R>,
{
let mut left = A::default();
let mut right = B::default();

for val in self {
match predicate(val) {
Either::Left(v) => left.extend(Some(v)),
Either::Right(v) => right.extend(Some(v)),
}
}
self.for_each(|val| match predicate(val) {
Either::Left(v) => left.extend(Some(v)),
Either::Right(v) => right.extend(Some(v)),
});

(left, right)
}
Expand Down

0 comments on commit 521938f

Please sign in to comment.