-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Try to improve the documentation of filter()
and filter_map()
.
#75949
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
I've just noticed that I wrapped my lines longer than before. Let me know if that's an issue and I'll fix it. |
What column are they wrapped to? Standard library, IIRC, uses 80. |
Re-wrapped to 80 and made the docs for What do you think? |
It occurs to me that it might be better to say |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good, but yeah, I also hear you about the "returned iterator". Hmmm...
Having thought a little more, I prefer "returned iterator". Fix pushed. OK to squash? |
☔ The latest upstream changes (presumably #76265) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased to resolve merge conflict. Another change updated the links which I had removed anyway. |
Why not something like "The returned iterator will only contain elements that returns true when applied to the predicate". Short and no double negatives with "false" and "not" |
I'd go for a slight tweak on that:
(And we've already said that each element will be passed to the closure) |
You removed some links also that need to be added back:
I still consider #75949 (comment) a blocking concern though. |
I've had a shot at addressing comments. There's a curious merge conflict (for a path I've not touched), but we can look at that later. Are we getting any closer? |
You updated submodules, I'm not quite sure how to fix it. Maybe |
/// Given an element the closure must return `Some(value)` or `None`. The | ||
/// returned iterator will only yield a value when the closure returns | ||
/// `Some`. The values inside the `Some`s are yielded. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little verbose, but I'm not sure how better to word it. It seems like it's saying the same thing 3 times sort of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spent quite some time trying to get these three sentences down to 2 (or even better one), but failed.
It's hard to explain concisely that it is not the element that is returned, but the innards of the Some
that is returned.
I'm open to suggestions, but also I'd like to move forward. You can always tweak this in a later PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would something like this be any better?
The returned iterator yields only the
value
s for which the supplied closure returnsSome(value)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, I like that!
r=me without the submodule updates. Not sure how exactly to fix those ... maybe something like this? git checkout filter-docs
git reset fd001558c8f077da2e9e645c6667881b48524e72
git add library/core/src/iter/traits/iterator.rs
git commit -m "Address comments"
git push -f |
@jyn514 I think we raced. I made a suggestion in the above thread at the same time as it was marked resolved. |
I think this should be good. Assuming all is well, can I squash? |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Looks good to me but you still need to undo the submodule changes: #75949 (comment) |
I believe the documentation is currently a little misleading. For example, in the docs for `filter()`: > If the closure returns `false`, it will try again, and call the closure on > the next element, seeing if it passes the test. This kind of implies that if the closure returns true then we *don't* "try again" and no further elements are considered. In actuality that's not the case, every element is tried regardless of what happened with the previous element. This change tries to clarify that by removing the uses of "try again" altogether.
Ugh. I thought I had removed those. I think this is the desired result (with a squash also). |
@bors r+ rollup Thanks for the PR! (and for persisting through the trouble with submodules) |
📌 Commit 8af85fa has been approved by |
Try to improve the documentation of `filter()` and `filter_map()`. I believe the documentation is currently a little misleading. For example, in the docs for `filter()`: > If the closure returns `false`, it will try again, and call the closure on > the next element, seeing if it passes the test. This kind of implies that if the closure returns true then we *don't* "try again" and no further elements are considered. In actuality that's not the case, every element is tried regardless of what happened with the previous element. This change tries to clarify that by removing the uses of "try again" altogether.
⌛ Testing commit 8af85fa with merge 642ebd19e1bccb1179d6acee8af7e56f8920b242... |
💔 Test failed - checks-azure |
Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors retry network error:
|
Try to improve the documentation of `filter()` and `filter_map()`. I believe the documentation is currently a little misleading. For example, in the docs for `filter()`: > If the closure returns `false`, it will try again, and call the closure on > the next element, seeing if it passes the test. This kind of implies that if the closure returns true then we *don't* "try again" and no further elements are considered. In actuality that's not the case, every element is tried regardless of what happened with the previous element. This change tries to clarify that by removing the uses of "try again" altogether.
☀️ Test successful - checks-actions, checks-azure |
I believe the documentation is currently a little misleading.
For example, in the docs for
filter()
:This kind of implies that if the closure returns true then we don't "try
again" and no further elements are considered. In actuality that's not the
case, every element is tried regardless of what happened with the previous
element.
This change tries to clarify that by removing the uses of "try again"
altogether.