https://kotlinlang.org logo
Title
e

evkaky

06/07/2017, 1:25 PM
guys, how can I perform complex sort on the collection, like this one in sql:
ORDER BY name ASC, age DESC
? I tried something like this, but second sort function completely override previous order
persons.sortedBy { it.name }.sortedByDescending { it.age }
k

kirillrakhman

06/07/2017, 1:26 PM
evkaky:
listOf<Person>().sortedWith(compareBy<Person> { it.name }.thenByDescending { it.age })
👍 1
e

evkaky

06/07/2017, 1:32 PM
Can I set descending order in this example:
list.sortedWith(compareBy({ it.a }, { it.b }, { it.c }))
?
in one of the lambdas
k

kirillrakhman

06/07/2017, 1:33 PM
I don't think so
e

evkaky

06/07/2017, 1:42 PM
thank you dude
k

kirillrakhman

06/07/2017, 1:42 PM
you're welcome