From c5b367bf10e085c0b5b692de17579869f84e7903 Mon Sep 17 00:00:00 2001 From: Philippe-Cholet Date: Thu, 9 Nov 2023 19:53:15 +0100 Subject: [PATCH 1/2] `PadUsing::fold` --- src/pad_tail.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pad_tail.rs b/src/pad_tail.rs index 47e62b2cf..4be781242 100644 --- a/src/pad_tail.rs +++ b/src/pad_tail.rs @@ -67,6 +67,18 @@ where let tail = self.min.saturating_sub(self.pos); size_hint::max(self.iter.size_hint(), (tail, Some(tail))) } + + fn fold(self, mut init: B, mut f: G) -> B + where + G: FnMut(B, Self::Item) -> B, + { + let mut pos = self.pos; + init = self.iter.fold(init, |acc, item| { + pos += 1; + f(acc, item) + }); + (pos..self.min).map(self.filler).fold(init, f) + } } impl DoubleEndedIterator for PadUsing From 1629077004c5d511a3882963f9332092673f13ec Mon Sep 17 00:00:00 2001 From: Philippe-Cholet Date: Sun, 26 Nov 2023 14:07:00 +0100 Subject: [PATCH 2/2] `PadUsing::rfold` --- src/pad_tail.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pad_tail.rs b/src/pad_tail.rs index 4be781242..5595b42ba 100644 --- a/src/pad_tail.rs +++ b/src/pad_tail.rs @@ -97,6 +97,16 @@ where Some((self.filler)(self.min)) } } + + fn rfold(self, mut init: B, mut f: G) -> B + where + G: FnMut(B, Self::Item) -> B, + { + init = (self.iter.len()..self.min) + .map(self.filler) + .rfold(init, &mut f); + self.iter.rfold(init, f) + } } impl ExactSizeIterator for PadUsing