W3cubDocs

/Kotlin

thenDescending

infix fun <T> Comparator<T>.thenDescending(
    comparator: Comparator<in T>
): Comparator<T>

Platform and version requirements: JS

Combines this comparator and the given comparator such that the latter is applied only when the former considered values equal.

import kotlin.test.*

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

val lengthThenCaseInsensitive = compareBy<String> { it.length }
        .thenDescending(String.CASE_INSENSITIVE_ORDER)

val sorted = list.sortedWith(lengthThenCaseInsensitive)

println(sorted) // [b, A, a, bb, aa]
//sampleEnd
}

© 2010–2018 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.comparisons/then-descending.html