From b4ba00ca366324f19bda581dd4605d785b4c69cb Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 21 May 2020 23:42:57 +0300 Subject: [PATCH] Document and test NaN propagation of maxOf/minOf Also simplify minOf/maxOf implementations #KT-38708 --- .../stdlib/common/src/generated/_Arrays.kt | 936 ++++-------------- .../common/src/generated/_Collections.kt | 68 +- .../stdlib/common/src/generated/_Maps.kt | 16 + .../stdlib/common/src/generated/_Sequences.kt | 68 +- .../stdlib/common/src/generated/_Strings.kt | 104 +- .../stdlib/common/src/generated/_UArrays.kt | 416 ++------ .../stdlib/test/collections/CollectionTest.kt | 11 +- .../stdlib/test/numbers/NaNPropagationTest.kt | 83 +- libraries/stdlib/test/testUtils.kt | 15 +- .../src/templates/Aggregates.kt | 29 +- 10 files changed, 514 insertions(+), 1232 deletions(-) diff --git a/libraries/stdlib/common/src/generated/_Arrays.kt b/libraries/stdlib/common/src/generated/_Arrays.kt index 061219d1257..9b709991a3f 100644 --- a/libraries/stdlib/common/src/generated/_Arrays.kt +++ b/libraries/stdlib/common/src/generated/_Arrays.kt @@ -13425,6 +13425,8 @@ public inline fun > CharArray.maxBy(selector: (Char) -> R): Ch * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13434,15 +13436,9 @@ public inline fun > CharArray.maxBy(selector: (Char) -> R): Ch public inline fun Array.maxOf(selector: (T) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13451,6 +13447,8 @@ public inline fun Array.maxOf(selector: (T) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13460,15 +13458,9 @@ public inline fun Array.maxOf(selector: (T) -> Double): Double { public inline fun ByteArray.maxOf(selector: (Byte) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13477,6 +13469,8 @@ public inline fun ByteArray.maxOf(selector: (Byte) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13486,15 +13480,9 @@ public inline fun ByteArray.maxOf(selector: (Byte) -> Double): Double { public inline fun ShortArray.maxOf(selector: (Short) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13503,6 +13491,8 @@ public inline fun ShortArray.maxOf(selector: (Short) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13512,15 +13502,9 @@ public inline fun ShortArray.maxOf(selector: (Short) -> Double): Double { public inline fun IntArray.maxOf(selector: (Int) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13529,6 +13513,8 @@ public inline fun IntArray.maxOf(selector: (Int) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13538,15 +13524,9 @@ public inline fun IntArray.maxOf(selector: (Int) -> Double): Double { public inline fun LongArray.maxOf(selector: (Long) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13555,6 +13535,8 @@ public inline fun LongArray.maxOf(selector: (Long) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13564,15 +13546,9 @@ public inline fun LongArray.maxOf(selector: (Long) -> Double): Double { public inline fun FloatArray.maxOf(selector: (Float) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13581,6 +13557,8 @@ public inline fun FloatArray.maxOf(selector: (Float) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13590,15 +13568,9 @@ public inline fun FloatArray.maxOf(selector: (Float) -> Double): Double { public inline fun DoubleArray.maxOf(selector: (Double) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13607,6 +13579,8 @@ public inline fun DoubleArray.maxOf(selector: (Double) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13616,15 +13590,9 @@ public inline fun DoubleArray.maxOf(selector: (Double) -> Double): Double { public inline fun BooleanArray.maxOf(selector: (Boolean) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13633,6 +13601,8 @@ public inline fun BooleanArray.maxOf(selector: (Boolean) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13642,15 +13612,9 @@ public inline fun BooleanArray.maxOf(selector: (Boolean) -> Double): Double { public inline fun CharArray.maxOf(selector: (Char) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13659,6 +13623,8 @@ public inline fun CharArray.maxOf(selector: (Char) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13668,15 +13634,9 @@ public inline fun CharArray.maxOf(selector: (Char) -> Double): Double { public inline fun Array.maxOf(selector: (T) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13685,6 +13645,8 @@ public inline fun Array.maxOf(selector: (T) -> Float): Float { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13694,15 +13656,9 @@ public inline fun Array.maxOf(selector: (T) -> Float): Float { public inline fun ByteArray.maxOf(selector: (Byte) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13711,6 +13667,8 @@ public inline fun ByteArray.maxOf(selector: (Byte) -> Float): Float { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13720,15 +13678,9 @@ public inline fun ByteArray.maxOf(selector: (Byte) -> Float): Float { public inline fun ShortArray.maxOf(selector: (Short) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13737,6 +13689,8 @@ public inline fun ShortArray.maxOf(selector: (Short) -> Float): Float { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13746,15 +13700,9 @@ public inline fun ShortArray.maxOf(selector: (Short) -> Float): Float { public inline fun IntArray.maxOf(selector: (Int) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13763,6 +13711,8 @@ public inline fun IntArray.maxOf(selector: (Int) -> Float): Float { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13772,15 +13722,9 @@ public inline fun IntArray.maxOf(selector: (Int) -> Float): Float { public inline fun LongArray.maxOf(selector: (Long) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13789,6 +13733,8 @@ public inline fun LongArray.maxOf(selector: (Long) -> Float): Float { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13798,15 +13744,9 @@ public inline fun LongArray.maxOf(selector: (Long) -> Float): Float { public inline fun FloatArray.maxOf(selector: (Float) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13815,6 +13755,8 @@ public inline fun FloatArray.maxOf(selector: (Float) -> Float): Float { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13824,15 +13766,9 @@ public inline fun FloatArray.maxOf(selector: (Float) -> Float): Float { public inline fun DoubleArray.maxOf(selector: (Double) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13841,6 +13777,8 @@ public inline fun DoubleArray.maxOf(selector: (Double) -> Float): Float { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13850,15 +13788,9 @@ public inline fun DoubleArray.maxOf(selector: (Double) -> Float): Float { public inline fun BooleanArray.maxOf(selector: (Boolean) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13867,6 +13799,8 @@ public inline fun BooleanArray.maxOf(selector: (Boolean) -> Float): Float { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -13876,15 +13810,9 @@ public inline fun BooleanArray.maxOf(selector: (Boolean) -> Float): Float { public inline fun CharArray.maxOf(selector: (Char) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -13902,12 +13830,8 @@ public inline fun CharArray.maxOf(selector: (Char) -> Float): Float { public inline fun > Array.maxOf(selector: (T) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -13928,12 +13852,8 @@ public inline fun > Array.maxOf(selector: (T) -> R): public inline fun > ByteArray.maxOf(selector: (Byte) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -13954,12 +13874,8 @@ public inline fun > ByteArray.maxOf(selector: (Byte) -> R): R public inline fun > ShortArray.maxOf(selector: (Short) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -13980,12 +13896,8 @@ public inline fun > ShortArray.maxOf(selector: (Short) -> R): public inline fun > IntArray.maxOf(selector: (Int) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14006,12 +13918,8 @@ public inline fun > IntArray.maxOf(selector: (Int) -> R): R { public inline fun > LongArray.maxOf(selector: (Long) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14032,12 +13940,8 @@ public inline fun > LongArray.maxOf(selector: (Long) -> R): R public inline fun > FloatArray.maxOf(selector: (Float) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14058,12 +13962,8 @@ public inline fun > FloatArray.maxOf(selector: (Float) -> R): public inline fun > DoubleArray.maxOf(selector: (Double) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14084,12 +13984,8 @@ public inline fun > DoubleArray.maxOf(selector: (Double) -> R) public inline fun > BooleanArray.maxOf(selector: (Boolean) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14110,12 +14006,8 @@ public inline fun > BooleanArray.maxOf(selector: (Boolean) -> public inline fun > CharArray.maxOf(selector: (Char) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14126,6 +14018,8 @@ public inline fun > CharArray.maxOf(selector: (Char) -> R): R /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14134,15 +14028,9 @@ public inline fun > CharArray.maxOf(selector: (Char) -> R): R public inline fun Array.maxOfOrNull(selector: (T) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14150,6 +14038,8 @@ public inline fun Array.maxOfOrNull(selector: (T) -> Double): Double? /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14158,15 +14048,9 @@ public inline fun Array.maxOfOrNull(selector: (T) -> Double): Double? public inline fun ByteArray.maxOfOrNull(selector: (Byte) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14174,6 +14058,8 @@ public inline fun ByteArray.maxOfOrNull(selector: (Byte) -> Double): Double? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14182,15 +14068,9 @@ public inline fun ByteArray.maxOfOrNull(selector: (Byte) -> Double): Double? { public inline fun ShortArray.maxOfOrNull(selector: (Short) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14198,6 +14078,8 @@ public inline fun ShortArray.maxOfOrNull(selector: (Short) -> Double): Double? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14206,15 +14088,9 @@ public inline fun ShortArray.maxOfOrNull(selector: (Short) -> Double): Double? { public inline fun IntArray.maxOfOrNull(selector: (Int) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14222,6 +14098,8 @@ public inline fun IntArray.maxOfOrNull(selector: (Int) -> Double): Double? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14230,15 +14108,9 @@ public inline fun IntArray.maxOfOrNull(selector: (Int) -> Double): Double? { public inline fun LongArray.maxOfOrNull(selector: (Long) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14246,6 +14118,8 @@ public inline fun LongArray.maxOfOrNull(selector: (Long) -> Double): Double? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14254,15 +14128,9 @@ public inline fun LongArray.maxOfOrNull(selector: (Long) -> Double): Double? { public inline fun FloatArray.maxOfOrNull(selector: (Float) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14270,6 +14138,8 @@ public inline fun FloatArray.maxOfOrNull(selector: (Float) -> Double): Double? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14278,15 +14148,9 @@ public inline fun FloatArray.maxOfOrNull(selector: (Float) -> Double): Double? { public inline fun DoubleArray.maxOfOrNull(selector: (Double) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14294,6 +14158,8 @@ public inline fun DoubleArray.maxOfOrNull(selector: (Double) -> Double): Double? /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14302,15 +14168,9 @@ public inline fun DoubleArray.maxOfOrNull(selector: (Double) -> Double): Double? public inline fun BooleanArray.maxOfOrNull(selector: (Boolean) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14318,6 +14178,8 @@ public inline fun BooleanArray.maxOfOrNull(selector: (Boolean) -> Double): Doubl /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14326,15 +14188,9 @@ public inline fun BooleanArray.maxOfOrNull(selector: (Boolean) -> Double): Doubl public inline fun CharArray.maxOfOrNull(selector: (Char) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14342,6 +14198,8 @@ public inline fun CharArray.maxOfOrNull(selector: (Char) -> Double): Double? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14350,15 +14208,9 @@ public inline fun CharArray.maxOfOrNull(selector: (Char) -> Double): Double? { public inline fun Array.maxOfOrNull(selector: (T) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14366,6 +14218,8 @@ public inline fun Array.maxOfOrNull(selector: (T) -> Float): Float? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14374,15 +14228,9 @@ public inline fun Array.maxOfOrNull(selector: (T) -> Float): Float? { public inline fun ByteArray.maxOfOrNull(selector: (Byte) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14390,6 +14238,8 @@ public inline fun ByteArray.maxOfOrNull(selector: (Byte) -> Float): Float? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14398,15 +14248,9 @@ public inline fun ByteArray.maxOfOrNull(selector: (Byte) -> Float): Float? { public inline fun ShortArray.maxOfOrNull(selector: (Short) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14414,6 +14258,8 @@ public inline fun ShortArray.maxOfOrNull(selector: (Short) -> Float): Float? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14422,15 +14268,9 @@ public inline fun ShortArray.maxOfOrNull(selector: (Short) -> Float): Float? { public inline fun IntArray.maxOfOrNull(selector: (Int) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14438,6 +14278,8 @@ public inline fun IntArray.maxOfOrNull(selector: (Int) -> Float): Float? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14446,15 +14288,9 @@ public inline fun IntArray.maxOfOrNull(selector: (Int) -> Float): Float? { public inline fun LongArray.maxOfOrNull(selector: (Long) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14462,6 +14298,8 @@ public inline fun LongArray.maxOfOrNull(selector: (Long) -> Float): Float? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14470,15 +14308,9 @@ public inline fun LongArray.maxOfOrNull(selector: (Long) -> Float): Float? { public inline fun FloatArray.maxOfOrNull(selector: (Float) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14486,6 +14318,8 @@ public inline fun FloatArray.maxOfOrNull(selector: (Float) -> Float): Float? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14494,15 +14328,9 @@ public inline fun FloatArray.maxOfOrNull(selector: (Float) -> Float): Float? { public inline fun DoubleArray.maxOfOrNull(selector: (Double) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14510,6 +14338,8 @@ public inline fun DoubleArray.maxOfOrNull(selector: (Double) -> Float): Float? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14518,15 +14348,9 @@ public inline fun DoubleArray.maxOfOrNull(selector: (Double) -> Float): Float? { public inline fun BooleanArray.maxOfOrNull(selector: (Boolean) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14534,6 +14358,8 @@ public inline fun BooleanArray.maxOfOrNull(selector: (Boolean) -> Float): Float? /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -14542,15 +14368,9 @@ public inline fun BooleanArray.maxOfOrNull(selector: (Boolean) -> Float): Float? public inline fun CharArray.maxOfOrNull(selector: (Char) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -14566,12 +14386,8 @@ public inline fun CharArray.maxOfOrNull(selector: (Char) -> Float): Float? { public inline fun > Array.maxOfOrNull(selector: (T) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14590,12 +14406,8 @@ public inline fun > Array.maxOfOrNull(selector: (T) public inline fun > ByteArray.maxOfOrNull(selector: (Byte) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14614,12 +14426,8 @@ public inline fun > ByteArray.maxOfOrNull(selector: (Byte) -> public inline fun > ShortArray.maxOfOrNull(selector: (Short) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14638,12 +14446,8 @@ public inline fun > ShortArray.maxOfOrNull(selector: (Short) - public inline fun > IntArray.maxOfOrNull(selector: (Int) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14662,12 +14466,8 @@ public inline fun > IntArray.maxOfOrNull(selector: (Int) -> R) public inline fun > LongArray.maxOfOrNull(selector: (Long) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14686,12 +14486,8 @@ public inline fun > LongArray.maxOfOrNull(selector: (Long) -> public inline fun > FloatArray.maxOfOrNull(selector: (Float) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14710,12 +14506,8 @@ public inline fun > FloatArray.maxOfOrNull(selector: (Float) - public inline fun > DoubleArray.maxOfOrNull(selector: (Double) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14734,12 +14526,8 @@ public inline fun > DoubleArray.maxOfOrNull(selector: (Double) public inline fun > BooleanArray.maxOfOrNull(selector: (Boolean) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14758,12 +14546,8 @@ public inline fun > BooleanArray.maxOfOrNull(selector: (Boolea public inline fun > CharArray.maxOfOrNull(selector: (Char) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -14784,8 +14568,6 @@ public inline fun > CharArray.maxOfOrNull(selector: (Char) -> public inline fun Array.maxOfWith(comparator: Comparator, selector: (T) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -14808,8 +14590,6 @@ public inline fun Array.maxOfWith(comparator: Comparator, se public inline fun ByteArray.maxOfWith(comparator: Comparator, selector: (Byte) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -14832,8 +14612,6 @@ public inline fun ByteArray.maxOfWith(comparator: Comparator, selector public inline fun ShortArray.maxOfWith(comparator: Comparator, selector: (Short) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -14856,8 +14634,6 @@ public inline fun ShortArray.maxOfWith(comparator: Comparator, selecto public inline fun IntArray.maxOfWith(comparator: Comparator, selector: (Int) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -14880,8 +14656,6 @@ public inline fun IntArray.maxOfWith(comparator: Comparator, selector: public inline fun LongArray.maxOfWith(comparator: Comparator, selector: (Long) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -14904,8 +14678,6 @@ public inline fun LongArray.maxOfWith(comparator: Comparator, selector public inline fun FloatArray.maxOfWith(comparator: Comparator, selector: (Float) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -14928,8 +14700,6 @@ public inline fun FloatArray.maxOfWith(comparator: Comparator, selecto public inline fun DoubleArray.maxOfWith(comparator: Comparator, selector: (Double) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -14952,8 +14722,6 @@ public inline fun DoubleArray.maxOfWith(comparator: Comparator, select public inline fun BooleanArray.maxOfWith(comparator: Comparator, selector: (Boolean) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -14976,8 +14744,6 @@ public inline fun BooleanArray.maxOfWith(comparator: Comparator, selec public inline fun CharArray.maxOfWith(comparator: Comparator, selector: (Char) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -14998,8 +14764,6 @@ public inline fun CharArray.maxOfWith(comparator: Comparator, selector public inline fun Array.maxOfWithOrNull(comparator: Comparator, selector: (T) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -15020,8 +14784,6 @@ public inline fun Array.maxOfWithOrNull(comparator: Comparator ByteArray.maxOfWithOrNull(comparator: Comparator, selector: (Byte) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -15042,8 +14804,6 @@ public inline fun ByteArray.maxOfWithOrNull(comparator: Comparator, se public inline fun ShortArray.maxOfWithOrNull(comparator: Comparator, selector: (Short) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -15064,8 +14824,6 @@ public inline fun ShortArray.maxOfWithOrNull(comparator: Comparator, s public inline fun IntArray.maxOfWithOrNull(comparator: Comparator, selector: (Int) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -15086,8 +14844,6 @@ public inline fun IntArray.maxOfWithOrNull(comparator: Comparator, sel public inline fun LongArray.maxOfWithOrNull(comparator: Comparator, selector: (Long) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -15108,8 +14864,6 @@ public inline fun LongArray.maxOfWithOrNull(comparator: Comparator, se public inline fun FloatArray.maxOfWithOrNull(comparator: Comparator, selector: (Float) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -15130,8 +14884,6 @@ public inline fun FloatArray.maxOfWithOrNull(comparator: Comparator, s public inline fun DoubleArray.maxOfWithOrNull(comparator: Comparator, selector: (Double) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -15152,8 +14904,6 @@ public inline fun DoubleArray.maxOfWithOrNull(comparator: Comparator, public inline fun BooleanArray.maxOfWithOrNull(comparator: Comparator, selector: (Boolean) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -15174,8 +14924,6 @@ public inline fun BooleanArray.maxOfWithOrNull(comparator: Comparator, public inline fun CharArray.maxOfWithOrNull(comparator: Comparator, selector: (Char) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -15652,6 +15400,8 @@ public inline fun > CharArray.minBy(selector: (Char) -> R): Ch * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15661,15 +15411,9 @@ public inline fun > CharArray.minBy(selector: (Char) -> R): Ch public inline fun Array.minOf(selector: (T) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -15678,6 +15422,8 @@ public inline fun Array.minOf(selector: (T) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15687,15 +15433,9 @@ public inline fun Array.minOf(selector: (T) -> Double): Double { public inline fun ByteArray.minOf(selector: (Byte) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -15704,6 +15444,8 @@ public inline fun ByteArray.minOf(selector: (Byte) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15713,15 +15455,9 @@ public inline fun ByteArray.minOf(selector: (Byte) -> Double): Double { public inline fun ShortArray.minOf(selector: (Short) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -15730,6 +15466,8 @@ public inline fun ShortArray.minOf(selector: (Short) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15739,15 +15477,9 @@ public inline fun ShortArray.minOf(selector: (Short) -> Double): Double { public inline fun IntArray.minOf(selector: (Int) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -15756,6 +15488,8 @@ public inline fun IntArray.minOf(selector: (Int) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15765,15 +15499,9 @@ public inline fun IntArray.minOf(selector: (Int) -> Double): Double { public inline fun LongArray.minOf(selector: (Long) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -15782,6 +15510,8 @@ public inline fun LongArray.minOf(selector: (Long) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15791,15 +15521,9 @@ public inline fun LongArray.minOf(selector: (Long) -> Double): Double { public inline fun FloatArray.minOf(selector: (Float) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -15808,6 +15532,8 @@ public inline fun FloatArray.minOf(selector: (Float) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15817,15 +15543,9 @@ public inline fun FloatArray.minOf(selector: (Float) -> Double): Double { public inline fun DoubleArray.minOf(selector: (Double) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -15834,6 +15554,8 @@ public inline fun DoubleArray.minOf(selector: (Double) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15843,15 +15565,9 @@ public inline fun DoubleArray.minOf(selector: (Double) -> Double): Double { public inline fun BooleanArray.minOf(selector: (Boolean) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -15860,6 +15576,8 @@ public inline fun BooleanArray.minOf(selector: (Boolean) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15869,15 +15587,9 @@ public inline fun BooleanArray.minOf(selector: (Boolean) -> Double): Double { public inline fun CharArray.minOf(selector: (Char) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -15886,6 +15598,8 @@ public inline fun CharArray.minOf(selector: (Char) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15895,15 +15609,9 @@ public inline fun CharArray.minOf(selector: (Char) -> Double): Double { public inline fun Array.minOf(selector: (T) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -15912,6 +15620,8 @@ public inline fun Array.minOf(selector: (T) -> Float): Float { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15921,15 +15631,9 @@ public inline fun Array.minOf(selector: (T) -> Float): Float { public inline fun ByteArray.minOf(selector: (Byte) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -15938,6 +15642,8 @@ public inline fun ByteArray.minOf(selector: (Byte) -> Float): Float { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15947,15 +15653,9 @@ public inline fun ByteArray.minOf(selector: (Byte) -> Float): Float { public inline fun ShortArray.minOf(selector: (Short) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -15964,6 +15664,8 @@ public inline fun ShortArray.minOf(selector: (Short) -> Float): Float { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15973,15 +15675,9 @@ public inline fun ShortArray.minOf(selector: (Short) -> Float): Float { public inline fun IntArray.minOf(selector: (Int) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -15990,6 +15686,8 @@ public inline fun IntArray.minOf(selector: (Int) -> Float): Float { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -15999,15 +15697,9 @@ public inline fun IntArray.minOf(selector: (Int) -> Float): Float { public inline fun LongArray.minOf(selector: (Long) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16016,6 +15708,8 @@ public inline fun LongArray.minOf(selector: (Long) -> Float): Float { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -16025,15 +15719,9 @@ public inline fun LongArray.minOf(selector: (Long) -> Float): Float { public inline fun FloatArray.minOf(selector: (Float) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16042,6 +15730,8 @@ public inline fun FloatArray.minOf(selector: (Float) -> Float): Float { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -16051,15 +15741,9 @@ public inline fun FloatArray.minOf(selector: (Float) -> Float): Float { public inline fun DoubleArray.minOf(selector: (Double) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16068,6 +15752,8 @@ public inline fun DoubleArray.minOf(selector: (Double) -> Float): Float { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -16077,15 +15763,9 @@ public inline fun DoubleArray.minOf(selector: (Double) -> Float): Float { public inline fun BooleanArray.minOf(selector: (Boolean) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16094,6 +15774,8 @@ public inline fun BooleanArray.minOf(selector: (Boolean) -> Float): Float { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -16103,15 +15785,9 @@ public inline fun BooleanArray.minOf(selector: (Boolean) -> Float): Float { public inline fun CharArray.minOf(selector: (Char) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16129,12 +15805,8 @@ public inline fun CharArray.minOf(selector: (Char) -> Float): Float { public inline fun > Array.minOf(selector: (T) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16155,12 +15827,8 @@ public inline fun > Array.minOf(selector: (T) -> R): public inline fun > ByteArray.minOf(selector: (Byte) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16181,12 +15849,8 @@ public inline fun > ByteArray.minOf(selector: (Byte) -> R): R public inline fun > ShortArray.minOf(selector: (Short) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16207,12 +15871,8 @@ public inline fun > ShortArray.minOf(selector: (Short) -> R): public inline fun > IntArray.minOf(selector: (Int) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16233,12 +15893,8 @@ public inline fun > IntArray.minOf(selector: (Int) -> R): R { public inline fun > LongArray.minOf(selector: (Long) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16259,12 +15915,8 @@ public inline fun > LongArray.minOf(selector: (Long) -> R): R public inline fun > FloatArray.minOf(selector: (Float) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16285,12 +15937,8 @@ public inline fun > FloatArray.minOf(selector: (Float) -> R): public inline fun > DoubleArray.minOf(selector: (Double) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16311,12 +15959,8 @@ public inline fun > DoubleArray.minOf(selector: (Double) -> R) public inline fun > BooleanArray.minOf(selector: (Boolean) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16337,12 +15981,8 @@ public inline fun > BooleanArray.minOf(selector: (Boolean) -> public inline fun > CharArray.minOf(selector: (Char) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16353,6 +15993,8 @@ public inline fun > CharArray.minOf(selector: (Char) -> R): R /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16361,15 +16003,9 @@ public inline fun > CharArray.minOf(selector: (Char) -> R): R public inline fun Array.minOfOrNull(selector: (T) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16377,6 +16013,8 @@ public inline fun Array.minOfOrNull(selector: (T) -> Double): Double? /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16385,15 +16023,9 @@ public inline fun Array.minOfOrNull(selector: (T) -> Double): Double? public inline fun ByteArray.minOfOrNull(selector: (Byte) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16401,6 +16033,8 @@ public inline fun ByteArray.minOfOrNull(selector: (Byte) -> Double): Double? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16409,15 +16043,9 @@ public inline fun ByteArray.minOfOrNull(selector: (Byte) -> Double): Double? { public inline fun ShortArray.minOfOrNull(selector: (Short) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16425,6 +16053,8 @@ public inline fun ShortArray.minOfOrNull(selector: (Short) -> Double): Double? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16433,15 +16063,9 @@ public inline fun ShortArray.minOfOrNull(selector: (Short) -> Double): Double? { public inline fun IntArray.minOfOrNull(selector: (Int) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16449,6 +16073,8 @@ public inline fun IntArray.minOfOrNull(selector: (Int) -> Double): Double? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16457,15 +16083,9 @@ public inline fun IntArray.minOfOrNull(selector: (Int) -> Double): Double? { public inline fun LongArray.minOfOrNull(selector: (Long) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16473,6 +16093,8 @@ public inline fun LongArray.minOfOrNull(selector: (Long) -> Double): Double? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16481,15 +16103,9 @@ public inline fun LongArray.minOfOrNull(selector: (Long) -> Double): Double? { public inline fun FloatArray.minOfOrNull(selector: (Float) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16497,6 +16113,8 @@ public inline fun FloatArray.minOfOrNull(selector: (Float) -> Double): Double? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16505,15 +16123,9 @@ public inline fun FloatArray.minOfOrNull(selector: (Float) -> Double): Double? { public inline fun DoubleArray.minOfOrNull(selector: (Double) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16521,6 +16133,8 @@ public inline fun DoubleArray.minOfOrNull(selector: (Double) -> Double): Double? /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16529,15 +16143,9 @@ public inline fun DoubleArray.minOfOrNull(selector: (Double) -> Double): Double? public inline fun BooleanArray.minOfOrNull(selector: (Boolean) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16545,6 +16153,8 @@ public inline fun BooleanArray.minOfOrNull(selector: (Boolean) -> Double): Doubl /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16553,15 +16163,9 @@ public inline fun BooleanArray.minOfOrNull(selector: (Boolean) -> Double): Doubl public inline fun CharArray.minOfOrNull(selector: (Char) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16569,6 +16173,8 @@ public inline fun CharArray.minOfOrNull(selector: (Char) -> Double): Double? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16577,15 +16183,9 @@ public inline fun CharArray.minOfOrNull(selector: (Char) -> Double): Double? { public inline fun Array.minOfOrNull(selector: (T) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16593,6 +16193,8 @@ public inline fun Array.minOfOrNull(selector: (T) -> Float): Float? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16601,15 +16203,9 @@ public inline fun Array.minOfOrNull(selector: (T) -> Float): Float? { public inline fun ByteArray.minOfOrNull(selector: (Byte) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16617,6 +16213,8 @@ public inline fun ByteArray.minOfOrNull(selector: (Byte) -> Float): Float? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16625,15 +16223,9 @@ public inline fun ByteArray.minOfOrNull(selector: (Byte) -> Float): Float? { public inline fun ShortArray.minOfOrNull(selector: (Short) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16641,6 +16233,8 @@ public inline fun ShortArray.minOfOrNull(selector: (Short) -> Float): Float? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16649,15 +16243,9 @@ public inline fun ShortArray.minOfOrNull(selector: (Short) -> Float): Float? { public inline fun IntArray.minOfOrNull(selector: (Int) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16665,6 +16253,8 @@ public inline fun IntArray.minOfOrNull(selector: (Int) -> Float): Float? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16673,15 +16263,9 @@ public inline fun IntArray.minOfOrNull(selector: (Int) -> Float): Float? { public inline fun LongArray.minOfOrNull(selector: (Long) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16689,6 +16273,8 @@ public inline fun LongArray.minOfOrNull(selector: (Long) -> Float): Float? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16697,15 +16283,9 @@ public inline fun LongArray.minOfOrNull(selector: (Long) -> Float): Float? { public inline fun FloatArray.minOfOrNull(selector: (Float) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16713,6 +16293,8 @@ public inline fun FloatArray.minOfOrNull(selector: (Float) -> Float): Float? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16721,15 +16303,9 @@ public inline fun FloatArray.minOfOrNull(selector: (Float) -> Float): Float? { public inline fun DoubleArray.minOfOrNull(selector: (Double) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16737,6 +16313,8 @@ public inline fun DoubleArray.minOfOrNull(selector: (Double) -> Float): Float? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16745,15 +16323,9 @@ public inline fun DoubleArray.minOfOrNull(selector: (Double) -> Float): Float? { public inline fun BooleanArray.minOfOrNull(selector: (Boolean) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16761,6 +16333,8 @@ public inline fun BooleanArray.minOfOrNull(selector: (Boolean) -> Float): Float? /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -16769,15 +16343,9 @@ public inline fun BooleanArray.minOfOrNull(selector: (Boolean) -> Float): Float? public inline fun CharArray.minOfOrNull(selector: (Char) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -16793,12 +16361,8 @@ public inline fun CharArray.minOfOrNull(selector: (Char) -> Float): Float? { public inline fun > Array.minOfOrNull(selector: (T) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16817,12 +16381,8 @@ public inline fun > Array.minOfOrNull(selector: (T) public inline fun > ByteArray.minOfOrNull(selector: (Byte) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16841,12 +16401,8 @@ public inline fun > ByteArray.minOfOrNull(selector: (Byte) -> public inline fun > ShortArray.minOfOrNull(selector: (Short) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16865,12 +16421,8 @@ public inline fun > ShortArray.minOfOrNull(selector: (Short) - public inline fun > IntArray.minOfOrNull(selector: (Int) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16889,12 +16441,8 @@ public inline fun > IntArray.minOfOrNull(selector: (Int) -> R) public inline fun > LongArray.minOfOrNull(selector: (Long) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16913,12 +16461,8 @@ public inline fun > LongArray.minOfOrNull(selector: (Long) -> public inline fun > FloatArray.minOfOrNull(selector: (Float) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16937,12 +16481,8 @@ public inline fun > FloatArray.minOfOrNull(selector: (Float) - public inline fun > DoubleArray.minOfOrNull(selector: (Double) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16961,12 +16501,8 @@ public inline fun > DoubleArray.minOfOrNull(selector: (Double) public inline fun > BooleanArray.minOfOrNull(selector: (Boolean) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -16985,12 +16521,8 @@ public inline fun > BooleanArray.minOfOrNull(selector: (Boolea public inline fun > CharArray.minOfOrNull(selector: (Char) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -17011,8 +16543,6 @@ public inline fun > CharArray.minOfOrNull(selector: (Char) -> public inline fun Array.minOfWith(comparator: Comparator, selector: (T) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17035,8 +16565,6 @@ public inline fun Array.minOfWith(comparator: Comparator, se public inline fun ByteArray.minOfWith(comparator: Comparator, selector: (Byte) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17059,8 +16587,6 @@ public inline fun ByteArray.minOfWith(comparator: Comparator, selector public inline fun ShortArray.minOfWith(comparator: Comparator, selector: (Short) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17083,8 +16609,6 @@ public inline fun ShortArray.minOfWith(comparator: Comparator, selecto public inline fun IntArray.minOfWith(comparator: Comparator, selector: (Int) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17107,8 +16631,6 @@ public inline fun IntArray.minOfWith(comparator: Comparator, selector: public inline fun LongArray.minOfWith(comparator: Comparator, selector: (Long) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17131,8 +16653,6 @@ public inline fun LongArray.minOfWith(comparator: Comparator, selector public inline fun FloatArray.minOfWith(comparator: Comparator, selector: (Float) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17155,8 +16675,6 @@ public inline fun FloatArray.minOfWith(comparator: Comparator, selecto public inline fun DoubleArray.minOfWith(comparator: Comparator, selector: (Double) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17179,8 +16697,6 @@ public inline fun DoubleArray.minOfWith(comparator: Comparator, select public inline fun BooleanArray.minOfWith(comparator: Comparator, selector: (Boolean) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17203,8 +16719,6 @@ public inline fun BooleanArray.minOfWith(comparator: Comparator, selec public inline fun CharArray.minOfWith(comparator: Comparator, selector: (Char) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17225,8 +16739,6 @@ public inline fun CharArray.minOfWith(comparator: Comparator, selector public inline fun Array.minOfWithOrNull(comparator: Comparator, selector: (T) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17247,8 +16759,6 @@ public inline fun Array.minOfWithOrNull(comparator: Comparator ByteArray.minOfWithOrNull(comparator: Comparator, selector: (Byte) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17269,8 +16779,6 @@ public inline fun ByteArray.minOfWithOrNull(comparator: Comparator, se public inline fun ShortArray.minOfWithOrNull(comparator: Comparator, selector: (Short) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17291,8 +16799,6 @@ public inline fun ShortArray.minOfWithOrNull(comparator: Comparator, s public inline fun IntArray.minOfWithOrNull(comparator: Comparator, selector: (Int) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17313,8 +16819,6 @@ public inline fun IntArray.minOfWithOrNull(comparator: Comparator, sel public inline fun LongArray.minOfWithOrNull(comparator: Comparator, selector: (Long) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17335,8 +16839,6 @@ public inline fun LongArray.minOfWithOrNull(comparator: Comparator, se public inline fun FloatArray.minOfWithOrNull(comparator: Comparator, selector: (Float) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17357,8 +16859,6 @@ public inline fun FloatArray.minOfWithOrNull(comparator: Comparator, s public inline fun DoubleArray.minOfWithOrNull(comparator: Comparator, selector: (Double) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17379,8 +16879,6 @@ public inline fun DoubleArray.minOfWithOrNull(comparator: Comparator, public inline fun BooleanArray.minOfWithOrNull(comparator: Comparator, selector: (Boolean) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -17401,8 +16899,6 @@ public inline fun BooleanArray.minOfWithOrNull(comparator: Comparator, public inline fun CharArray.minOfWithOrNull(comparator: Comparator, selector: (Char) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { diff --git a/libraries/stdlib/common/src/generated/_Collections.kt b/libraries/stdlib/common/src/generated/_Collections.kt index d13590e1520..15c4af755ae 100644 --- a/libraries/stdlib/common/src/generated/_Collections.kt +++ b/libraries/stdlib/common/src/generated/_Collections.kt @@ -1797,6 +1797,8 @@ public inline fun > Iterable.maxBy(selector: (T) -> R): * Returns the largest value among all values produced by [selector] function * applied to each element in the collection. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the collection is empty. */ @SinceKotlin("1.4") @@ -1807,13 +1809,9 @@ public inline fun Iterable.maxOf(selector: (T) -> Double): Double { val iterator = iterator() if (!iterator.hasNext()) throw NoSuchElementException() var maxValue = selector(iterator.next()) - if (maxValue.isNaN()) return maxValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -1822,6 +1820,8 @@ public inline fun Iterable.maxOf(selector: (T) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the collection. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the collection is empty. */ @SinceKotlin("1.4") @@ -1832,13 +1832,9 @@ public inline fun Iterable.maxOf(selector: (T) -> Float): Float { val iterator = iterator() if (!iterator.hasNext()) throw NoSuchElementException() var maxValue = selector(iterator.next()) - if (maxValue.isNaN()) return maxValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -1859,7 +1855,6 @@ public inline fun > Iterable.maxOf(selector: (T) -> R): var maxValue = selector(iterator.next()) while (iterator.hasNext()) { val v = selector(iterator.next()) - if (maxValue < v) { maxValue = v } @@ -1870,6 +1865,8 @@ public inline fun > Iterable.maxOf(selector: (T) -> R): /** * Returns the largest value among all values produced by [selector] function * applied to each element in the collection or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -1879,13 +1876,9 @@ public inline fun Iterable.maxOfOrNull(selector: (T) -> Double): Double? val iterator = iterator() if (!iterator.hasNext()) return null var maxValue = selector(iterator.next()) - if (maxValue.isNaN()) return maxValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -1893,6 +1886,8 @@ public inline fun Iterable.maxOfOrNull(selector: (T) -> Double): Double? /** * Returns the largest value among all values produced by [selector] function * applied to each element in the collection or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -1902,13 +1897,9 @@ public inline fun Iterable.maxOfOrNull(selector: (T) -> Float): Float? { val iterator = iterator() if (!iterator.hasNext()) return null var maxValue = selector(iterator.next()) - if (maxValue.isNaN()) return maxValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -1927,7 +1918,6 @@ public inline fun > Iterable.maxOfOrNull(selector: (T) - var maxValue = selector(iterator.next()) while (iterator.hasNext()) { val v = selector(iterator.next()) - if (maxValue < v) { maxValue = v } @@ -2071,6 +2061,8 @@ public inline fun > Iterable.minBy(selector: (T) -> R): * Returns the smallest value among all values produced by [selector] function * applied to each element in the collection. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the collection is empty. */ @SinceKotlin("1.4") @@ -2081,13 +2073,9 @@ public inline fun Iterable.minOf(selector: (T) -> Double): Double { val iterator = iterator() if (!iterator.hasNext()) throw NoSuchElementException() var minValue = selector(iterator.next()) - if (minValue.isNaN()) return minValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -2096,6 +2084,8 @@ public inline fun Iterable.minOf(selector: (T) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the collection. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the collection is empty. */ @SinceKotlin("1.4") @@ -2106,13 +2096,9 @@ public inline fun Iterable.minOf(selector: (T) -> Float): Float { val iterator = iterator() if (!iterator.hasNext()) throw NoSuchElementException() var minValue = selector(iterator.next()) - if (minValue.isNaN()) return minValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -2133,7 +2119,6 @@ public inline fun > Iterable.minOf(selector: (T) -> R): var minValue = selector(iterator.next()) while (iterator.hasNext()) { val v = selector(iterator.next()) - if (minValue > v) { minValue = v } @@ -2144,6 +2129,8 @@ public inline fun > Iterable.minOf(selector: (T) -> R): /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the collection or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -2153,13 +2140,9 @@ public inline fun Iterable.minOfOrNull(selector: (T) -> Double): Double? val iterator = iterator() if (!iterator.hasNext()) return null var minValue = selector(iterator.next()) - if (minValue.isNaN()) return minValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -2167,6 +2150,8 @@ public inline fun Iterable.minOfOrNull(selector: (T) -> Double): Double? /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the collection or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -2176,13 +2161,9 @@ public inline fun Iterable.minOfOrNull(selector: (T) -> Float): Float? { val iterator = iterator() if (!iterator.hasNext()) return null var minValue = selector(iterator.next()) - if (minValue.isNaN()) return minValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -2201,7 +2182,6 @@ public inline fun > Iterable.minOfOrNull(selector: (T) - var minValue = selector(iterator.next()) while (iterator.hasNext()) { val v = selector(iterator.next()) - if (minValue > v) { minValue = v } diff --git a/libraries/stdlib/common/src/generated/_Maps.kt b/libraries/stdlib/common/src/generated/_Maps.kt index dcbd2cd9980..2a24dd68927 100644 --- a/libraries/stdlib/common/src/generated/_Maps.kt +++ b/libraries/stdlib/common/src/generated/_Maps.kt @@ -193,6 +193,8 @@ public inline fun > Map.maxBy(selector: (Map.E * Returns the largest value among all values produced by [selector] function * applied to each entry in the map. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the map is empty. */ @SinceKotlin("1.4") @@ -207,6 +209,8 @@ public inline fun Map.maxOf(selector: (Map.Entry) -> Doub * Returns the largest value among all values produced by [selector] function * applied to each entry in the map. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the map is empty. */ @SinceKotlin("1.4") @@ -234,6 +238,8 @@ public inline fun > Map.maxOf(selector: (Map.E /** * Returns the largest value among all values produced by [selector] function * applied to each entry in the map or `null` if there are no entries. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -246,6 +252,8 @@ public inline fun Map.maxOfOrNull(selector: (Map.Entry) - /** * Returns the largest value among all values produced by [selector] function * applied to each entry in the map or `null` if there are no entries. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -314,6 +322,8 @@ public inline fun > Map.minBy(selector: (Map.E * Returns the smallest value among all values produced by [selector] function * applied to each entry in the map. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the map is empty. */ @SinceKotlin("1.4") @@ -328,6 +338,8 @@ public inline fun Map.minOf(selector: (Map.Entry) -> Doub * Returns the smallest value among all values produced by [selector] function * applied to each entry in the map. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the map is empty. */ @SinceKotlin("1.4") @@ -355,6 +367,8 @@ public inline fun > Map.minOf(selector: (Map.E /** * Returns the smallest value among all values produced by [selector] function * applied to each entry in the map or `null` if there are no entries. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -367,6 +381,8 @@ public inline fun Map.minOfOrNull(selector: (Map.Entry) - /** * Returns the smallest value among all values produced by [selector] function * applied to each entry in the map or `null` if there are no entries. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) diff --git a/libraries/stdlib/common/src/generated/_Sequences.kt b/libraries/stdlib/common/src/generated/_Sequences.kt index 78c6aac0c4e..297bde74066 100644 --- a/libraries/stdlib/common/src/generated/_Sequences.kt +++ b/libraries/stdlib/common/src/generated/_Sequences.kt @@ -1252,6 +1252,8 @@ public inline fun > Sequence.maxBy(selector: (T) -> R): * Returns the largest value among all values produced by [selector] function * applied to each element in the sequence. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the sequence is empty. * * The operation is _terminal_. @@ -1264,13 +1266,9 @@ public inline fun Sequence.maxOf(selector: (T) -> Double): Double { val iterator = iterator() if (!iterator.hasNext()) throw NoSuchElementException() var maxValue = selector(iterator.next()) - if (maxValue.isNaN()) return maxValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -1279,6 +1277,8 @@ public inline fun Sequence.maxOf(selector: (T) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the sequence. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the sequence is empty. * * The operation is _terminal_. @@ -1291,13 +1291,9 @@ public inline fun Sequence.maxOf(selector: (T) -> Float): Float { val iterator = iterator() if (!iterator.hasNext()) throw NoSuchElementException() var maxValue = selector(iterator.next()) - if (maxValue.isNaN()) return maxValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -1320,7 +1316,6 @@ public inline fun > Sequence.maxOf(selector: (T) -> R): var maxValue = selector(iterator.next()) while (iterator.hasNext()) { val v = selector(iterator.next()) - if (maxValue < v) { maxValue = v } @@ -1331,6 +1326,8 @@ public inline fun > Sequence.maxOf(selector: (T) -> R): /** * Returns the largest value among all values produced by [selector] function * applied to each element in the sequence or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. * * The operation is _terminal_. */ @@ -1342,13 +1339,9 @@ public inline fun Sequence.maxOfOrNull(selector: (T) -> Double): Double? val iterator = iterator() if (!iterator.hasNext()) return null var maxValue = selector(iterator.next()) - if (maxValue.isNaN()) return maxValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -1356,6 +1349,8 @@ public inline fun Sequence.maxOfOrNull(selector: (T) -> Double): Double? /** * Returns the largest value among all values produced by [selector] function * applied to each element in the sequence or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. * * The operation is _terminal_. */ @@ -1367,13 +1362,9 @@ public inline fun Sequence.maxOfOrNull(selector: (T) -> Float): Float? { val iterator = iterator() if (!iterator.hasNext()) return null var maxValue = selector(iterator.next()) - if (maxValue.isNaN()) return maxValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -1394,7 +1385,6 @@ public inline fun > Sequence.maxOfOrNull(selector: (T) - var maxValue = selector(iterator.next()) while (iterator.hasNext()) { val v = selector(iterator.next()) - if (maxValue < v) { maxValue = v } @@ -1552,6 +1542,8 @@ public inline fun > Sequence.minBy(selector: (T) -> R): * Returns the smallest value among all values produced by [selector] function * applied to each element in the sequence. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the sequence is empty. * * The operation is _terminal_. @@ -1564,13 +1556,9 @@ public inline fun Sequence.minOf(selector: (T) -> Double): Double { val iterator = iterator() if (!iterator.hasNext()) throw NoSuchElementException() var minValue = selector(iterator.next()) - if (minValue.isNaN()) return minValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -1579,6 +1567,8 @@ public inline fun Sequence.minOf(selector: (T) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the sequence. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the sequence is empty. * * The operation is _terminal_. @@ -1591,13 +1581,9 @@ public inline fun Sequence.minOf(selector: (T) -> Float): Float { val iterator = iterator() if (!iterator.hasNext()) throw NoSuchElementException() var minValue = selector(iterator.next()) - if (minValue.isNaN()) return minValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -1620,7 +1606,6 @@ public inline fun > Sequence.minOf(selector: (T) -> R): var minValue = selector(iterator.next()) while (iterator.hasNext()) { val v = selector(iterator.next()) - if (minValue > v) { minValue = v } @@ -1631,6 +1616,8 @@ public inline fun > Sequence.minOf(selector: (T) -> R): /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the sequence or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. * * The operation is _terminal_. */ @@ -1642,13 +1629,9 @@ public inline fun Sequence.minOfOrNull(selector: (T) -> Double): Double? val iterator = iterator() if (!iterator.hasNext()) return null var minValue = selector(iterator.next()) - if (minValue.isNaN()) return minValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -1656,6 +1639,8 @@ public inline fun Sequence.minOfOrNull(selector: (T) -> Double): Double? /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the sequence or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. * * The operation is _terminal_. */ @@ -1667,13 +1652,9 @@ public inline fun Sequence.minOfOrNull(selector: (T) -> Float): Float? { val iterator = iterator() if (!iterator.hasNext()) return null var minValue = selector(iterator.next()) - if (minValue.isNaN()) return minValue while (iterator.hasNext()) { val v = selector(iterator.next()) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -1694,7 +1675,6 @@ public inline fun > Sequence.minOfOrNull(selector: (T) - var minValue = selector(iterator.next()) while (iterator.hasNext()) { val v = selector(iterator.next()) - if (minValue > v) { minValue = v } diff --git a/libraries/stdlib/common/src/generated/_Strings.kt b/libraries/stdlib/common/src/generated/_Strings.kt index 8dff8ea6449..7b32f41aa62 100644 --- a/libraries/stdlib/common/src/generated/_Strings.kt +++ b/libraries/stdlib/common/src/generated/_Strings.kt @@ -1127,6 +1127,8 @@ public inline fun > CharSequence.maxBy(selector: (Char) -> R): * Returns the largest value among all values produced by [selector] function * applied to each character in the char sequence. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the char sequence is empty. */ @SinceKotlin("1.4") @@ -1136,15 +1138,9 @@ public inline fun > CharSequence.maxBy(selector: (Char) -> R): public inline fun CharSequence.maxOf(selector: (Char) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -1153,6 +1149,8 @@ public inline fun CharSequence.maxOf(selector: (Char) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each character in the char sequence. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the char sequence is empty. */ @SinceKotlin("1.4") @@ -1162,15 +1160,9 @@ public inline fun CharSequence.maxOf(selector: (Char) -> Double): Double { public inline fun CharSequence.maxOf(selector: (Char) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -1188,12 +1180,8 @@ public inline fun CharSequence.maxOf(selector: (Char) -> Float): Float { public inline fun > CharSequence.maxOf(selector: (Char) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -1204,6 +1192,8 @@ public inline fun > CharSequence.maxOf(selector: (Char) -> R): /** * Returns the largest value among all values produced by [selector] function * applied to each character in the char sequence or `null` if there are no characters. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -1212,15 +1202,9 @@ public inline fun > CharSequence.maxOf(selector: (Char) -> R): public inline fun CharSequence.maxOfOrNull(selector: (Char) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -1228,6 +1212,8 @@ public inline fun CharSequence.maxOfOrNull(selector: (Char) -> Double): Double? /** * Returns the largest value among all values produced by [selector] function * applied to each character in the char sequence or `null` if there are no characters. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -1236,15 +1222,9 @@ public inline fun CharSequence.maxOfOrNull(selector: (Char) -> Double): Double? public inline fun CharSequence.maxOfOrNull(selector: (Char) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -1260,12 +1240,8 @@ public inline fun CharSequence.maxOfOrNull(selector: (Char) -> Float): Float? { public inline fun > CharSequence.maxOfOrNull(selector: (Char) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -1286,8 +1262,6 @@ public inline fun > CharSequence.maxOfOrNull(selector: (Char) public inline fun CharSequence.maxOfWith(comparator: Comparator, selector: (Char) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -1308,8 +1282,6 @@ public inline fun CharSequence.maxOfWith(comparator: Comparator, selec public inline fun CharSequence.maxOfWithOrNull(comparator: Comparator, selector: (Char) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -1371,6 +1343,8 @@ public inline fun > CharSequence.minBy(selector: (Char) -> R): * Returns the smallest value among all values produced by [selector] function * applied to each character in the char sequence. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the char sequence is empty. */ @SinceKotlin("1.4") @@ -1380,15 +1354,9 @@ public inline fun > CharSequence.minBy(selector: (Char) -> R): public inline fun CharSequence.minOf(selector: (Char) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -1397,6 +1365,8 @@ public inline fun CharSequence.minOf(selector: (Char) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each character in the char sequence. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the char sequence is empty. */ @SinceKotlin("1.4") @@ -1406,15 +1376,9 @@ public inline fun CharSequence.minOf(selector: (Char) -> Double): Double { public inline fun CharSequence.minOf(selector: (Char) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -1432,12 +1396,8 @@ public inline fun CharSequence.minOf(selector: (Char) -> Float): Float { public inline fun > CharSequence.minOf(selector: (Char) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -1448,6 +1408,8 @@ public inline fun > CharSequence.minOf(selector: (Char) -> R): /** * Returns the smallest value among all values produced by [selector] function * applied to each character in the char sequence or `null` if there are no characters. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -1456,15 +1418,9 @@ public inline fun > CharSequence.minOf(selector: (Char) -> R): public inline fun CharSequence.minOfOrNull(selector: (Char) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -1472,6 +1428,8 @@ public inline fun CharSequence.minOfOrNull(selector: (Char) -> Double): Double? /** * Returns the smallest value among all values produced by [selector] function * applied to each character in the char sequence or `null` if there are no characters. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -1480,15 +1438,9 @@ public inline fun CharSequence.minOfOrNull(selector: (Char) -> Double): Double? public inline fun CharSequence.minOfOrNull(selector: (Char) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -1504,12 +1456,8 @@ public inline fun CharSequence.minOfOrNull(selector: (Char) -> Float): Float? { public inline fun > CharSequence.minOfOrNull(selector: (Char) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -1530,8 +1478,6 @@ public inline fun > CharSequence.minOfOrNull(selector: (Char) public inline fun CharSequence.minOfWith(comparator: Comparator, selector: (Char) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -1552,8 +1498,6 @@ public inline fun CharSequence.minOfWith(comparator: Comparator, selec public inline fun CharSequence.minOfWithOrNull(comparator: Comparator, selector: (Char) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { diff --git a/libraries/stdlib/common/src/generated/_UArrays.kt b/libraries/stdlib/common/src/generated/_UArrays.kt index ce818572c5a..38cf9a26b53 100644 --- a/libraries/stdlib/common/src/generated/_UArrays.kt +++ b/libraries/stdlib/common/src/generated/_UArrays.kt @@ -5874,6 +5874,8 @@ public inline fun > UShortArray.maxBy(selector: (UShort) -> R) * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -5884,15 +5886,9 @@ public inline fun > UShortArray.maxBy(selector: (UShort) -> R) public inline fun UIntArray.maxOf(selector: (UInt) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -5901,6 +5897,8 @@ public inline fun UIntArray.maxOf(selector: (UInt) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -5911,15 +5909,9 @@ public inline fun UIntArray.maxOf(selector: (UInt) -> Double): Double { public inline fun ULongArray.maxOf(selector: (ULong) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -5928,6 +5920,8 @@ public inline fun ULongArray.maxOf(selector: (ULong) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -5938,15 +5932,9 @@ public inline fun ULongArray.maxOf(selector: (ULong) -> Double): Double { public inline fun UByteArray.maxOf(selector: (UByte) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -5955,6 +5943,8 @@ public inline fun UByteArray.maxOf(selector: (UByte) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -5965,15 +5955,9 @@ public inline fun UByteArray.maxOf(selector: (UByte) -> Double): Double { public inline fun UShortArray.maxOf(selector: (UShort) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -5982,6 +5966,8 @@ public inline fun UShortArray.maxOf(selector: (UShort) -> Double): Double { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -5992,15 +5978,9 @@ public inline fun UShortArray.maxOf(selector: (UShort) -> Double): Double { public inline fun UIntArray.maxOf(selector: (UInt) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -6009,6 +5989,8 @@ public inline fun UIntArray.maxOf(selector: (UInt) -> Float): Float { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -6019,15 +6001,9 @@ public inline fun UIntArray.maxOf(selector: (UInt) -> Float): Float { public inline fun ULongArray.maxOf(selector: (ULong) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -6036,6 +6012,8 @@ public inline fun ULongArray.maxOf(selector: (ULong) -> Float): Float { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -6046,15 +6024,9 @@ public inline fun ULongArray.maxOf(selector: (ULong) -> Float): Float { public inline fun UByteArray.maxOf(selector: (UByte) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -6063,6 +6035,8 @@ public inline fun UByteArray.maxOf(selector: (UByte) -> Float): Float { * Returns the largest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -6073,15 +6047,9 @@ public inline fun UByteArray.maxOf(selector: (UByte) -> Float): Float { public inline fun UShortArray.maxOf(selector: (UShort) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -6100,12 +6068,8 @@ public inline fun UShortArray.maxOf(selector: (UShort) -> Float): Float { public inline fun > UIntArray.maxOf(selector: (UInt) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -6127,12 +6091,8 @@ public inline fun > UIntArray.maxOf(selector: (UInt) -> R): R public inline fun > ULongArray.maxOf(selector: (ULong) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -6154,12 +6114,8 @@ public inline fun > ULongArray.maxOf(selector: (ULong) -> R): public inline fun > UByteArray.maxOf(selector: (UByte) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -6181,12 +6137,8 @@ public inline fun > UByteArray.maxOf(selector: (UByte) -> R): public inline fun > UShortArray.maxOf(selector: (UShort) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -6197,6 +6149,8 @@ public inline fun > UShortArray.maxOf(selector: (UShort) -> R) /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -6206,15 +6160,9 @@ public inline fun > UShortArray.maxOf(selector: (UShort) -> R) public inline fun UIntArray.maxOfOrNull(selector: (UInt) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -6222,6 +6170,8 @@ public inline fun UIntArray.maxOfOrNull(selector: (UInt) -> Double): Double? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -6231,15 +6181,9 @@ public inline fun UIntArray.maxOfOrNull(selector: (UInt) -> Double): Double? { public inline fun ULongArray.maxOfOrNull(selector: (ULong) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -6247,6 +6191,8 @@ public inline fun ULongArray.maxOfOrNull(selector: (ULong) -> Double): Double? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -6256,15 +6202,9 @@ public inline fun ULongArray.maxOfOrNull(selector: (ULong) -> Double): Double? { public inline fun UByteArray.maxOfOrNull(selector: (UByte) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -6272,6 +6212,8 @@ public inline fun UByteArray.maxOfOrNull(selector: (UByte) -> Double): Double? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -6281,15 +6223,9 @@ public inline fun UByteArray.maxOfOrNull(selector: (UByte) -> Double): Double? { public inline fun UShortArray.maxOfOrNull(selector: (UShort) -> Double): Double? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -6297,6 +6233,8 @@ public inline fun UShortArray.maxOfOrNull(selector: (UShort) -> Double): Double? /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -6306,15 +6244,9 @@ public inline fun UShortArray.maxOfOrNull(selector: (UShort) -> Double): Double? public inline fun UIntArray.maxOfOrNull(selector: (UInt) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -6322,6 +6254,8 @@ public inline fun UIntArray.maxOfOrNull(selector: (UInt) -> Float): Float? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -6331,15 +6265,9 @@ public inline fun UIntArray.maxOfOrNull(selector: (UInt) -> Float): Float? { public inline fun ULongArray.maxOfOrNull(selector: (ULong) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -6347,6 +6275,8 @@ public inline fun ULongArray.maxOfOrNull(selector: (ULong) -> Float): Float? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -6356,15 +6286,9 @@ public inline fun ULongArray.maxOfOrNull(selector: (ULong) -> Float): Float? { public inline fun UByteArray.maxOfOrNull(selector: (UByte) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -6372,6 +6296,8 @@ public inline fun UByteArray.maxOfOrNull(selector: (UByte) -> Float): Float? { /** * Returns the largest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -6381,15 +6307,9 @@ public inline fun UByteArray.maxOfOrNull(selector: (UByte) -> Float): Float? { public inline fun UShortArray.maxOfOrNull(selector: (UShort) -> Float): Float? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - if (maxValue.isNaN()) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (maxValue < v) { - maxValue = v - } + maxValue = maxOf(maxValue, v) } return maxValue } @@ -6406,12 +6326,8 @@ public inline fun UShortArray.maxOfOrNull(selector: (UShort) -> Float): Float? { public inline fun > UIntArray.maxOfOrNull(selector: (UInt) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -6431,12 +6347,8 @@ public inline fun > UIntArray.maxOfOrNull(selector: (UInt) -> public inline fun > ULongArray.maxOfOrNull(selector: (ULong) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -6456,12 +6368,8 @@ public inline fun > ULongArray.maxOfOrNull(selector: (ULong) - public inline fun > UByteArray.maxOfOrNull(selector: (UByte) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -6481,12 +6389,8 @@ public inline fun > UByteArray.maxOfOrNull(selector: (UByte) - public inline fun > UShortArray.maxOfOrNull(selector: (UShort) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (maxValue < v) { maxValue = v } @@ -6508,8 +6412,6 @@ public inline fun > UShortArray.maxOfOrNull(selector: (UShort) public inline fun UIntArray.maxOfWith(comparator: Comparator, selector: (UInt) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -6533,8 +6435,6 @@ public inline fun UIntArray.maxOfWith(comparator: Comparator, selector public inline fun ULongArray.maxOfWith(comparator: Comparator, selector: (ULong) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -6558,8 +6458,6 @@ public inline fun ULongArray.maxOfWith(comparator: Comparator, selecto public inline fun UByteArray.maxOfWith(comparator: Comparator, selector: (UByte) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -6583,8 +6481,6 @@ public inline fun UByteArray.maxOfWith(comparator: Comparator, selecto public inline fun UShortArray.maxOfWith(comparator: Comparator, selector: (UShort) -> R): R { if (isEmpty()) throw NoSuchElementException() var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -6606,8 +6502,6 @@ public inline fun UShortArray.maxOfWith(comparator: Comparator, select public inline fun UIntArray.maxOfWithOrNull(comparator: Comparator, selector: (UInt) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -6629,8 +6523,6 @@ public inline fun UIntArray.maxOfWithOrNull(comparator: Comparator, se public inline fun ULongArray.maxOfWithOrNull(comparator: Comparator, selector: (ULong) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -6652,8 +6544,6 @@ public inline fun ULongArray.maxOfWithOrNull(comparator: Comparator, s public inline fun UByteArray.maxOfWithOrNull(comparator: Comparator, selector: (UByte) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -6675,8 +6565,6 @@ public inline fun UByteArray.maxOfWithOrNull(comparator: Comparator, s public inline fun UShortArray.maxOfWithOrNull(comparator: Comparator, selector: (UShort) -> R): R? { if (isEmpty()) return null var maxValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return maxValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(maxValue, v) < 0) { @@ -6910,6 +6798,8 @@ public inline fun > UShortArray.minBy(selector: (UShort) -> R) * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -6920,15 +6810,9 @@ public inline fun > UShortArray.minBy(selector: (UShort) -> R) public inline fun UIntArray.minOf(selector: (UInt) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -6937,6 +6821,8 @@ public inline fun UIntArray.minOf(selector: (UInt) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -6947,15 +6833,9 @@ public inline fun UIntArray.minOf(selector: (UInt) -> Double): Double { public inline fun ULongArray.minOf(selector: (ULong) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -6964,6 +6844,8 @@ public inline fun ULongArray.minOf(selector: (ULong) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -6974,15 +6856,9 @@ public inline fun ULongArray.minOf(selector: (ULong) -> Double): Double { public inline fun UByteArray.minOf(selector: (UByte) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -6991,6 +6867,8 @@ public inline fun UByteArray.minOf(selector: (UByte) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -7001,15 +6879,9 @@ public inline fun UByteArray.minOf(selector: (UByte) -> Double): Double { public inline fun UShortArray.minOf(selector: (UShort) -> Double): Double { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -7018,6 +6890,8 @@ public inline fun UShortArray.minOf(selector: (UShort) -> Double): Double { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -7028,15 +6902,9 @@ public inline fun UShortArray.minOf(selector: (UShort) -> Double): Double { public inline fun UIntArray.minOf(selector: (UInt) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -7045,6 +6913,8 @@ public inline fun UIntArray.minOf(selector: (UInt) -> Float): Float { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -7055,15 +6925,9 @@ public inline fun UIntArray.minOf(selector: (UInt) -> Float): Float { public inline fun ULongArray.minOf(selector: (ULong) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -7072,6 +6936,8 @@ public inline fun ULongArray.minOf(selector: (ULong) -> Float): Float { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -7082,15 +6948,9 @@ public inline fun ULongArray.minOf(selector: (ULong) -> Float): Float { public inline fun UByteArray.minOf(selector: (UByte) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -7099,6 +6959,8 @@ public inline fun UByteArray.minOf(selector: (UByte) -> Float): Float { * Returns the smallest value among all values produced by [selector] function * applied to each element in the array. * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + * * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.4") @@ -7109,15 +6971,9 @@ public inline fun UByteArray.minOf(selector: (UByte) -> Float): Float { public inline fun UShortArray.minOf(selector: (UShort) -> Float): Float { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -7136,12 +6992,8 @@ public inline fun UShortArray.minOf(selector: (UShort) -> Float): Float { public inline fun > UIntArray.minOf(selector: (UInt) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -7163,12 +7015,8 @@ public inline fun > UIntArray.minOf(selector: (UInt) -> R): R public inline fun > ULongArray.minOf(selector: (ULong) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -7190,12 +7038,8 @@ public inline fun > ULongArray.minOf(selector: (ULong) -> R): public inline fun > UByteArray.minOf(selector: (UByte) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -7217,12 +7061,8 @@ public inline fun > UByteArray.minOf(selector: (UByte) -> R): public inline fun > UShortArray.minOf(selector: (UShort) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -7233,6 +7073,8 @@ public inline fun > UShortArray.minOf(selector: (UShort) -> R) /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -7242,15 +7084,9 @@ public inline fun > UShortArray.minOf(selector: (UShort) -> R) public inline fun UIntArray.minOfOrNull(selector: (UInt) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -7258,6 +7094,8 @@ public inline fun UIntArray.minOfOrNull(selector: (UInt) -> Double): Double? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -7267,15 +7105,9 @@ public inline fun UIntArray.minOfOrNull(selector: (UInt) -> Double): Double? { public inline fun ULongArray.minOfOrNull(selector: (ULong) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -7283,6 +7115,8 @@ public inline fun ULongArray.minOfOrNull(selector: (ULong) -> Double): Double? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -7292,15 +7126,9 @@ public inline fun ULongArray.minOfOrNull(selector: (ULong) -> Double): Double? { public inline fun UByteArray.minOfOrNull(selector: (UByte) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -7308,6 +7136,8 @@ public inline fun UByteArray.minOfOrNull(selector: (UByte) -> Double): Double? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -7317,15 +7147,9 @@ public inline fun UByteArray.minOfOrNull(selector: (UByte) -> Double): Double? { public inline fun UShortArray.minOfOrNull(selector: (UShort) -> Double): Double? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -7333,6 +7157,8 @@ public inline fun UShortArray.minOfOrNull(selector: (UShort) -> Double): Double? /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -7342,15 +7168,9 @@ public inline fun UShortArray.minOfOrNull(selector: (UShort) -> Double): Double? public inline fun UIntArray.minOfOrNull(selector: (UInt) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -7358,6 +7178,8 @@ public inline fun UIntArray.minOfOrNull(selector: (UInt) -> Float): Float? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -7367,15 +7189,9 @@ public inline fun UIntArray.minOfOrNull(selector: (UInt) -> Float): Float? { public inline fun ULongArray.minOfOrNull(selector: (ULong) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -7383,6 +7199,8 @@ public inline fun ULongArray.minOfOrNull(selector: (ULong) -> Float): Float? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -7392,15 +7210,9 @@ public inline fun ULongArray.minOfOrNull(selector: (ULong) -> Float): Float? { public inline fun UByteArray.minOfOrNull(selector: (UByte) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -7408,6 +7220,8 @@ public inline fun UByteArray.minOfOrNull(selector: (UByte) -> Float): Float? { /** * Returns the smallest value among all values produced by [selector] function * applied to each element in the array or `null` if there are no elements. + * + * If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. */ @SinceKotlin("1.4") @OptIn(kotlin.experimental.ExperimentalTypeInference::class) @@ -7417,15 +7231,9 @@ public inline fun UByteArray.minOfOrNull(selector: (UByte) -> Float): Float? { public inline fun UShortArray.minOfOrNull(selector: (UShort) -> Float): Float? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - if (minValue.isNaN()) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) - if (v.isNaN()) return v - if (minValue > v) { - minValue = v - } + minValue = minOf(minValue, v) } return minValue } @@ -7442,12 +7250,8 @@ public inline fun UShortArray.minOfOrNull(selector: (UShort) -> Float): Float? { public inline fun > UIntArray.minOfOrNull(selector: (UInt) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -7467,12 +7271,8 @@ public inline fun > UIntArray.minOfOrNull(selector: (UInt) -> public inline fun > ULongArray.minOfOrNull(selector: (ULong) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -7492,12 +7292,8 @@ public inline fun > ULongArray.minOfOrNull(selector: (ULong) - public inline fun > UByteArray.minOfOrNull(selector: (UByte) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -7517,12 +7313,8 @@ public inline fun > UByteArray.minOfOrNull(selector: (UByte) - public inline fun > UShortArray.minOfOrNull(selector: (UShort) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue - for (i in 1..lastIndex) { val v = selector(this[i]) - if (minValue > v) { minValue = v } @@ -7544,8 +7336,6 @@ public inline fun > UShortArray.minOfOrNull(selector: (UShort) public inline fun UIntArray.minOfWith(comparator: Comparator, selector: (UInt) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -7569,8 +7359,6 @@ public inline fun UIntArray.minOfWith(comparator: Comparator, selector public inline fun ULongArray.minOfWith(comparator: Comparator, selector: (ULong) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -7594,8 +7382,6 @@ public inline fun ULongArray.minOfWith(comparator: Comparator, selecto public inline fun UByteArray.minOfWith(comparator: Comparator, selector: (UByte) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -7619,8 +7405,6 @@ public inline fun UByteArray.minOfWith(comparator: Comparator, selecto public inline fun UShortArray.minOfWith(comparator: Comparator, selector: (UShort) -> R): R { if (isEmpty()) throw NoSuchElementException() var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -7642,8 +7426,6 @@ public inline fun UShortArray.minOfWith(comparator: Comparator, select public inline fun UIntArray.minOfWithOrNull(comparator: Comparator, selector: (UInt) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -7665,8 +7447,6 @@ public inline fun UIntArray.minOfWithOrNull(comparator: Comparator, se public inline fun ULongArray.minOfWithOrNull(comparator: Comparator, selector: (ULong) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -7688,8 +7468,6 @@ public inline fun ULongArray.minOfWithOrNull(comparator: Comparator, s public inline fun UByteArray.minOfWithOrNull(comparator: Comparator, selector: (UByte) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { @@ -7711,8 +7489,6 @@ public inline fun UByteArray.minOfWithOrNull(comparator: Comparator, s public inline fun UShortArray.minOfWithOrNull(comparator: Comparator, selector: (UShort) -> R): R? { if (isEmpty()) return null var minValue = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return minValue for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare(minValue, v) > 0) { diff --git a/libraries/stdlib/test/collections/CollectionTest.kt b/libraries/stdlib/test/collections/CollectionTest.kt index 4a7f99686b0..dfb6d08e8a1 100644 --- a/libraries/stdlib/test/collections/CollectionTest.kt +++ b/libraries/stdlib/test/collections/CollectionTest.kt @@ -5,6 +5,8 @@ package test.collections +import test.assertIsNegativeZero +import test.assertIsPositiveZero import test.assertStaticAndRuntimeTypeIs import kotlin.test.* import test.collections.behaviors.* @@ -909,6 +911,9 @@ class CollectionTest { assertEquals(Double.NaN, listOf(1, -1, 0).minOf { it.toDouble().pow(0.5) }) assertEquals(Float.NaN, listOf(1, -1, 0).minOf { it.toFloat().pow(0.5F) }) + + assertIsNegativeZero(listOf(1.0, -1.0).shuffled().minOf { it * 0.0 }) + assertIsNegativeZero(listOf(1.0F, -1.0F).shuffled().minOf { it * 0.0F }.toDouble()) } @Test fun minOfWith() { @@ -934,6 +939,9 @@ class CollectionTest { assertEquals(16.0, listOf(1, 2, 3, 4, 5).maxOf { (-2.0).pow(it) }) assertEquals(16.0F, listOf(1, 2, 3, 4, 5).maxOf { (-2.0F).pow(it) }) + + assertIsPositiveZero(listOf(1.0, -1.0).shuffled().maxOf { it * 0.0 }) + assertIsPositiveZero(listOf(1.0F, -1.0F).shuffled().maxOf { it * 0.0F }.toDouble()) } @Test fun maxOfWith() { @@ -946,9 +954,6 @@ class CollectionTest { assertEquals(null, emptyList().maxOfWithOrNull(naturalOrder()) { it }) // TODO: investigate why no unit-coercion happens here and an explicit 'Unit' is required assertFailsWith { emptyList().maxOfWith(naturalOrder()) { it }; Unit } - - assertEquals(Double.NaN, listOf(1, -1, 0).maxOf { it.toDouble().pow(0.5) }) - assertEquals(Float.NaN, listOf(1, -1, 0).maxOf { it.toFloat().pow(0.5F) }) } diff --git a/libraries/stdlib/test/numbers/NaNPropagationTest.kt b/libraries/stdlib/test/numbers/NaNPropagationTest.kt index 29a1907996b..b3fbb898d4f 100644 --- a/libraries/stdlib/test/numbers/NaNPropagationTest.kt +++ b/libraries/stdlib/test/numbers/NaNPropagationTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -100,6 +100,24 @@ class NaNPropagationTest { ) } + @Test + fun arrayMinOf() { + propagateOf3( + { a, b, c -> arrayOf(a, b, c).minOf { it } }, + { a, b, c -> arrayOf(a, b, c).minOf { it } }, + "arrayOf().minOf()" + ) + } + + @Test + fun arrayMaxOf() { + propagateOf3( + { a, b, c -> arrayOf(a, b, c).maxOf { it } }, + { a, b, c -> arrayOf(a, b, c).maxOf { it } }, + "arrayOf().maxOf()" + ) + } + @Test fun primitiveArrayMin() { propagateOf2( @@ -118,6 +136,34 @@ class NaNPropagationTest { ) } + @Test + fun primitiveArrayMinOf() { + propagateOf3( + { a, b, c -> doubleArrayOf(a, b, c).minOf { it } }, + { a, b, c -> floatArrayOf(a, b, c).minOf { it } }, + "primitiveArrayOf().minOf()" + ) + propagateOf3( + { a, b, c -> val arr = doubleArrayOf(a, b, c); intArrayOf(0, 1, 2).minOf { arr[it] } }, + { a, b, c -> val arr = floatArrayOf(a, b, c); intArrayOf(0, 1, 2).minOf { arr[it] } }, + "intArrayOf().minOf()" + ) + } + + @Test + fun primitiveArrayMaxOf() { + propagateOf3( + { a, b, c -> doubleArrayOf(a, b, c).maxOf { it } }, + { a, b, c -> floatArrayOf(a, b, c).maxOf { it } }, + "primitiveArrayOf().maxOf()" + ) + propagateOf3( + { a, b, c -> val arr = doubleArrayOf(a, b, c); intArrayOf(0, 1, 2).maxOf { arr[it] } }, + { a, b, c -> val arr = floatArrayOf(a, b, c); intArrayOf(0, 1, 2).maxOf { arr[it] } }, + "intArrayOf().maxOf()" + ) + } + @Test fun listMin() { propagateOf2( @@ -136,6 +182,24 @@ class NaNPropagationTest { ) } + @Test + fun listMinOf() { + propagateOf3( + { a, b, c -> listOf(a, b, c).minOf { it } }, + { a, b, c -> listOf(a, b, c).minOf { it } }, + "listOf().minOf()" + ) + } + + @Test + fun listMaxOf() { + propagateOf3( + { a, b, c -> listOf(a, b, c).maxOf { it } }, + { a, b, c -> listOf(a, b, c).maxOf { it } }, + "listOf().maxOf()" + ) + } + @Test fun sequenceMin() { propagateOf2( @@ -154,6 +218,23 @@ class NaNPropagationTest { ) } + @Test + fun sequenceMinOf() { + propagateOf3( + { a, b, c -> sequenceOf(a, b, c).minOf { it } }, + { a, b, c -> sequenceOf(a, b, c).minOf { it } }, + "sequenceOf().minOf()" + ) + } + + @Test + fun sequenceMaxOf() { + propagateOf3( + { a, b, c -> sequenceOf(a, b, c).maxOf { it } }, + { a, b, c -> sequenceOf(a, b, c).maxOf { it } }, + "sequenceOf().maxOf()" + ) + } } class NaNTotalOrderTest { diff --git a/libraries/stdlib/test/testUtils.kt b/libraries/stdlib/test/testUtils.kt index 6c08207aab5..8b16cf2af8b 100644 --- a/libraries/stdlib/test/testUtils.kt +++ b/libraries/stdlib/test/testUtils.kt @@ -1,10 +1,12 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package test +import kotlin.math.withSign +import kotlin.test.assertEquals import kotlin.test.assertTrue import kotlin.test.fail @@ -27,4 +29,13 @@ fun assertArrayContentEquals(expected: CharArray, actual: CharArray, message: St fun assertArrayContentEquals(expected: UIntArray, actual: UIntArray, message: String? = null) = assertTrue(expected contentEquals actual, message) fun assertArrayContentEquals(expected: ULongArray, actual: ULongArray, message: String? = null) = assertTrue(expected contentEquals actual, message) fun assertArrayContentEquals(expected: UShortArray, actual: UShortArray, message: String? = null) = assertTrue(expected contentEquals actual, message) -fun assertArrayContentEquals(expected: UByteArray, actual: UByteArray, message: String? = null) = assertTrue(expected contentEquals actual, message) \ No newline at end of file +fun assertArrayContentEquals(expected: UByteArray, actual: UByteArray, message: String? = null) = assertTrue(expected contentEquals actual, message) + +fun assertIsNegativeZero(value: Double) { + assertEquals(-0.0, value) + assertEquals(-1.0, 1.0.withSign(value)) +} +fun assertIsPositiveZero(value: Double) { + assertEquals(0.0, value) + assertEquals(1.0, 1.0.withSign(value)) +} \ No newline at end of file diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt index c66ee21adb0..685035462e3 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt @@ -562,9 +562,9 @@ object Aggregates : TemplateGroupBase() { Returns the ${if (op == "max") "largest" else "smallest"} value among all values produced by [selector] function applied to each ${f.element} in the ${f.collection}${" or `null` if there are no ${f.element.pluralize()}".ifOrEmpty(nullable)}. """ + -// """ -// If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. -// """.ifOrEmpty(isFloat) + + """ + If any of values produced by [selector] function is `NaN`, the returned result is `NaN`. + """.ifOrEmpty(isFloat) + """ @throws NoSuchElementException if the ${f.collection} is empty. """.ifOrEmpty(!nullable) @@ -574,19 +574,20 @@ object Aggregates : TemplateGroupBase() { returns(selectorType + "?".ifOrEmpty(nullable)) val doOnEmpty = if (nullable) "return null" else "throw NoSuchElementException()" val acc = op + "Value" - val cmp = if (op == "max") "<" else ">" + val cmpBlock = if (isFloat) + """$acc = ${op}Of($acc, v)""" + else + """if ($acc ${if (op == "max") "<" else ">"} v) { + $acc = v + }""" body { """ val iterator = iterator() if (!iterator.hasNext()) $doOnEmpty var $acc = selector(iterator.next()) - ${"if ($acc.isNaN()) return $acc".ifOrEmpty(isFloat)} while (iterator.hasNext()) { val v = selector(iterator.next()) - ${"if (v.isNaN()) return v".ifOrEmpty(isFloat)} - if ($acc $cmp v) { - $acc = v - } + $cmpBlock } return $acc """ @@ -596,15 +597,9 @@ object Aggregates : TemplateGroupBase() { if (isEmpty()) $doOnEmpty var $acc = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return $acc - ${"if ($acc.isNaN()) return $acc".ifOrEmpty(isFloat)} for (i in 1..lastIndex) { val v = selector(this[i]) - ${"if (v.isNaN()) return v".ifOrEmpty(isFloat)} - if ($acc $cmp v) { - $acc = v - } + $cmpBlock } return $acc """ @@ -668,8 +663,6 @@ object Aggregates : TemplateGroupBase() { if (isEmpty()) $doOnEmpty var $acc = selector(this[0]) - val lastIndex = this.lastIndex - if (lastIndex == 0) return $acc for (i in 1..lastIndex) { val v = selector(this[i]) if (comparator.compare($acc, v) $cmp 0) {