-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Clarify behavior of map/filter #30632
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
Comments
/cc @rust-lang/libs |
I don't think we need to change anything here apart from maybe improving the docs by pointing out this pitfall. The behavior of |
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this issue
Feb 1, 2016
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Feb 2, 2016
Fixes rust-lang#30632 I'm not sure if this explanation is good enough. If it is, I will add it to filter as well.
tslnc04
added a commit
to tslnc04/rust
that referenced
this issue
May 5, 2024
Issue rust-lang#30632 shows the unexpected behavior that can arise from `iter::Map` and `iter::Filter` both implementing `DoubleEndedIterator`. PR rust-lang#31220 makes note of this behavior by adding a note to the docs for `iter::Map`, but does not do the same for `iter::Filter`. This PR adds similar documentation to `iter::Filter`. It may be worth considering adding this documentation to `iter::FilterMap` as well or placing it in another location with a note that it applies to using all of these types with stateful closures.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apparently
iter::Map
anditer::Filter
implementDoubleEndedIterator
. This could lead to unexpected behavior:These adapters are only really reversible when passed closure is side-effect free. Unfortunately, we can't simply say that
map
calls the passed closure on each element yielded becausecounter.last() != counter.reverse().next()
.The text was updated successfully, but these errors were encountered: