Skip to content

Commit c2abf8f

Browse files
committed
Tweak partition, unzip, try_find.
Many default iterator methods use `try_fold` or `fold`, and these ones can too.
1 parent 4b7c3d8 commit c2abf8f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/libcore/iter/traits/iterator.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1697,8 +1697,8 @@ pub trait Iterator {
16971697
mut f: impl FnMut(&T) -> bool + 'a,
16981698
left: &'a mut B,
16991699
right: &'a mut B,
1700-
) -> impl FnMut(T) + 'a {
1701-
move |x| {
1700+
) -> impl FnMut((), T) + 'a {
1701+
move |(), x| {
17021702
if f(&x) {
17031703
left.extend(Some(x));
17041704
} else {
@@ -1710,7 +1710,7 @@ pub trait Iterator {
17101710
let mut left: B = Default::default();
17111711
let mut right: B = Default::default();
17121712

1713-
self.for_each(extend(f, &mut left, &mut right));
1713+
self.fold((), extend(f, &mut left, &mut right));
17141714

17151715
(left, right)
17161716
}
@@ -2281,7 +2281,7 @@ pub trait Iterator {
22812281
F: FnMut(&Self::Item) -> R,
22822282
R: Try<Ok = bool, Error = E>,
22832283
{
2284-
self.try_for_each(move |x| match f(&x).into_result() {
2284+
self.try_fold((), move |(), x| match f(&x).into_result() {
22852285
Ok(false) => LoopState::Continue(()),
22862286
Ok(true) => LoopState::Break(Ok(x)),
22872287
Err(x) => LoopState::Break(Err(x)),
@@ -2673,8 +2673,8 @@ pub trait Iterator {
26732673
fn extend<'a, A, B>(
26742674
ts: &'a mut impl Extend<A>,
26752675
us: &'a mut impl Extend<B>,
2676-
) -> impl FnMut((A, B)) + 'a {
2677-
move |(t, u)| {
2676+
) -> impl FnMut((), (A, B)) + 'a {
2677+
move |(), (t, u)| {
26782678
ts.extend(Some(t));
26792679
us.extend(Some(u));
26802680
}
@@ -2683,7 +2683,7 @@ pub trait Iterator {
26832683
let mut ts: FromA = Default::default();
26842684
let mut us: FromB = Default::default();
26852685

2686-
self.for_each(extend(&mut ts, &mut us));
2686+
self.fold((), extend(&mut ts, &mut us));
26872687

26882688
(ts, us)
26892689
}

0 commit comments

Comments
 (0)