Skip to content

Commit

Permalink
Positions::fold
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet committed Dec 8, 2023
1 parent b07b0ad commit e23d1cb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/adaptors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,21 @@ where
fn size_hint(&self) -> (usize, Option<usize>) {
(0, self.iter.size_hint().1)
}

fn fold<B, G>(self, init: B, mut func: G) -> B
where
G: FnMut(B, Self::Item) -> B,
{
let mut count = self.count;
let mut f = self.f;
self.iter.fold(init, |mut acc, val| {
if f(val) {
acc = func(acc, count);
}
count += 1;
acc
})
}
}

impl<I, F> DoubleEndedIterator for Positions<I, F>
Expand Down

0 comments on commit e23d1cb

Please sign in to comment.