diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index 1e8476d3880c8..955bbde5ff69f 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -754,6 +754,26 @@ impl Iterator for StepBy where I: Iterator { self.iter.nth(nth - 1); } } + + fn try_fold(&mut self, init: B, mut f: F) -> R where + Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try + { + let mut accum = init; + + if self.first_take { + self.first_take = false; + if let Some(x) = self.iter.next() { + accum = f(accum, x)?; + } else { + return Try::from_ok(accum); + } + } + + while let Some(x) = self.iter.nth(self.step) { + accum = f(accum, x)?; + } + Try::from_ok(accum) + } } // StepBy can only make the iterator shorter, so the len will still fit.