Skip to content

Commit

Permalink
implement nth_back for Fuse
Browse files Browse the repository at this point in the history
  • Loading branch information
koalatux committed Apr 16, 2019
1 parent cc2689a commit fae2a68
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libcore/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,17 @@ impl<I> DoubleEndedIterator for Fuse<I> where I: DoubleEndedIterator {
}
}

#[inline]
default fn nth_back(&mut self, n: usize) -> Option<<I as Iterator>::Item> {
if self.done {
None
} else {
let nth = self.iter.nth_back(n);
self.done = nth.is_none();
nth
}
}

#[inline]
default fn try_rfold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R where
Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc>
Expand Down Expand Up @@ -1877,6 +1888,11 @@ impl<I> DoubleEndedIterator for Fuse<I>
self.iter.next_back()
}

#[inline]
fn nth_back(&mut self, n: usize) -> Option<<I as Iterator>::Item> {
self.iter.nth_back(n)
}

#[inline]
fn try_rfold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R where
Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc>
Expand Down

0 comments on commit fae2a68

Please sign in to comment.