Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.7.2, 1.8-beta-1
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
It would be nice to be able to reverse the order of a map without running collect on it first. For example,
def foo = ["string1":1, "string2":2, "string3":3]
println foo.sort
//println foo.sort {it.value}
.reverse() // <-- this is what I propose
This is, of course, a simplistic example for which there are workarounds, like
foo.sort {-it.value}
but I could imagine other potential uses for this method.
Issue Links
- is related to
-
GROOVY-2597
Map or Property Sort
-
A Map does not imply any order on the values. You see an input order because we use a LinkedHashMap. If it were a TreeMap you would see a different order. You get a sorting in here because of your call to sort, but your collect then returns a list. So your reverse ends up with a list too... You want a list in the end?