https://kotlinlang.org logo
#announcements
Title
# announcements
m

myanmarking

06/12/2017, 11:41 AM
guys, how do i reverse this:
Copy code
return this.sortedWith(
                compareBy(
                        { it.isFriendOnline },
                        { it.presenceMode },
                        { it.gameStatus },
                        { it.name }
                )
        )
i want to reverse the sorting order without creating a new list. apparently, swapping the comparators order won’t work
c

christophsturm

06/12/2017, 11:43 AM
you could invert all the comparators
m

mg6maciej

06/12/2017, 11:44 AM
Cannot invert
String
and gameStatus (int or enum).
m

myanmarking

06/12/2017, 12:55 PM
yes the problem are enums
i

ilya.gorbunov

06/12/2017, 2:40 PM
Use
Comparator.reversed
function to get the compartor of inverted order
👍 2
m

myanmarking

06/12/2017, 4:09 PM
ok. thanks
3 Views