-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking Issue for cmp::minmax{_by,_by_key}
#115939
Comments
Big fan. |
Looks like |
@Jules-Bertholet yes, of course. and the fix would be the same (either using HKT, which is unergonomic in rust, or having a separate function for |
I knew this looked familiar 🙂 #73857 |
Concern: Why I can't find precedent in Informal survey
I believe these results indicate By the principle of least surprise, I propose |
It used to be that the tuple was far better because it worked in patterns. Now that |
@anko as @scottmcm said, a lot of this is probably historic reasons — addition of matching / destructuring arrays is relatively new (checks notes, apparently it was stabilized in Rust 1.42, not that new). I prefer and have used an array in those signatures, because I think it's nicer and better shows the intent. It's nicer in the sense that arrays are more powerful than tuples — since they are homogenous they allow for more operations. Even though I think the result of this expression will almost always be destructured immediately, it's still nicer. It better shows the intent in the sense that the methods return not just a pair of two values, but an ordered array. Also it highlightes the similarity to the Ultimately I don't think it matters much, but IMO the array is better here. (ps. arrays and tuples also implement into/from) |
Looking forward to having this! Wanted it today when writing an algorithm that identifies the smaller of two values and walks it towards the greater. |
If the issue with #34162 takes longer than expected to resolve, could (Tbh, I'm not familiar with the requirements of stabilization) |
@nmay231 that is possible, we do partial stabilization all the time. |
I disagree, an array is a (possibly unordered) collection of a single kind of thing, whereas a tuple is an ordered collection of (possibly different kinds of) things, so a tuple shows intent better. Also min and max are opposites so they are arguably not even really the same kind of thing, making an array an even weaker option. That being said the ordering of min and max is arbitrary and they have clear names, so returning a struct could be even clearer. The problem with that being then you have a struct cluttering the namespace. |
@notme4 how are tuples any more ordered than arrays? |
Feature gate:
#![feature(cmp_minmax)]
This is a tracking issue for
core::cmp::minmax{_by,_by_key}
.Those functions take two values and return an array of
[min, max]
. This is essentially a sort specialized for two arguments.Public API
Steps / History
minmax{,_by,_by_key}
functions tocore::cmp
#109409Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: