-
Notifications
You must be signed in to change notification settings - Fork 13.3k
doc: clearer and more correct Iterator::scan #99244
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
Conversation
The `Iterator::scan` documentation seemed a little misleading to my newcomer eyes, and this tries to address that. * I found “similar to `fold`” unhelpful because (a) the similarity is only that they maintain state between iterations, and (b) the _dissimilarity_ is no less important: one returns a final value and the other an iterator. So this replaces that with “which, like `fold`, holds internal state, but unlike `fold`, produces a new iterator. * I found “the return value from the closure, an [`Option`], is yielded by the iterator” to be downright incorrect, because “yielded by the iterator” means “returned by the `next` method wrapped in `Some`”, so this implied that `scan` would convert an input iterator of `T` to an output iterator of `Option<T>`. So this replaces “yielded by the iterator” with “returned by the `next` method” and elaborates: “Thus the closure can return `Some(value)` to yield `value`, or `None` to end the iteration.” * This also changes the example to illustrate the latter point by returning `None` to terminate the iteration early based on `state`.
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @m-ou-se (or someone else) soon. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
(Sidenote: this is my first Rust PR and the documentation, the |
@bors r+ |
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#99244 (doc: clearer and more correct Iterator::scan) - rust-lang#103707 (Replace libstd, libcore, liballoc terminology in docs) - rust-lang#104182 (`IN6ADDR_ANY_INIT` and `IN6ADDR_LOOPBACK_INIT` documentation.) - rust-lang#106273 (rustdoc: remove redundant CSS `.source .content { overflow: visible }`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The
Iterator::scan
documentation seemed a little misleading to my newcomereyes, and this tries to address that.
I found “similar to
fold
” unhelpful because (a) the similarity is only thatthey maintain state between iterations, and (b) the dissimilarity is no less
important: one returns a final value and the other an iterator. So this
replaces that with “which, like
fold
, holds internal state, but unlikefold
, produces a new iterator.I found “the return value from the closure, an
Option
, is yielded by theiterator” to be downright incorrect, because “yielded by the iterator” means
“returned by the
next
method wrapped inSome
”, so this implied thatscan
would convert an input iterator of
T
to an output iterator ofOption<T>
.So this replaces “yielded by the iterator” with “returned by the
next
method” and elaborates: “Thus the closure can return
Some(value)
to yieldvalue
, orNone
to end the iteration.”This also changes the example to illustrate the latter point by returning
None
to terminate the iteration early based onstate
.