Comparator

expect fun interface Comparator<T>(source)

Provides a comparison function for imposing a total ordering between instances of the type T.

Since Kotlin

1.0
actual fun interface Comparator<T>(source)

Since Kotlin

1.1
actual typealias Comparator<T> = java.util.Comparator<T>(source)

Since Kotlin

1.1
actual fun interface Comparator<T>(source)

Since Kotlin

1.3
actual fun interface Comparator<T>(source)

Provides a comparison function for imposing a total ordering between instances of the type T.

Since Kotlin

1.8
actual fun interface Comparator<T>(source)

Provides a comparison function for imposing a total ordering between instances of the type T.

Since Kotlin

1.8

Functions

Link copied to clipboard
expect abstract fun compare(a: T, b: T): Int

Compares its two arguments for order. Returns zero if the arguments are equal, a negative number if the first argument is less than the second, or a positive number if the first argument is greater than the second.

Since Kotlin 1.0
actual abstract fun compare(a: T, b: T): Int
Since Kotlin 1.1
actual abstract fun compare(a: T, b: T): Int
Since Kotlin 1.3
actual abstract fun compare(a: T, b: T): Int

Compares its two arguments for order. Returns zero if the arguments are equal, a negative number if the first argument is less than the second, or a positive number if the first argument is greater than the second.

Since Kotlin 1.8
actual abstract fun compare(a: T, b: T): Int

Compares its two arguments for order. Returns zero if the arguments are equal, a negative number if the first argument is less than the second, or a positive number if the first argument is greater than the second.

Since Kotlin 1.8
Link copied to clipboard

Returns a comparator that imposes the reverse ordering of this comparator.

Since Kotlin 1.0
Link copied to clipboard
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.

Since Kotlin 1.0
Link copied to clipboard
inline fun <T> Comparator<T>.thenBy(crossinline selector: (T) -> Comparable<*>?): Comparator<T>

Creates a comparator comparing values after the primary comparator defined them equal. It uses the function to transform value to a Comparable instance for comparison.

Since Kotlin 1.0
inline fun <T, K> Comparator<T>.thenBy(comparator: Comparator<in K>, crossinline selector: (T) -> K): Comparator<T>

Creates a comparator comparing values after the primary comparator defined them equal. It uses the selector function to transform values and then compares them with the given comparator.

Since Kotlin 1.0
Link copied to clipboard
inline fun <T> Comparator<T>.thenByDescending(crossinline selector: (T) -> Comparable<*>?): Comparator<T>

Creates a descending comparator using the primary comparator and the function to transform value to a Comparable instance for comparison.

Since Kotlin 1.0
inline fun <T, K> Comparator<T>.thenByDescending(comparator: Comparator<in K>, crossinline selector: (T) -> K): Comparator<T>

Creates a descending comparator comparing values after the primary comparator defined them equal. It uses the selector function to transform values and then compares them with the given comparator.

Since Kotlin 1.0
Link copied to clipboard
inline fun <T> Comparator<T>.thenComparator(crossinline comparison: (a: T, b: T) -> Int): Comparator<T>

Creates a comparator using the primary comparator and function to calculate a result of comparison.

Since Kotlin 1.0
Link copied to clipboard
infix fun <T> Comparator<T>.thenDescending(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.

Since Kotlin 1.0