[ruby-core:93092] [Ruby trunk Feature#15725] Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by!
From:
duerst@...
Date:
2019-06-13 06:41:13 UTC
List:
ruby-core #93092
Issue #15725 has been updated by duerst (Martin D=FCrst).
Clarified that .reverse! can/should be used for reverse order with commit =
2a26c1ea24..7f79a86d8b.
----------------------------------------
Feature #15725: Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_s=
ort_by, and #reverse_sort_by!
https://bugs.ruby-lang.org/issues/15725#change-78514
* Author: sikachu (Prem Sichanugrist)
* Status: Rejected
* Priority: Normal
* Assignee: =
* Target version: =
----------------------------------------
Hello,
I would like to propose four new methods: `#reverse_sort`, `#revert_sort!`,=
`#reverse_sort_by`, and `#reverse_sort_by!` to Array.
These methods provides the most efficient way for user to get a reversed so=
rted array by calling `sort(_by)` then `.reverse!`.
As a language designer, I believe that we should suggest the most efficient=
way to perform a certain action to user. By introduce these methods, we ca=
n discourage user to use them instead of do `array.sort.reverse` or `array.=
sort {|a,b| b<=3D>a}` which are less performant.
I've looked through Redmine, and I saw that there was a proposal to introdu=
ce a similar method to Enumerable in https://bugs.ruby-lang.org/issues/8422=
, but was somewhat rejected due to the complication with infinite Enumerabl=
e. Given that Array is finite, I think this is the best place for these met=
hods to be implemented.
I've attached a patch to implement these methods based on other `ary_sort` =
related methods. Please let me know your thought on how I could improve the=
m to be mergeable, as I am not proficient in writing C.
I'm looking forward to hear your thoughts about this proposal. Thank you ve=
ry much.
---Files--------------------------------
0001-Add-Array-reverse_sort-reverse_sort_by-methods.patch (6.29 KB)
-- =
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>