Add vararg overloads for maxOf/minOf functions #KT-33906

This commit is contained in:
Abduqodiri Qurbonzoda
2020-02-03 20:46:48 +03:00
parent 5aae3b5d27
commit 1f721796b8
10 changed files with 782 additions and 1 deletions
@@ -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
}
@@ -91,6 +91,50 @@ public inline fun maxOf(a: UShort, b: UShort, c: UShort): UShort {
return maxOf(a, maxOf(b, c))
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun maxOf(a: UInt, vararg other: UInt): UInt {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun maxOf(a: ULong, vararg other: ULong): ULong {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun maxOf(a: UByte, vararg other: UByte): UByte {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun maxOf(a: UShort, vararg other: UShort): UShort {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the smaller of two values.
*/
@@ -167,3 +211,47 @@ public inline fun minOf(a: UShort, b: UShort, c: UShort): UShort {
return minOf(a, minOf(b, c))
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun minOf(a: UInt, vararg other: UInt): UInt {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun minOf(a: ULong, vararg other: ULong): ULong {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun minOf(a: UByte, vararg other: UByte): UByte {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun minOf(a: UShort, vararg other: UShort): UShort {
var min = a
for (e in other) min = minOf(min, e)
return min
}
@@ -147,6 +147,76 @@ public actual inline fun maxOf(a: Double, b: Double, c: Double): Double {
return Math.max(a, b, c)
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun <T : Comparable<T>> maxOf(a: T, vararg other: T): T {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Byte, vararg other: Byte): Byte {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Short, vararg other: Short): Short {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Int, vararg other: Int): Int {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Long, vararg other: Long): Long {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Float, vararg other: Float): Float {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Double, vararg other: Double): Double {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the smaller of two values.
* If values are equal, returns the first one.
@@ -282,3 +352,73 @@ public actual inline fun minOf(a: Double, b: Double, c: Double): Double {
return Math.min(a, b, c)
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun <T : Comparable<T>> minOf(a: T, vararg other: T): T {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Byte, vararg other: Byte): Byte {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Short, vararg other: Short): Short {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Int, vararg other: Int): Int {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Long, vararg other: Long): Long {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Float, vararg other: Float): Float {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Double, vararg other: Double): Double {
var min = a
for (e in other) min = minOf(min, e)
return min
}
@@ -147,6 +147,76 @@ public actual inline fun maxOf(a: Double, b: Double, c: Double): Double {
return Math.max(a, b, c)
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun <T : Comparable<T>> maxOf(a: T, vararg other: T): T {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Byte, vararg other: Byte): Byte {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Short, vararg other: Short): Short {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Int, vararg other: Int): Int {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Long, vararg other: Long): Long {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Float, vararg other: Float): Float {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Double, vararg other: Double): Double {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the smaller of two values.
* If values are equal, returns the first one.
@@ -282,3 +352,73 @@ public actual inline fun minOf(a: Double, b: Double, c: Double): Double {
return Math.min(a, b, c)
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun <T : Comparable<T>> minOf(a: T, vararg other: T): T {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Byte, vararg other: Byte): Byte {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Short, vararg other: Short): Short {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Int, vararg other: Int): Int {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Long, vararg other: Long): Long {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Float, vararg other: Float): Float {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Double, vararg other: Double): Double {
var min = a
for (e in other) min = minOf(min, e)
return min
}
@@ -139,6 +139,76 @@ public actual inline fun maxOf(a: Double, b: Double, c: Double): Double {
return maxOf(a, maxOf(b, c))
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun <T : Comparable<T>> maxOf(a: T, vararg other: T): T {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Byte, vararg other: Byte): Byte {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Short, vararg other: Short): Short {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Int, vararg other: Int): Int {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Long, vararg other: Long): Long {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Float, vararg other: Float): Float {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the greater of given values.
*/
@SinceKotlin("1.4")
public actual fun maxOf(a: Double, vararg other: Double): Double {
var max = a
for (e in other) max = maxOf(max, e)
return max
}
/**
* Returns the smaller of two values.
* If values are equal, returns the first one.
@@ -264,3 +334,73 @@ public actual inline fun minOf(a: Double, b: Double, c: Double): Double {
return minOf(a, minOf(b, c))
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun <T : Comparable<T>> minOf(a: T, vararg other: T): T {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Byte, vararg other: Byte): Byte {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Short, vararg other: Short): Short {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Int, vararg other: Int): Int {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Long, vararg other: Long): Long {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Float, vararg other: Float): Float {
var min = a
for (e in other) min = minOf(min, e)
return min
}
/**
* Returns the smaller of given values.
*/
@SinceKotlin("1.4")
public actual fun minOf(a: Double, vararg other: Double): Double {
var min = a
for (e in other) min = minOf(min, e)
return min
}
+13
View File
@@ -20,6 +20,7 @@ class OrderingTest {
val v1 = Item("wine", 9)
val v2 = Item("beer", 10)
val v3 = Item("apple", 20)
val v4 = Item("grape", 22)
@Test
fun compareByCompareTo() {
@@ -154,44 +155,56 @@ class OrderingTest {
fun maxOf() {
assertEquals(Int.MAX_VALUE, maxOf(Int.MAX_VALUE, Int.MIN_VALUE))
assertEquals(Int.MAX_VALUE, maxOf(Int.MAX_VALUE, Int.MIN_VALUE, 0))
assertEquals(Int.MAX_VALUE, maxOf(Int.MAX_VALUE, Int.MIN_VALUE, 0, -1))
assertEquals(Long.MAX_VALUE, maxOf(Long.MAX_VALUE, Long.MIN_VALUE))
assertEquals(Long.MAX_VALUE, maxOf(Long.MAX_VALUE, Long.MIN_VALUE, 0))
assertEquals(Long.MAX_VALUE, maxOf(Long.MAX_VALUE, Long.MIN_VALUE, 0, -1))
assertEquals(Double.POSITIVE_INFINITY, maxOf(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY))
assertEquals(Double.POSITIVE_INFINITY, maxOf(Double.POSITIVE_INFINITY, Double.MAX_VALUE, Double.MIN_VALUE))
assertEquals(Double.POSITIVE_INFINITY, maxOf(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.MAX_VALUE, Double.MIN_VALUE))
assertEquals(0.0, maxOf(0.0, -0.0))
assertEquals(0.0, maxOf(-0.0, 0.0))
assertEquals(0.0, maxOf(-0.0, 0.0, 0.0, -0.0))
}
@Test
fun maxOfWith() {
assertEquals(v1, maxOf(v1, v2, compareBy { it.name }))
assertEquals(v1, maxOf(v3, v2, v1, compareBy { it.name }))
assertEquals(v1, maxOf(v4, v3, v2, v1, comparator = compareBy { it.name }))
assertEquals(v2, maxOf(v1, v2, compareBy { it.rating }))
assertEquals(v3, maxOf(v1, v2, v3, compareBy { it.rating }))
assertEquals(v4, maxOf(v4, v1, v2, v3, comparator = compareBy { it.rating }))
}
@Test
fun minOf() {
assertEquals(Int.MIN_VALUE, minOf(Int.MAX_VALUE, Int.MIN_VALUE))
assertEquals(Int.MIN_VALUE, minOf(Int.MAX_VALUE, Int.MIN_VALUE, 0))
assertEquals(Int.MIN_VALUE, minOf(Int.MAX_VALUE, Int.MIN_VALUE, 0, -1))
assertEquals(Long.MIN_VALUE, minOf(Long.MAX_VALUE, Long.MIN_VALUE))
assertEquals(Long.MIN_VALUE, minOf(Long.MAX_VALUE, Long.MIN_VALUE, 0))
assertEquals(Long.MIN_VALUE, minOf(Long.MAX_VALUE, Long.MIN_VALUE, 0, -1))
assertEquals(Double.NEGATIVE_INFINITY, minOf(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY))
assertEquals(Double.MIN_VALUE, minOf(Double.POSITIVE_INFINITY, Double.MAX_VALUE, Double.MIN_VALUE))
assertEquals(Double.NEGATIVE_INFINITY, minOf(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.MAX_VALUE, Double.MIN_VALUE))
assertEquals(-0.0, minOf(0.0, -0.0))
assertEquals(-0.0, minOf(-0.0, 0.0))
assertEquals(-0.0, minOf(-0.0, 0.0, 0.0, -0.0))
}
@Test
fun minOfWith() {
assertEquals(v2, minOf(v1, v2, compareBy { it.name }))
assertEquals(v3, minOf(v3, v2, v1, compareBy { it.name }))
assertEquals(v3, minOf(v4, v2, v3, v1, comparator = compareBy { it.name }))
assertEquals(v1, minOf(v1, v2, compareBy { it.rating }))
assertEquals(v1, minOf(v1, v2, v3, compareBy { it.rating }))
assertEquals(v1, minOf(v4, v1, v2, v3, comparator = compareBy { it.rating }))
}
}
@@ -58,12 +58,30 @@ class NaNPropagationTest {
propagateOf3(::minOf, ::minOf, "minOf")
}
@Test
fun minOfVararg() {
propagateOf3(
{ a, b, c -> minOf(a, *doubleArrayOf(b, c)) },
{ a, b, c -> minOf(a, *floatArrayOf(b, c)) },
"minOf(a, vararg other)"
)
}
@Test
fun maxOf() {
propagateOf2(::maxOf, ::maxOf, "maxOf")
propagateOf3(::maxOf, ::maxOf, "maxOf")
}
@Test
fun maxOfVararg() {
propagateOf3(
{ a, b, c -> maxOf(a, *doubleArrayOf(b, c)) },
{ a, b, c -> maxOf(a, *floatArrayOf(b, c)) },
"maxOf(a, vararg other)"
)
}
@Test
fun arrayMin() {
propagateOf2(
@@ -26,6 +26,14 @@ class UComparisonsTest {
expect(42312uL) { minOf(42312uL, 42312uL, 42312uL) }
}
@Test
fun minOf_vararg() {
expect(1.toUByte()) { minOf(2.toUByte(), 1.toUByte(), 3.toUByte(), 2.toUByte(), 10.toUByte()) }
expect(55.toUShort()) { minOf(58.toUShort(), 32768.toUShort(), 55.toUShort(), 2423.toUShort()) }
expect(UInt.MIN_VALUE) { minOf(UInt.MIN_VALUE, UInt.MAX_VALUE, 0u, 1000u, (-1).toUInt(), Int.MAX_VALUE.toUInt()) }
expect(42312uL) { minOf(42312uL, 42312uL, 42312uL, 42312uL) }
}
@Test
fun maxOf_2() {
expect(2.toUByte()) { maxOf(2.toUByte(), 1.toUByte()) }
@@ -41,4 +49,12 @@ class UComparisonsTest {
expect(UInt.MAX_VALUE) { maxOf(UInt.MIN_VALUE, UInt.MAX_VALUE, 0u) }
expect(42312uL) { maxOf(42312uL, 42312uL, 42312uL) }
}
@Test
fun maxOf_vararg() {
expect(10.toUByte()) { maxOf(2.toUByte(), 1.toUByte(), 3.toUByte(), 2.toUByte(), 10.toUByte()) }
expect(32768.toUShort()) { maxOf(58.toUShort(), 32768.toUShort(), 55.toUShort(), 2423.toUShort()) }
expect(UInt.MAX_VALUE) { maxOf(UInt.MIN_VALUE, UInt.MAX_VALUE, 0u, 1000u, (-1).toUInt(), Int.MAX_VALUE.toUInt()) }
expect(42312uL) { maxOf(42312uL, 42312uL, 42312uL, 42312uL) }
}
}
@@ -2605,14 +2605,30 @@ public final class kotlin/comparisons/ComparisonsKt {
public static final fun compareBy ([Lkotlin/jvm/functions/Function1;)Ljava/util/Comparator;
public static final fun compareValues (Ljava/lang/Comparable;Ljava/lang/Comparable;)I
public static final fun compareValuesBy (Ljava/lang/Object;Ljava/lang/Object;[Lkotlin/jvm/functions/Function1;)I
public static final fun maxOf (B[B)B
public static final fun maxOf (D[D)D
public static final fun maxOf (F[F)F
public static final fun maxOf (I[I)I
public static final fun maxOf (J[J)J
public static final fun maxOf (Ljava/lang/Comparable;Ljava/lang/Comparable;)Ljava/lang/Comparable;
public static final fun maxOf (Ljava/lang/Comparable;Ljava/lang/Comparable;Ljava/lang/Comparable;)Ljava/lang/Comparable;
public static final fun maxOf (Ljava/lang/Comparable;[Ljava/lang/Comparable;)Ljava/lang/Comparable;
public static final fun maxOf (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object;
public static final fun maxOf (Ljava/lang/Object;Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object;
public static final fun maxOf (Ljava/lang/Object;[Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object;
public static final fun maxOf (S[S)S
public static final fun minOf (B[B)B
public static final fun minOf (D[D)D
public static final fun minOf (F[F)F
public static final fun minOf (I[I)I
public static final fun minOf (J[J)J
public static final fun minOf (Ljava/lang/Comparable;Ljava/lang/Comparable;)Ljava/lang/Comparable;
public static final fun minOf (Ljava/lang/Comparable;Ljava/lang/Comparable;Ljava/lang/Comparable;)Ljava/lang/Comparable;
public static final fun minOf (Ljava/lang/Comparable;[Ljava/lang/Comparable;)Ljava/lang/Comparable;
public static final fun minOf (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object;
public static final fun minOf (Ljava/lang/Object;Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object;
public static final fun minOf (Ljava/lang/Object;[Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object;
public static final fun minOf (S[S)S
public static final fun naturalOrder ()Ljava/util/Comparator;
public static final fun nullsFirst (Ljava/util/Comparator;)Ljava/util/Comparator;
public static final fun nullsLast (Ljava/util/Comparator;)Ljava/util/Comparator;
@@ -2626,11 +2642,19 @@ public final class kotlin/comparisons/UComparisonsKt {
public static final fun maxOf-5PvTz6A (SS)S
public static final fun maxOf-J1ME1BU (II)I
public static final fun maxOf-Kr8caGY (BB)B
public static final fun maxOf-Md2H83M (I[I)I
public static final fun maxOf-R03FKyM (J[J)J
public static final fun maxOf-Wr6uiD8 (B[B)B
public static final fun maxOf-eb3DHEI (JJ)J
public static final fun maxOf-t1qELG4 (S[S)S
public static final fun minOf-5PvTz6A (SS)S
public static final fun minOf-J1ME1BU (II)I
public static final fun minOf-Kr8caGY (BB)B
public static final fun minOf-Md2H83M (I[I)I
public static final fun minOf-R03FKyM (J[J)J
public static final fun minOf-Wr6uiD8 (B[B)B
public static final fun minOf-eb3DHEI (JJ)J
public static final fun minOf-t1qELG4 (S[S)S
}
public final class kotlin/concurrent/ThreadsKt {
@@ -12,7 +12,7 @@ object ComparableOps : TemplateGroupBase() {
init {
defaultBuilder {
specialFor(Unsigned) {
since("1.3")
sinceAtLeast("1.3")
annotation("@ExperimentalUnsignedTypes")
}
}
@@ -259,6 +259,34 @@ object ComparableOps : TemplateGroupBase() {
}
}
val f_minOf_vararg = fn("minOf(a: T, vararg other: T)") {
include(Generic)
include(Primitives, numericPrimitives)
include(Unsigned)
} builder {
sourceFile(f.sourceFileComparisons)
since("1.4")
typeParam("T : Comparable<T>")
returns("T")
receiver("")
// TODO: Add a note about NaN propagation for floats.
doc {
"""
Returns the smaller of given values.
"""
}
body {
"""
var min = a
for (e in other) min = minOf(min, e)
return min
"""
}
specialFor(Generic, Primitives) {
on(Platform.JS) { /* just to make expect, KT-22520 */ }
}
}
val f_minOf_2_comparator = fn("minOf(a: T, b: T, comparator: Comparator<in T>)") {
include(Generic)
} builder {
@@ -294,6 +322,27 @@ object ComparableOps : TemplateGroupBase() {
}
}
val f_minOf_vararg_comparator = fn("minOf(a: T, vararg other: T, comparator: Comparator<in T>)") {
include(Generic)
} builder {
sourceFile(f.sourceFileComparisons)
since("1.4")
returns("T")
receiver("")
doc {
"""
Returns the smaller of given values according to the order specified by the given [comparator].
"""
}
body {
"""
var min = a
for (e in other) if (comparator.compare(min, e) > 0) min = e
return min
"""
}
}
val f_maxOf_2 = fn("maxOf(a: T, b: T)") {
include(Generic)
include(Primitives, numericPrimitives)
@@ -398,6 +447,34 @@ object ComparableOps : TemplateGroupBase() {
}
}
val f_maxOf_vararg = fn("maxOf(a: T, vararg other: T)") {
include(Generic)
include(Primitives, numericPrimitives)
include(Unsigned)
} builder {
sourceFile(f.sourceFileComparisons)
since("1.4")
typeParam("T : Comparable<T>")
returns("T")
receiver("")
// TODO: Add a note about NaN propagation for floats.
doc {
"""
Returns the greater of given values.
"""
}
body {
"""
var max = a
for (e in other) max = maxOf(max, e)
return max
"""
}
specialFor(Generic, Primitives) {
on(Platform.JS) { /* just to make expect, KT-22520 */ }
}
}
val f_maxOf_2_comparator = fn("maxOf(a: T, b: T, comparator: Comparator<in T>)") {
include(Generic)
} builder {
@@ -433,6 +510,27 @@ object ComparableOps : TemplateGroupBase() {
}
}
val f_maxOf_vararg_comparator = fn("maxOf(a: T, vararg other: T, comparator: Comparator<in T>)") {
include(Generic)
} builder {
sourceFile(f.sourceFileComparisons)
since("1.4")
returns("T")
receiver("")
doc {
"""
Returns the greater of given values according to the order specified by the given [comparator].
"""
}
body {
"""
var max = a
for (e in other) if (comparator.compare(max, e) < 0) max = e
return max
"""
}
}
val f_coerceIn_min_max = fn("coerceIn(minimumValue: SELF, maximumValue: SELF)") {
include(Generic)