From 0fc4675b51ecc95ec49026d2212e3b1225fe8b33 Mon Sep 17 00:00:00 2001 From: Philippe-Cholet Date: Fri, 24 Nov 2023 10:47:02 +0100 Subject: [PATCH] `Positions::rfold` --- src/adaptors/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/adaptors/mod.rs b/src/adaptors/mod.rs index 7f6ff95a1..52ee4800c 100644 --- a/src/adaptors/mod.rs +++ b/src/adaptors/mod.rs @@ -1111,6 +1111,21 @@ where } None } + + fn rfold(self, init: B, mut func: G) -> B + where + G: FnMut(B, Self::Item) -> B, + { + let mut count = self.count + self.iter.len(); + let mut f = self.f; + self.iter.rfold(init, |mut acc, val| { + count -= 1; + if f(val) { + acc = func(acc, count); + } + acc + }) + } } impl FusedIterator for Positions