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

doc: clearer and more correct Iterator::scan #99244

Merged
merged 2 commits into from
Dec 30, 2022

Conversation

gthb
Copy link
Contributor

@gthb gthb commented Jul 14, 2022

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.

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`.
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jul 14, 2022
@rustbot
Copy link
Collaborator

rustbot commented Jul 14, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 14, 2022
@rust-log-analyzer

This comment has been minimized.

@gthb
Copy link
Contributor Author

gthb commented Jul 14, 2022

(Sidenote: this is my first Rust PR and the documentation, the x.py script, and the Github bot support, are all so nice! 👏)

@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 13, 2022
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 8, 2022
@m-ou-se
Copy link
Member

m-ou-se commented Dec 30, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Dec 30, 2022

📌 Commit 588592b has been approved by m-ou-se

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 30, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 30, 2022
…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
@bors
Copy link
Contributor

bors commented Dec 30, 2022

⌛ Testing commit 588592b with merge bbdca4c...

@bors bors merged commit 80e309f into rust-lang:master Dec 30, 2022
@rustbot rustbot added this to the 1.68.0 milestone Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants