Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
infix fun <T> Comparator<T>.then(
    comparator: Comparator<in T>
): Comparator<T>

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>) {
val list = listOf("A", "aa", "b", "bb", "a")

val lengthThenCaseInsensitive = compareBy<String> { it.length }

val sorted = list.sortedWith(lengthThenCaseInsensitive)

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

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.