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

Laziness in tuple_windows #601

Closed
aobatact opened this issue Feb 7, 2022 · 2 comments · Fixed by #602
Closed

Laziness in tuple_windows #601

aobatact opened this issue Feb 7, 2022 · 2 comments · Fixed by #602

Comments

@aobatact
Copy link
Contributor

aobatact commented Feb 7, 2022

I was bit surprised by that Itertools::tuple_windows is not somewhat lazy and has side effect.
It is consuming the first tuple when calling Itertools::tuple_windows .

https://doc.rust-lang.org/nightly/core/iter/index.html#laziness says that adapters in Iterator is lazy and
the TupleWindows has #[must_use = "iterator adaptors are lazy and do nothing unless consumed] since #227

So the question is

  • Is this intended behavior?
  • Should (all) adapters in Itertools be lazy?
  • Should the laziness be documented?
@aobatact
Copy link
Contributor Author

I think this is a bug to be fixed...

@Philippe-Cholet
Copy link
Member

I looked for (mut text in function definitions and found multiple functions I thought as lazy to actually consume one item before we actually consume them:

CoalesceBy and Product also uses #[must_use = "iterator adaptors are lazy and do nothing unless consumed"].

Now that I think about it, I suppose we could argue that "must_use" implies that the user is supposed to consume the iterator and consume one item at definition is not a big deal since it's "just a moment" before the rest?!

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

Successfully merging a pull request may close this issue.

2 participants