Skip to content

Commit 0fc4675

Browse files
Positions::rfold
1 parent e23d1cb commit 0fc4675

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/adaptors/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,21 @@ where
11111111
}
11121112
None
11131113
}
1114+
1115+
fn rfold<B, G>(self, init: B, mut func: G) -> B
1116+
where
1117+
G: FnMut(B, Self::Item) -> B,
1118+
{
1119+
let mut count = self.count + self.iter.len();
1120+
let mut f = self.f;
1121+
self.iter.rfold(init, |mut acc, val| {
1122+
count -= 1;
1123+
if f(val) {
1124+
acc = func(acc, count);
1125+
}
1126+
acc
1127+
})
1128+
}
11141129
}
11151130

11161131
impl<I, F> FusedIterator for Positions<I, F>

0 commit comments

Comments
 (0)