Add vararg overloads for maxOf/minOf functions #KT-33906
This commit is contained in:
@@ -129,6 +129,58 @@ public fun <T> maxOf(a: T, b: T, comparator: Comparator<in T>): T {
|
||||
return if (comparator.compare(a, b) >= 0) a else b
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the greater of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun <T : Comparable<T>> maxOf(a: T, vararg other: T): T
|
||||
|
||||
/**
|
||||
* Returns the greater of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun maxOf(a: Byte, vararg other: Byte): Byte
|
||||
|
||||
/**
|
||||
* Returns the greater of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun maxOf(a: Short, vararg other: Short): Short
|
||||
|
||||
/**
|
||||
* Returns the greater of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun maxOf(a: Int, vararg other: Int): Int
|
||||
|
||||
/**
|
||||
* Returns the greater of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun maxOf(a: Long, vararg other: Long): Long
|
||||
|
||||
/**
|
||||
* Returns the greater of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun maxOf(a: Float, vararg other: Float): Float
|
||||
|
||||
/**
|
||||
* Returns the greater of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun maxOf(a: Double, vararg other: Double): Double
|
||||
|
||||
/**
|
||||
* Returns the greater of given values according to the order specified by the given [comparator].
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun <T> maxOf(a: T, vararg other: T, comparator: Comparator<in T>): T {
|
||||
var max = a
|
||||
for (e in other) if (comparator.compare(max, e) < 0) max = e
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smaller of two values.
|
||||
* If values are equal, returns the first one.
|
||||
@@ -243,3 +295,55 @@ public fun <T> minOf(a: T, b: T, comparator: Comparator<in T>): T {
|
||||
return if (comparator.compare(a, b) <= 0) a else b
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smaller of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun <T : Comparable<T>> minOf(a: T, vararg other: T): T
|
||||
|
||||
/**
|
||||
* Returns the smaller of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun minOf(a: Byte, vararg other: Byte): Byte
|
||||
|
||||
/**
|
||||
* Returns the smaller of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun minOf(a: Short, vararg other: Short): Short
|
||||
|
||||
/**
|
||||
* Returns the smaller of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun minOf(a: Int, vararg other: Int): Int
|
||||
|
||||
/**
|
||||
* Returns the smaller of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun minOf(a: Long, vararg other: Long): Long
|
||||
|
||||
/**
|
||||
* Returns the smaller of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun minOf(a: Float, vararg other: Float): Float
|
||||
|
||||
/**
|
||||
* Returns the smaller of given values.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public expect fun minOf(a: Double, vararg other: Double): Double
|
||||
|
||||
/**
|
||||
* Returns the smaller of given values according to the order specified by the given [comparator].
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun <T> minOf(a: T, vararg other: T, comparator: Comparator<in T>): T {
|
||||
var min = a
|
||||
for (e in other) if (comparator.compare(min, e) > 0) min = e
|
||||
return min
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user