Skip to content

Commit

Permalink
Auto merge of #56904 - sinkuu:cycle_fold, r=bluss
Browse files Browse the repository at this point in the history
Remove Cycle::try_fold override

Fixes #56883
  • Loading branch information
bors committed Dec 17, 2018
2 parents 54f3cd6 + f0483f7 commit adbfec2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
13 changes: 0 additions & 13 deletions src/libcore/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,19 +649,6 @@ impl<I> Iterator for Cycle<I> where I: Clone + Iterator {
_ => (usize::MAX, None)
}
}

#[inline]
fn try_fold<Acc, F, R>(&mut self, init: Acc, mut f: F) -> R where
Self: Sized, F: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc>
{
let mut accum = init;
while let Some(x) = self.iter.next() {
accum = f(accum, x)?;
accum = self.iter.try_fold(accum, &mut f)?;
self.iter = self.orig.clone();
}
Try::from_ok(accum)
}
}

#[stable(feature = "fused", since = "1.26.0")]
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/tests/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,8 @@ fn test_cycle() {
assert_eq!(it.next(), None);

assert_eq!(empty::<i32>().cycle().fold(0, |acc, x| acc + x), 0);

assert_eq!(once(1).cycle().skip(1).take(4).fold(0, |acc, x| acc + x), 4);
}

#[test]
Expand Down

0 comments on commit adbfec2

Please sign in to comment.