Skip to content

partition_map: loosened Fn to FnMut; replaced for by for_each #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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