Skip to content

Commit

Permalink
Positions::rfold
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet committed Dec 8, 2023
1 parent e23d1cb commit 0fc4675
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 @@ -1111,6 +1111,21 @@ where
}
None
}

fn rfold<B, G>(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<I, F> FusedIterator for Positions<I, F>
Expand Down

0 comments on commit 0fc4675

Please sign in to comment.