-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
New sort function 'sorted()' for vec that returns a new vec for chaining. #2731
Comments
I meant that a popular itertools crate has |
Thanks for the reply. I disagree though and think it should be in std. Swift, Objective-C and Python comes to mind for other languages that have this. Probably there are more. |
I think we need more opinions from a wider community. |
can we also have one for fixed size arrays |
I'd personally prefer if std kept few distinctive names for expensive operations, so a method that clones an array should never be called just Just do I could however imagine something like
except doing that breaks any code that uses apply for anything, so you'd need some trait. |
|
I think a such basic operation should be in an ergonomic way in the stdlib. |
To bring over a comment from an earlier issue; this verbiage would be great if used consistently. |
If you've
If you add all six Worse, method shadowing always creates some ambiguity that makes understanding code harder. We should discuss if shadowing might complicate refactoring code from |
I too think sorted should be in std lib. In Rust playground, repl.it and other places where I can't install packages I am forced to use mutable vectors whose names don't represent the data they contain at all times. 😢 |
Just for the record, itertools is on rust playground. |
Would be nice to have this in the standard lib to make things possible like [v1, v2].concat().sorted() |
In the std lib of D language there's something related but with a different usage: it doesn't create a new vector, it sorts the two given arrays one after the other, viewing it like a single array. |
I think rust's concept of moving self, and allowing for it to be returned again after an operation like sorting makes standardizing methods like |
So? Discussed for 5 years. When will add to std? |
I found an old (somewhat related) issue suggesting to change sort() to return &mut self which of course can't be done since it a breaking change. I suggest instead the following:
How about a new function "sorted()", that returns a new sorted vec? When I was doing iOS programming back in the day there were usually two functions for sorting, one sorted in place and one returned a new sorted vec. It was convenient to have both options.
The text was updated successfully, but these errors were encountered: