Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite lookahead adaptor #260

Open
Michael-F-Bryan opened this issue Feb 2, 2018 · 3 comments
Open

Infinite lookahead adaptor #260

Michael-F-Bryan opened this issue Feb 2, 2018 · 3 comments

Comments

@Michael-F-Bryan
Copy link

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?

(example implementation)

@bluss
Copy link
Member

bluss commented Feb 2, 2018

Sounds like it overlaps with multipeek, so reconcile their differences

@Michael-F-Bryan
Copy link
Author

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?

@bluss
Copy link
Member

bluss commented Feb 3, 2018

See #93. It's best to let your use case guide us here, I don't have one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants