rust-itertools / itertools

Extra iterator adaptors, iterator methods, free functions, and macros.
https://docs.rs/itertools/
Apache License 2.0
2.76k stars 309 forks source link

Add `peeking_next_map` #994

Open ronnodas opened 2 months ago

ronnodas commented 2 months ago

I would like to have a method on "peekable" iterators with roughly the following signature and behavior similar to PeekingNext::peeking_next:

fn peeking_next_map(&mut self, parse: impl FnOnce(&Self::Item) -> Option<B>) -> Option<B>;

This would allow, for example, peeking for multiple kinds of opening delimiters at once and getting one back "parsed" and not just "validated".

Since such a method can be implemented in terms of a peek (or put_back) method as well, it might make sense to combine this with #679.