We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 37771d4 commit 5850f0bCopy full SHA for 5850f0b
src/libcore/iter/mod.rs
@@ -698,13 +698,16 @@ impl<I> Iterator for StepBy<I> where I: Iterator {
698
#[inline]
699
fn nth(&mut self, mut n: usize) -> Option<Self::Item> {
700
if self.first_take {
701
+ self.first_take = false;
702
+ let first = self.iter.next();
703
if n == 0 {
- self.first_take = false;
- return self.iter.next()
704
+ return first;
705
}
706
n -= 1;
707
- self.iter.nth(n * self.step)
708
+ // n and self.step are indices, thus we need to add 1 before multiplying.
709
+ // After that we need to subtract 1 from the result to convert it back to an index.
710
+ self.iter.nth((n + 1) * (self.step + 1) - 1)
711
712
713
0 commit comments