Package-level declarations

Helper functions for creating java.util.Comparator instances.

Helper functions for creating java.util.Comparator instances.

Helper functions for creating Comparator instances.

Helper functions for creating java.util.Comparator instances.

Functions

Link copied to clipboard
fun <T> compareBy(vararg selectors: (T) -> Comparable<*>?): Comparator<T>

Creates a comparator using the sequence of functions to calculate a result of comparison. The functions are called sequentially, receive the given values a and b and return Comparable objects. As soon as the Comparable instances returned by a function for a and b values do not compare as equal, the result of that comparison is returned from the Comparator.

Since Kotlin 1.0
inline fun <T> compareBy(crossinline selector: (T) -> Comparable<*>?): Comparator<T>

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

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

Creates a comparator using the selector function to transform values being compared and then applying the specified comparator to compare transformed values.

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

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

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

Creates a descending comparator using the selector function to transform values being compared and then applying the specified comparator to compare transformed values.

Since Kotlin 1.0
Link copied to clipboard
fun <T : Comparable<*>> compareValues(a: T?, b: T?): Int

Compares two nullable Comparable values. Null is considered less than any value.

Since Kotlin 1.0
Link copied to clipboard
fun <T> compareValuesBy(a: T, b: T, vararg selectors: (T) -> Comparable<*>?): Int

Compares two values using the specified functions selectors to calculate the result of the comparison. The functions are called sequentially, receive the given values a and b and return Comparable objects. As soon as the Comparable instances returned by a function for a and b values do not compare as equal, the result of that comparison is returned.

Since Kotlin 1.0
inline fun <T> compareValuesBy(a: T, b: T, selector: (T) -> Comparable<*>?): Int

Compares two values using the specified selector function to calculate the result of the comparison. The function is applied to the given values a and b and return Comparable objects. The result of comparison of these Comparable instances is returned.

Since Kotlin 1.0
inline fun <T, K> compareValuesBy(a: T, b: T, comparator: Comparator<in K>, selector: (T) -> K): Int

Compares two values using the specified selector function to calculate the result of the comparison. The function is applied to the given values a and b and return objects of type K which are then being compared with the given comparator.

Since Kotlin 1.0
Link copied to clipboard
expect fun <T : Comparable<T>> maxOf(a: T, b: T): T
expect inline fun maxOf(a: Byte, b: Byte): Byte
expect inline fun maxOf(a: Double, b: Double): Double
expect inline fun maxOf(a: Float, b: Float): Float
expect inline fun maxOf(a: Int, b: Int): Int
expect inline fun maxOf(a: Long, b: Long): Long
expect inline fun maxOf(a: Short, b: Short): Short

Returns the greater of two values.

Since Kotlin 1.1
expect fun <T : Comparable<T>> maxOf(a: T, vararg other: T): T
expect fun maxOf(a: Byte, vararg other: Byte): Byte
expect fun maxOf(a: Double, vararg other: Double): Double
expect fun maxOf(a: Float, vararg other: Float): Float
expect fun maxOf(a: Int, vararg other: Int): Int
expect fun maxOf(a: Long, vararg other: Long): Long
expect fun maxOf(a: Short, vararg other: Short): Short
fun maxOf(a: UInt, vararg other: UInt): UInt

Returns the greater of the given values.

Since Kotlin 1.4
fun maxOf(a: UByte, b: UByte): UByte
fun maxOf(a: UInt, b: UInt): UInt
fun maxOf(a: ULong, b: ULong): ULong
fun maxOf(a: UShort, b: UShort): UShort

Returns the greater of two values.

Since Kotlin 1.5
fun <T> maxOf(a: T, b: T, comparator: Comparator<in T>): T

Returns the greater of two values according to the order specified by the given comparator.

Since Kotlin 1.1
fun <T> maxOf(a: T, vararg other: T, comparator: Comparator<in T>): T

Returns the greater of the given values according to the order specified by the given comparator.

Since Kotlin 1.4
expect fun <T : Comparable<T>> maxOf(a: T, b: T, c: T): T
expect inline fun maxOf(a: Byte, b: Byte, c: Byte): Byte
expect inline fun maxOf(a: Double, b: Double, c: Double): Double
expect inline fun maxOf(a: Float, b: Float, c: Float): Float
expect inline fun maxOf(a: Int, b: Int, c: Int): Int
expect inline fun maxOf(a: Long, b: Long, c: Long): Long
expect inline fun maxOf(a: Short, b: Short, c: Short): Short

Returns the greater of three values.

Since Kotlin 1.1
inline fun maxOf(a: UByte, b: UByte, c: UByte): UByte
inline fun maxOf(a: UInt, b: UInt, c: UInt): UInt
inline fun maxOf(a: ULong, b: ULong, c: ULong): ULong
inline fun maxOf(a: UShort, b: UShort, c: UShort): UShort

Returns the greater of three values.

Since Kotlin 1.5
fun <T> maxOf(a: T, b: T, c: T, comparator: Comparator<in T>): T

Returns the greater of three values according to the order specified by the given comparator.

Since Kotlin 1.1
actual fun <T : Comparable<T>> maxOf(a: T, b: T): T
actual inline fun maxOf(a: Byte, b: Byte): Byte
actual inline fun maxOf(a: Double, b: Double): Double
actual inline fun maxOf(a: Float, b: Float): Float
actual inline fun maxOf(a: Int, b: Int): Int
actual inline fun maxOf(a: Long, b: Long): Long
actual inline fun maxOf(a: Short, b: Short): Short

Returns the greater of two values.

Since Kotlin 1.1
actual fun <T : Comparable<T>> maxOf(a: T, vararg other: T): T
actual fun maxOf(a: Byte, vararg other: Byte): Byte
actual fun maxOf(a: Double, vararg other: Double): Double
actual fun maxOf(a: Float, vararg other: Float): Float
actual fun maxOf(a: Int, vararg other: Int): Int
actual fun maxOf(a: Long, vararg other: Long): Long
actual fun maxOf(a: Short, vararg other: Short): Short

Returns the greater of the given values.

Since Kotlin 1.4
actual fun <T : Comparable<T>> maxOf(a: T, b: T, c: T): T
actual inline fun maxOf(a: Byte, b: Byte, c: Byte): Byte
actual inline fun maxOf(a: Double, b: Double, c: Double): Double
actual inline fun maxOf(a: Float, b: Float, c: Float): Float
actual inline fun maxOf(a: Int, b: Int, c: Int): Int
actual inline fun maxOf(a: Long, b: Long, c: Long): Long
actual inline fun maxOf(a: Short, b: Short, c: Short): Short

Returns the greater of three values.

Since Kotlin 1.1
actual fun <T : Comparable<T>> maxOf(a: T, b: T): T
actual inline fun maxOf(a: Byte, b: Byte): Byte
actual inline fun maxOf(a: Double, b: Double): Double
actual inline fun maxOf(a: Float, b: Float): Float
actual inline fun maxOf(a: Int, b: Int): Int
actual inline fun maxOf(a: Long, b: Long): Long
actual inline fun maxOf(a: Short, b: Short): Short

Returns the greater of two values.

Since Kotlin 1.1
actual fun <T : Comparable<T>> maxOf(a: T, vararg other: T): T
actual fun maxOf(a: Byte, vararg other: Byte): Byte
actual fun maxOf(a: Double, vararg other: Double): Double
actual fun maxOf(a: Float, vararg other: Float): Float
actual fun maxOf(a: Int, vararg other: Int): Int
actual fun maxOf(a: Long, vararg other: Long): Long
actual fun maxOf(a: Short, vararg other: Short): Short

Returns the greater of the given values.

Since Kotlin 1.4
actual fun <T : Comparable<T>> maxOf(a: T, b: T, c: T): T
actual inline fun maxOf(a: Byte, b: Byte, c: Byte): Byte
actual inline fun maxOf(a: Double, b: Double, c: Double): Double
actual inline fun maxOf(a: Float, b: Float, c: Float): Float
actual inline fun maxOf(a: Int, b: Int, c: Int): Int
actual inline fun maxOf(a: Long, b: Long, c: Long): Long
actual inline fun maxOf(a: Short, b: Short, c: Short): Short

Returns the greater of three values.

Since Kotlin 1.1
actual fun <T : Comparable<T>> maxOf(a: T, b: T): T
actual inline fun maxOf(a: Byte, b: Byte): Byte
actual inline fun maxOf(a: Double, b: Double): Double
actual inline fun maxOf(a: Float, b: Float): Float
actual inline fun maxOf(a: Int, b: Int): Int
actual inline fun maxOf(a: Long, b: Long): Long
actual inline fun maxOf(a: Short, b: Short): Short

Returns the greater of two values.

Since Kotlin 1.3
actual fun <T : Comparable<T>> maxOf(a: T, vararg other: T): T
actual fun maxOf(a: Byte, vararg other: Byte): Byte
actual fun maxOf(a: Double, vararg other: Double): Double
actual fun maxOf(a: Float, vararg other: Float): Float
actual fun maxOf(a: Int, vararg other: Int): Int
actual fun maxOf(a: Long, vararg other: Long): Long
actual fun maxOf(a: Short, vararg other: Short): Short

Returns the greater of the given values.

Since Kotlin 1.4
actual fun <T : Comparable<T>> maxOf(a: T, b: T, c: T): T
actual inline fun maxOf(a: Byte, b: Byte, c: Byte): Byte
actual inline fun maxOf(a: Double, b: Double, c: Double): Double
actual inline fun maxOf(a: Float, b: Float, c: Float): Float
actual inline fun maxOf(a: Int, b: Int, c: Int): Int
actual inline fun maxOf(a: Long, b: Long, c: Long): Long
actual inline fun maxOf(a: Short, b: Short, c: Short): Short

Returns the greater of three values.

Since Kotlin 1.3
Link copied to clipboard
expect fun <T : Comparable<T>> minOf(a: T, b: T): T
expect inline fun minOf(a: Byte, b: Byte): Byte
expect inline fun minOf(a: Double, b: Double): Double
expect inline fun minOf(a: Float, b: Float): Float
expect inline fun minOf(a: Int, b: Int): Int
expect inline fun minOf(a: Long, b: Long): Long
expect inline fun minOf(a: Short, b: Short): Short

Returns the smaller of two values.

Since Kotlin 1.1
expect fun <T : Comparable<T>> minOf(a: T, vararg other: T): T
expect fun minOf(a: Byte, vararg other: Byte): Byte
expect fun minOf(a: Double, vararg other: Double): Double
expect fun minOf(a: Float, vararg other: Float): Float
expect fun minOf(a: Int, vararg other: Int): Int
expect fun minOf(a: Long, vararg other: Long): Long
expect fun minOf(a: Short, vararg other: Short): Short
fun minOf(a: UInt, vararg other: UInt): UInt

Returns the smaller of the given values.

Since Kotlin 1.4
fun minOf(a: UByte, b: UByte): UByte
fun minOf(a: UInt, b: UInt): UInt
fun minOf(a: ULong, b: ULong): ULong
fun minOf(a: UShort, b: UShort): UShort

Returns the smaller of two values.

Since Kotlin 1.5
fun <T> minOf(a: T, b: T, comparator: Comparator<in T>): T

Returns the smaller of two values according to the order specified by the given comparator.

Since Kotlin 1.1
fun <T> minOf(a: T, vararg other: T, comparator: Comparator<in T>): T

Returns the smaller of the given values according to the order specified by the given comparator.

Since Kotlin 1.4
expect fun <T : Comparable<T>> minOf(a: T, b: T, c: T): T
expect inline fun minOf(a: Byte, b: Byte, c: Byte): Byte
expect inline fun minOf(a: Double, b: Double, c: Double): Double
expect inline fun minOf(a: Float, b: Float, c: Float): Float
expect inline fun minOf(a: Int, b: Int, c: Int): Int
expect inline fun minOf(a: Long, b: Long, c: Long): Long
expect inline fun minOf(a: Short, b: Short, c: Short): Short

Returns the smaller of three values.

Since Kotlin 1.1
inline fun minOf(a: UByte, b: UByte, c: UByte): UByte
inline fun minOf(a: UInt, b: UInt, c: UInt): UInt
inline fun minOf(a: ULong, b: ULong, c: ULong): ULong
inline fun minOf(a: UShort, b: UShort, c: UShort): UShort

Returns the smaller of three values.

Since Kotlin 1.5
fun <T> minOf(a: T, b: T, c: T, comparator: Comparator<in T>): T

Returns the smaller of three values according to the order specified by the given comparator.

Since Kotlin 1.1
actual fun <T : Comparable<T>> minOf(a: T, b: T): T
actual inline fun minOf(a: Byte, b: Byte): Byte
actual inline fun minOf(a: Double, b: Double): Double
actual inline fun minOf(a: Float, b: Float): Float
actual inline fun minOf(a: Int, b: Int): Int
actual inline fun minOf(a: Long, b: Long): Long
actual inline fun minOf(a: Short, b: Short): Short

Returns the smaller of two values.

Since Kotlin 1.1
actual fun <T : Comparable<T>> minOf(a: T, vararg other: T): T
actual fun minOf(a: Byte, vararg other: Byte): Byte
actual fun minOf(a: Double, vararg other: Double): Double
actual fun minOf(a: Float, vararg other: Float): Float
actual fun minOf(a: Int, vararg other: Int): Int
actual fun minOf(a: Long, vararg other: Long): Long
actual fun minOf(a: Short, vararg other: Short): Short

Returns the smaller of the given values.

Since Kotlin 1.4
actual fun <T : Comparable<T>> minOf(a: T, b: T, c: T): T
actual inline fun minOf(a: Byte, b: Byte, c: Byte): Byte
actual inline fun minOf(a: Double, b: Double, c: Double): Double
actual inline fun minOf(a: Float, b: Float, c: Float): Float
actual inline fun minOf(a: Int, b: Int, c: Int): Int
actual inline fun minOf(a: Long, b: Long, c: Long): Long
actual inline fun minOf(a: Short, b: Short, c: Short): Short

Returns the smaller of three values.

Since Kotlin 1.1
actual fun <T : Comparable<T>> minOf(a: T, b: T): T
actual inline fun minOf(a: Byte, b: Byte): Byte
actual inline fun minOf(a: Double, b: Double): Double
actual inline fun minOf(a: Float, b: Float): Float
actual inline fun minOf(a: Int, b: Int): Int
actual inline fun minOf(a: Long, b: Long): Long
actual inline fun minOf(a: Short, b: Short): Short

Returns the smaller of two values.

Since Kotlin 1.1
actual fun <T : Comparable<T>> minOf(a: T, vararg other: T): T
actual fun minOf(a: Byte, vararg other: Byte): Byte
actual fun minOf(a: Double, vararg other: Double): Double
actual fun minOf(a: Float, vararg other: Float): Float
actual fun minOf(a: Int, vararg other: Int): Int
actual fun minOf(a: Long, vararg other: Long): Long
actual fun minOf(a: Short, vararg other: Short): Short

Returns the smaller of the given values.

Since Kotlin 1.4
actual fun <T : Comparable<T>> minOf(a: T, b: T, c: T): T
actual inline fun minOf(a: Byte, b: Byte, c: Byte): Byte
actual inline fun minOf(a: Double, b: Double, c: Double): Double
actual inline fun minOf(a: Float, b: Float, c: Float): Float
actual inline fun minOf(a: Int, b: Int, c: Int): Int
actual inline fun minOf(a: Long, b: Long, c: Long): Long
actual inline fun minOf(a: Short, b: Short, c: Short): Short

Returns the smaller of three values.

Since Kotlin 1.1
actual fun <T : Comparable<T>> minOf(a: T, b: T): T
actual inline fun minOf(a: Byte, b: Byte): Byte
actual inline fun minOf(a: Double, b: Double): Double
actual inline fun minOf(a: Float, b: Float): Float
actual inline fun minOf(a: Int, b: Int): Int
actual inline fun minOf(a: Long, b: Long): Long
actual inline fun minOf(a: Short, b: Short): Short

Returns the smaller of two values.

Since Kotlin 1.3
actual fun <T : Comparable<T>> minOf(a: T, vararg other: T): T
actual fun minOf(a: Byte, vararg other: Byte): Byte
actual fun minOf(a: Double, vararg other: Double): Double
actual fun minOf(a: Float, vararg other: Float): Float
actual fun minOf(a: Int, vararg other: Int): Int
actual fun minOf(a: Long, vararg other: Long): Long
actual fun minOf(a: Short, vararg other: Short): Short

Returns the smaller of the given values.

Since Kotlin 1.4
actual fun <T : Comparable<T>> minOf(a: T, b: T, c: T): T
actual inline fun minOf(a: Byte, b: Byte, c: Byte): Byte
actual inline fun minOf(a: Double, b: Double, c: Double): Double
actual inline fun minOf(a: Float, b: Float, c: Float): Float
actual inline fun minOf(a: Int, b: Int, c: Int): Int
actual inline fun minOf(a: Long, b: Long, c: Long): Long
actual inline fun minOf(a: Short, b: Short, c: Short): Short

Returns the smaller of three values.

Since Kotlin 1.3
Link copied to clipboard

Returns a comparator that compares Comparable objects in natural order.

Since Kotlin 1.0
Link copied to clipboard
inline fun <T : Comparable<T>> nullsFirst(): Comparator<T?>

Provides a comparator of nullable Comparable values considering null value less than any other value. Non-null values are compared according to their natural order.

Since Kotlin 1.0
fun <T : Any> nullsFirst(comparator: Comparator<in T>): Comparator<T?>

Extends the given comparator of non-nullable values to a comparator of nullable values considering null value less than any other value. Non-null values are compared with the provided comparator.

Since Kotlin 1.0
Link copied to clipboard
inline fun <T : Comparable<T>> nullsLast(): Comparator<T?>

Provides a comparator of nullable Comparable values considering null value greater than any other value. Non-null values are compared according to their natural order.

Since Kotlin 1.0
fun <T : Any> nullsLast(comparator: Comparator<in T>): Comparator<T?>

Extends the given comparator of non-nullable values to a comparator of nullable values considering null value greater than any other value. Non-null values are compared with the provided comparator.

Since Kotlin 1.0
Link copied to clipboard

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

Since Kotlin 1.0
Link copied to clipboard

Returns a comparator that compares Comparable objects in reversed natural order.

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