Open Michael-F-Bryan opened 6 years ago
Sounds like it overlaps with multipeek, so reconcile their differences
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
?
See #93. It's best to let your use case guide us here, I don't have one.
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)