then

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

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

Since Kotlin

1.1

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf("A", "aa", "b", "bb", "a")

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

val sorted = list.sortedWith(lengthThenCaseInsensitive)

println(sorted) // [A, a, b, aa, bb] 
   //sampleEnd
}
infix fun <T> Comparator<T>.then(comparator: Comparator<in T>): Comparator<T>(source)

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

Since Kotlin

1.0

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf("A", "aa", "b", "bb", "a")

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

val sorted = list.sortedWith(lengthThenCaseInsensitive)

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