reversed

kotlin-stdlib / kotlin.comparisons / reversed
 

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0) 

fun <T> Comparator<T>.reversed(): Comparator<T> 
 Returns a comparator that imposes the reverse ordering of this comparator. import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val list = listOf("aa", "b", "bb", "a")

val lengthThenString = compareBy<String> { it.length }.thenBy { it }

val sorted = list.sortedWith(lengthThenString)
println(sorted) // [a, b, aa, bb]

val sortedReversed = list.sortedWith(lengthThenString.reversed())
println(sortedReversed) // [bb, aa, b, a]
//sampleEnd
} 


    
{'path': 'public/docs/kotlin~1.7/api/latest/jvm/stdlib/kotlin.comparisons/reversed.html', 'source': 'DevDocs.IO'}