Reverse sort a list

Is there a way to reverse sort a group so that the largest value appears first? Currently I have

 gChargerTimes.members.sortBy[ (state as Number).intValue ].forEach [ NumberItem lowestRuntime | <do stuff> ]

which delivers the results from lowest to highest, and I need a way that delivers from highest to lowest

There are two ways:

gChargerTimers.members.sortBy[ -state ].forEach[ NumberItem lowestRuntime | <do stuff> ]

gChargerTimers.members.sortBy[ state ].reverseView.forEach[ NumberItem lowestRuntime | <do stuff> ]

The first one might need to be cast to a Number first:

gChargerTimers.members.sortBy[ -(state as Number) ].forEach[ NumberItem lowestRuntime | <do stuff> ]

There is no need to call intValue.

Reference: (Question 2)

Thanks very much indeed @rlkoshak , I’ve been trying to google a solution for this one for some time now. I used your last one which is working well.

gChargerTimers.members.sortBy[ -(state as Number) ].forEach[ NumberItem lowestRuntime | <do stuff> ]

Interestingly in my original example if I remove “.intValue” the VB Code spits out
“Bounds mismatch: The type arguments <Item, Number> are not a valid substitute for the bounded type parameters <T, C extends Comparable<? super C>> of the method sortBy(Iterable, Function1<? super T, C>)”

Not sure why it made that complaint. I’m 90% certain Number implements Comparable.

Either way the new setup is working and I’m very grateful for your help :slight_smile: