Skip to content

Commit

Permalink
PutBackN::fold
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet authored and phimuemue committed Dec 15, 2023
1 parent fbe30e7 commit 2357feb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/put_back_n_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,12 @@ impl<I: Iterator> Iterator for PutBackN<I> {
fn size_hint(&self) -> (usize, Option<usize>) {
size_hint::add_scalar(self.iter.size_hint(), self.top.len())
}

fn fold<B, F>(self, mut init: B, mut f: F) -> B
where
F: FnMut(B, Self::Item) -> B,
{
init = self.top.into_iter().rfold(init, &mut f);
self.iter.fold(init, f)
}
}

0 comments on commit 2357feb

Please sign in to comment.