You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For one of my projects I recently needed something which lets you peek more than one item ahead (std::iter::Peekable only lets you lookahead by one) so I implemented an InfiniteLookahead adaptor which buffers intermediate objects in a VecDeque internally. This is particularly useful when you're parsing text and your grammar requires 2 or more tokens of lookahead.
Would you be interested in a PR that adds it to the Itertools trait?
Oops. I assumed all iterator adaptors would be implemented on the Itertools trait, so I never knew about multipeek().
It looks like they're doing effectively the same thing, although multipeek() uses a "cursor" which gets moved forward every time you call peek(), while InfiniteLookahead effectively gives you random lookup... Would it be worth adding a lookahead() method to MultiPeek?
For one of my projects I recently needed something which lets you peek more than one item ahead (
std::iter::Peekable
only lets you lookahead by one) so I implemented anInfiniteLookahead
adaptor which buffers intermediate objects in aVecDeque
internally. This is particularly useful when you're parsing text and your grammar requires 2 or more tokens of lookahead.Would you be interested in a PR that adds it to the
Itertools
trait?(example implementation)
The text was updated successfully, but these errors were encountered: