-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Iterator#take_while consumes first falsy value #31318
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
Not only would it be a breaking change, but it is impossible for a general iterator: the only way to tell if |
For people reaching here and seeking a way to do this currently, |
Well, maybe we can put the first falsy value to inside |
The cost of cloning an iterator is totally depedent on which iterator it is. A slice iterator is implemented using two pointers, so the cloning amounts to storing two pointers during the iteration. When the whole iteration is inlined, and llvm breaking the structs down to their members, it should be able to remove the store of the pointer that doesn't change (the end), so the overhead is down to storing and restoring one pointer. |
|
This is a behavior that some find confusing, so it deserves its own example. Fixes rust-lang#31318
This is a behavior that some find confusing, so it deserves its own example. Fixes rust-lang#31318 I think this wording might be a bit strange, but I couldn't come up with anything better. Feedback very welcome.
The
take_while
method on iterators consumes the first falsy value, instead of leaving it in the iterator.This behavior seems unintuitive to me; and I could not find any documentation of this functionality. Due to this (I think) being a breaking change, it's probably not worth changing the
take_while
functionality, but documenting this is probably a good idea.I tried this code:
I expected to see this output:
Instead, this I saw this output:
Meta
rustc --version --verbose
:I believe this also occurs on stable (tested in play.rust-lang.org).
The text was updated successfully, but these errors were encountered: