Skip to content

Commit e23d1cb

Browse files
Positions::fold
1 parent b07b0ad commit e23d1cb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/adaptors/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,21 @@ where
10811081
fn size_hint(&self) -> (usize, Option<usize>) {
10821082
(0, self.iter.size_hint().1)
10831083
}
1084+
1085+
fn fold<B, G>(self, init: B, mut func: G) -> B
1086+
where
1087+
G: FnMut(B, Self::Item) -> B,
1088+
{
1089+
let mut count = self.count;
1090+
let mut f = self.f;
1091+
self.iter.fold(init, |mut acc, val| {
1092+
if f(val) {
1093+
acc = func(acc, count);
1094+
}
1095+
count += 1;
1096+
acc
1097+
})
1098+
}
10841099
}
10851100

10861101
impl<I, F> DoubleEndedIterator for Positions<I, F>

0 commit comments

Comments
 (0)