-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add Iterator comparison methods that take a comparison function #62205
Conversation
r? @KodrAus (rust_highfive has picked a reviewer for you, use r? to override) |
Even with the docs page better, this is still a ton of new methods -- it feels like the What if this only added |
My initial reason for not adding them was that they require the two iterators to have the same
|
I thought this over some more and I think I'm coming back on
As for the others, the |
Thanks for the PR @timvermeulen! Do you have any real-world examples that you think are improved by these additional methods? |
@KodrAus I do for I don't have any real-world use cases for |
Ping from triage, any updates? @KodrAus |
Thanks for the ping! Ok, the @timvermeulen would you like to add an example for each of these methods? I know there are a bunch of methods on |
We should also add some tests to |
Hey! This is a ping from triage, we would like to know if you @timvermeulen could give us a few more minutes to update here so we can move forward. Thanks. @rustbot modify labels to +S-waiting-on-author, -S-waiting-on-review |
Hello! Second ping from triage, thank you for your work @timvermeulen, please feel free to reopen once you have the time (Also note that pushing to the PR while it is closed prevents it from being reopened). @rustbot modify labels to +S-inactive-closed, -S-waiting-on-author |
@KodrAus Sorry for the delay, how do I reopen this? I think the closures passed to these methods should probably receive ownership of the items, since the items aren't used after being passed to the closure. I'll change that. |
Hi @timvermeulen 👋 I'll re-open this for you |
@KodrAus Thanks! I've added examples for all the involved methods, as well as some tests. I wasn't sure what to test exactly, is this more or less what you had in mind? |
☔ The latest upstream changes (presumably #64209) made this pull request unmergeable. Please resolve the merge conflicts. |
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 |
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.
Ok this looks good to me!
Thanks @timvermeulen
@bors r+ |
📌 Commit 58ba1f5 has been approved by |
⌛ Testing commit 58ba1f5 with merge bfb6714875f1954e769281072ccf29d4f260b255... |
Add Iterator comparison methods that take a comparison function This PR adds `Iterator::{cmp_by, partial_cmp_by, eq_by, ne_by, lt_by, le_by, gt_by, ge_by}`. We already have `Iterator::{cmp, partial_cmp, ...}` which are less general (but not any simpler) than the ones I'm proposing here. I'm submitting this PR now because rust-lang#61505 has been merged, so this change should not have a noticeable effect on the `Iterator` docs page size. The diff is quite messy, here's what I changed: - The logic of `cmp` / `partial_cmp` / `eq` is moved to `cmp_by` / `partial_cmp_by` / `eq_by` respectively, changing `x.cmp(&y)` to `cmp(&x, &y)` in the `cmp` method where `cmp` is the given comparison function (and similar for `partial_cmp_by` and `eq_by`). - `ne_by` / `lt_by` / `le_by` / `gt_by` / `ge_by` are each implemented in terms of one of the three methods above. - The existing comparison methods are each forwarded to their `_by` counterpart, passing one of `Ord::cmp` / `PartialOrd::partial_cmp` / `PartialEq::eq` as the comparison function. The corresponding `_by_key` methods aren't included because they're not as fundamental as the `_by` methods and can easily be implemented in terms of them. Is that reasonable, or would adding the `_by_key` methods be desirable for the sake of completeness? I didn't add any tests – I couldn't think of any that weren't already covered by our existing tests. Let me know if there's a particular test that would be useful to add.
@bors retry rolled up. |
⌛ Testing commit 58ba1f5 with merge e8216f8ad68e4517f8d1728e016e868c37373eaa... |
@bors retry rolled up. |
Rollup of 4 pull requests Successful merges: - #62205 (Add Iterator comparison methods that take a comparison function) - #64152 (Use backtrace formatting from the backtrace crate) - #64265 (resolve: Mark more erroneous imports as used) - #64267 (rustdoc: fix diagnostic with mixed code block styles) Failed merges: r? @ghost
Alrighty, I've opened a tracking issue in #64295 for this feature and will submit a follow-up PR to update our issue number to reference it. |
Document the unstable iter_order_by library feature Tracking issue: rust-lang#64295 Follow-up for: rust-lang#62205 References the tracking issue and adds a page to the unstable book for the new unstable `iter_order_by` feature.
Document the unstable iter_order_by library feature Tracking issue: rust-lang#64295 Follow-up for: rust-lang#62205 References the tracking issue and adds a page to the unstable book for the new unstable `iter_order_by` feature.
Document the unstable iter_order_by library feature Tracking issue: rust-lang#64295 Follow-up for: rust-lang#62205 References the tracking issue and adds a page to the unstable book for the new unstable `iter_order_by` feature.
This PR adds
Iterator::{cmp_by, partial_cmp_by, eq_by, ne_by, lt_by, le_by, gt_by, ge_by}
. We already haveIterator::{cmp, partial_cmp, ...}
which are less general (but not any simpler) than the ones I'm proposing here.I'm submitting this PR now because #61505 has been merged, so this change should not have a noticeable effect on the
Iterator
docs page size.The diff is quite messy, here's what I changed:
cmp
/partial_cmp
/eq
is moved tocmp_by
/partial_cmp_by
/eq_by
respectively, changingx.cmp(&y)
tocmp(&x, &y)
in thecmp
method wherecmp
is the given comparison function (and similar forpartial_cmp_by
andeq_by
).ne_by
/lt_by
/le_by
/gt_by
/ge_by
are each implemented in terms of one of the three methods above._by
counterpart, passing one ofOrd::cmp
/PartialOrd::partial_cmp
/PartialEq::eq
as the comparison function.The corresponding
_by_key
methods aren't included because they're not as fundamental as the_by
methods and can easily be implemented in terms of them. Is that reasonable, or would adding the_by_key
methods be desirable for the sake of completeness?I didn't add any tests – I couldn't think of any that weren't already covered by our existing tests. Let me know if there's a particular test that would be useful to add.