From b8a12636c5085ba46fe3e97a162fef43ee00e8ea Mon Sep 17 00:00:00 2001 From: Philippe-Cholet Date: Thu, 9 Nov 2023 19:42:35 +0100 Subject: [PATCH] `PeekNth::fold` --- src/peek_nth.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/peek_nth.rs b/src/peek_nth.rs index e8546030d..ff5a55cc0 100644 --- a/src/peek_nth.rs +++ b/src/peek_nth.rs @@ -152,6 +152,14 @@ where fn size_hint(&self) -> (usize, Option) { size_hint::add_scalar(self.iter.size_hint(), self.buf.len()) } + + fn fold(self, mut init: B, mut f: F) -> B + where + F: FnMut(B, Self::Item) -> B, + { + init = self.buf.into_iter().fold(init, &mut f); + self.iter.fold(init, f) + } } impl ExactSizeIterator for PeekNth where I: ExactSizeIterator {}