sortedByDescending
public inline fun <T, R : Comparable<R>>
Iterable<T>.sortedByDescending(crossinline selector: (T) -> R?): List<T> {
return sortedWith(compareByDescending(selector))
}
data class Person(val name: String, val age: Int)
val list = listOf(
Person("gold", 20),
Person("ari", 19),
Person("kasadin", 50),
Person("amumu", 15)
)
println(list.sortedByDescending { it.age })
// [Person(name=kasadin, age=50), Person(name=gold, age=20), Person(name=ari, age=19), Person(name=amumu, age=15)]
Last updated