From 7b68de38e1f23efc6d5bd7c14b00030532c48398 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 21 May 2020 00:17:01 +0300 Subject: [PATCH] Introduce minOf/maxOf, minOfWith/maxOfWith and their OrNull variants #KT-38708 Fixed --- .../stdlib/common/src/generated/_Arrays.kt | 3528 +++++++++++++++++ .../common/src/generated/_Collections.kt | 372 ++ .../stdlib/common/src/generated/_Maps.kt | 208 + .../stdlib/common/src/generated/_Sequences.kt | 404 ++ .../stdlib/common/src/generated/_Strings.kt | 392 ++ .../stdlib/common/src/generated/_UArrays.kt | 1632 ++++++++ .../stdlib/test/collections/CollectionTest.kt | 58 + .../src/templates/Aggregates.kt | 146 + .../src/templates/dsl/CommonTypes.kt | 6 +- 9 files changed, 6744 insertions(+), 2 deletions(-) diff --git a/libraries/stdlib/common/src/generated/_Arrays.kt b/libraries/stdlib/common/src/generated/_Arrays.kt index 431e2bca833..061219d1257 100644 --- a/libraries/stdlib/common/src/generated/_Arrays.kt +++ b/libraries/stdlib/common/src/generated/_Arrays.kt @@ -13421,6 +13421,1770 @@ public inline fun > CharArray.maxBy(selector: (Char) -> R): Ch return maxElem } +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun 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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + /** * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements. */ @@ -13884,6 +15648,1770 @@ public inline fun > CharArray.minBy(selector: (Char) -> R): Ch return minElem } +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun 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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + /** * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements. */ diff --git a/libraries/stdlib/common/src/generated/_Collections.kt b/libraries/stdlib/common/src/generated/_Collections.kt index ab85530f626..d13590e1520 100644 --- a/libraries/stdlib/common/src/generated/_Collections.kt +++ b/libraries/stdlib/common/src/generated/_Collections.kt @@ -1793,6 +1793,192 @@ public inline fun > Iterable.maxBy(selector: (T) -> R): return maxElem } +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the collection. + * + * @throws NoSuchElementException if the collection is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the collection. + * + * @throws NoSuchElementException if the collection is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the collection. + * + * @throws NoSuchElementException if the collection is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun > Iterable.maxOf(selector: (T) -> R): R { + val iterator = iterator() + if (!iterator.hasNext()) throw NoSuchElementException() + var maxValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + + if (maxValue < v) { + maxValue = v + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun > Iterable.maxOfOrNull(selector: (T) -> R): R? { + val iterator = iterator() + if (!iterator.hasNext()) return null + var maxValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + + if (maxValue < v) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the collection. + * + * @throws NoSuchElementException if the collection is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Iterable.maxOfWith(comparator: Comparator, selector: (T) -> R): R { + val iterator = iterator() + if (!iterator.hasNext()) throw NoSuchElementException() + var maxValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + if (comparator.compare(maxValue, v) < 0) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the collection or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Iterable.maxOfWithOrNull(comparator: Comparator, selector: (T) -> R): R? { + val iterator = iterator() + if (!iterator.hasNext()) return null + var maxValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + if (comparator.compare(maxValue, v) < 0) { + maxValue = v + } + } + return maxValue +} + /** * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements. */ @@ -1881,6 +2067,192 @@ public inline fun > Iterable.minBy(selector: (T) -> R): return minElem } +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the collection. + * + * @throws NoSuchElementException if the collection is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the collection. + * + * @throws NoSuchElementException if the collection is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the collection. + * + * @throws NoSuchElementException if the collection is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun > Iterable.minOf(selector: (T) -> R): R { + val iterator = iterator() + if (!iterator.hasNext()) throw NoSuchElementException() + var minValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + + if (minValue > v) { + minValue = v + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun > Iterable.minOfOrNull(selector: (T) -> R): R? { + val iterator = iterator() + if (!iterator.hasNext()) return null + var minValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + + if (minValue > v) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the collection. + * + * @throws NoSuchElementException if the collection is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Iterable.minOfWith(comparator: Comparator, selector: (T) -> R): R { + val iterator = iterator() + if (!iterator.hasNext()) throw NoSuchElementException() + var minValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + if (comparator.compare(minValue, v) > 0) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the collection or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Iterable.minOfWithOrNull(comparator: Comparator, selector: (T) -> R): R? { + val iterator = iterator() + if (!iterator.hasNext()) return null + var minValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + if (comparator.compare(minValue, v) > 0) { + minValue = v + } + } + return minValue +} + /** * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements. */ diff --git a/libraries/stdlib/common/src/generated/_Maps.kt b/libraries/stdlib/common/src/generated/_Maps.kt index 62b1e25bb81..dcbd2cd9980 100644 --- a/libraries/stdlib/common/src/generated/_Maps.kt +++ b/libraries/stdlib/common/src/generated/_Maps.kt @@ -189,6 +189,110 @@ public inline fun > Map.maxBy(selector: (Map.E return entries.maxBy(selector) } +/** + * Returns the largest value among all values produced by [selector] function + * applied to each entry in the map. + * + * @throws NoSuchElementException if the map is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Map.maxOf(selector: (Map.Entry) -> Double): Double { + return entries.maxOf(selector) +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each entry in the map. + * + * @throws NoSuchElementException if the map is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Map.maxOf(selector: (Map.Entry) -> Float): Float { + return entries.maxOf(selector) +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each entry in the map. + * + * @throws NoSuchElementException if the map is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun > Map.maxOf(selector: (Map.Entry) -> R): R { + return entries.maxOf(selector) +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Map.maxOfOrNull(selector: (Map.Entry) -> Double): Double? { + return entries.maxOfOrNull(selector) +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Map.maxOfOrNull(selector: (Map.Entry) -> Float): Float? { + return entries.maxOfOrNull(selector) +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun > Map.maxOfOrNull(selector: (Map.Entry) -> R): R? { + return entries.maxOfOrNull(selector) +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each entry in the map. + * + * @throws NoSuchElementException if the map is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Map.maxOfWith(comparator: Comparator, selector: (Map.Entry) -> R): R { + return entries.maxOfWith(comparator, selector) +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each entry in the map or `null` if there are no entries. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Map.maxOfWithOrNull(comparator: Comparator, selector: (Map.Entry) -> R): R? { + return entries.maxOfWithOrNull(comparator, selector) +} + /** * Returns the first entry having the largest value according to the provided [comparator] or `null` if there are no entries. */ @@ -206,6 +310,110 @@ public inline fun > Map.minBy(selector: (Map.E return entries.minBy(selector) } +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each entry in the map. + * + * @throws NoSuchElementException if the map is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Map.minOf(selector: (Map.Entry) -> Double): Double { + return entries.minOf(selector) +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each entry in the map. + * + * @throws NoSuchElementException if the map is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Map.minOf(selector: (Map.Entry) -> Float): Float { + return entries.minOf(selector) +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each entry in the map. + * + * @throws NoSuchElementException if the map is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun > Map.minOf(selector: (Map.Entry) -> R): R { + return entries.minOf(selector) +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Map.minOfOrNull(selector: (Map.Entry) -> Double): Double? { + return entries.minOfOrNull(selector) +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Map.minOfOrNull(selector: (Map.Entry) -> Float): Float? { + return entries.minOfOrNull(selector) +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun > Map.minOfOrNull(selector: (Map.Entry) -> R): R? { + return entries.minOfOrNull(selector) +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each entry in the map. + * + * @throws NoSuchElementException if the map is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Map.minOfWith(comparator: Comparator, selector: (Map.Entry) -> R): R { + return entries.minOfWith(comparator, selector) +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each entry in the map or `null` if there are no entries. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Map.minOfWithOrNull(comparator: Comparator, selector: (Map.Entry) -> R): R? { + return entries.minOfWithOrNull(comparator, selector) +} + /** * Returns the first entry having the smallest value according to the provided [comparator] or `null` if there are no entries. */ diff --git a/libraries/stdlib/common/src/generated/_Sequences.kt b/libraries/stdlib/common/src/generated/_Sequences.kt index 2c7ac55b7f2..78c6aac0c4e 100644 --- a/libraries/stdlib/common/src/generated/_Sequences.kt +++ b/libraries/stdlib/common/src/generated/_Sequences.kt @@ -1248,6 +1248,208 @@ public inline fun > Sequence.maxBy(selector: (T) -> R): return maxElem } +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the sequence. + * + * @throws NoSuchElementException if the sequence is empty. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the sequence. + * + * @throws NoSuchElementException if the sequence is empty. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the sequence. + * + * @throws NoSuchElementException if the sequence is empty. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun > Sequence.maxOf(selector: (T) -> R): R { + val iterator = iterator() + if (!iterator.hasNext()) throw NoSuchElementException() + var maxValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + + if (maxValue < v) { + maxValue = v + } + } + return maxValue +} + +/** + * 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. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun > Sequence.maxOfOrNull(selector: (T) -> R): R? { + val iterator = iterator() + if (!iterator.hasNext()) return null + var maxValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + + if (maxValue < v) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the sequence. + * + * @throws NoSuchElementException if the sequence is empty. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Sequence.maxOfWith(comparator: Comparator, selector: (T) -> R): R { + val iterator = iterator() + if (!iterator.hasNext()) throw NoSuchElementException() + var maxValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + if (comparator.compare(maxValue, v) < 0) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the sequence or `null` if there are no elements. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Sequence.maxOfWithOrNull(comparator: Comparator, selector: (T) -> R): R? { + val iterator = iterator() + if (!iterator.hasNext()) return null + var maxValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + if (comparator.compare(maxValue, v) < 0) { + maxValue = v + } + } + return maxValue +} + /** * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements. * @@ -1346,6 +1548,208 @@ public inline fun > Sequence.minBy(selector: (T) -> R): return minElem } +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the sequence. + * + * @throws NoSuchElementException if the sequence is empty. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the sequence. + * + * @throws NoSuchElementException if the sequence is empty. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the sequence. + * + * @throws NoSuchElementException if the sequence is empty. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun > Sequence.minOf(selector: (T) -> R): R { + val iterator = iterator() + if (!iterator.hasNext()) throw NoSuchElementException() + var minValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + + if (minValue > v) { + minValue = v + } + } + return minValue +} + +/** + * 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. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun > Sequence.minOfOrNull(selector: (T) -> R): R? { + val iterator = iterator() + if (!iterator.hasNext()) return null + var minValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + + if (minValue > v) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the sequence. + * + * @throws NoSuchElementException if the sequence is empty. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Sequence.minOfWith(comparator: Comparator, selector: (T) -> R): R { + val iterator = iterator() + if (!iterator.hasNext()) throw NoSuchElementException() + var minValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + if (comparator.compare(minValue, v) > 0) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the sequence or `null` if there are no elements. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +public inline fun Sequence.minOfWithOrNull(comparator: Comparator, selector: (T) -> R): R? { + val iterator = iterator() + if (!iterator.hasNext()) return null + var minValue = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + if (comparator.compare(minValue, v) > 0) { + minValue = v + } + } + return minValue +} + /** * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements. * diff --git a/libraries/stdlib/common/src/generated/_Strings.kt b/libraries/stdlib/common/src/generated/_Strings.kt index 309e204c5af..8dff8ea6449 100644 --- a/libraries/stdlib/common/src/generated/_Strings.kt +++ b/libraries/stdlib/common/src/generated/_Strings.kt @@ -1123,6 +1123,202 @@ public inline fun > CharSequence.maxBy(selector: (Char) -> R): return maxElem } +/** + * Returns the largest value among all values produced by [selector] function + * applied to each character in the char sequence. + * + * @throws NoSuchElementException if the char sequence is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each character in the char sequence. + * + * @throws NoSuchElementException if the char sequence is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each character in the char sequence. + * + * @throws NoSuchElementException if the char sequence is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each character in the char sequence. + * + * @throws NoSuchElementException if the char sequence is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each character in the char sequence or `null` if there are no characters. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + /** * Returns the first character having the largest value according to the provided [comparator] or `null` if there are no characters. */ @@ -1171,6 +1367,202 @@ public inline fun > CharSequence.minBy(selector: (Char) -> R): return minElem } +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each character in the char sequence. + * + * @throws NoSuchElementException if the char sequence is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each character in the char sequence. + * + * @throws NoSuchElementException if the char sequence is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each character in the char sequence. + * + * @throws NoSuchElementException if the char sequence is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each character in the char sequence. + * + * @throws NoSuchElementException if the char sequence is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each character in the char sequence or `null` if there are no characters. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + /** * Returns the first character having the smallest value according to the provided [comparator] or `null` if there are no characters. */ diff --git a/libraries/stdlib/common/src/generated/_UArrays.kt b/libraries/stdlib/common/src/generated/_UArrays.kt index 83084848796..ce818572c5a 100644 --- a/libraries/stdlib/common/src/generated/_UArrays.kt +++ b/libraries/stdlib/common/src/generated/_UArrays.kt @@ -5870,6 +5870,822 @@ public inline fun > UShortArray.maxBy(selector: (UShort) -> R) return maxElem } +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + +/** + * Returns the largest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + maxValue = v + } + } + return maxValue +} + /** * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements. */ @@ -6090,6 +6906,822 @@ public inline fun > UShortArray.minBy(selector: (UShort) -> R) return minElem } +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value among all values produced by [selector] function + * applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * 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. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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 + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array. + * + * @throws NoSuchElementException if the array is empty. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + +/** + * Returns the smallest value according to the provided [comparator] + * among all values produced by [selector] function applied to each element in the array or `null` if there are no elements. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +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) { + minValue = v + } + } + return minValue +} + /** * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements. */ diff --git a/libraries/stdlib/test/collections/CollectionTest.kt b/libraries/stdlib/test/collections/CollectionTest.kt index 63de7c0afbf..4a7f99686b0 100644 --- a/libraries/stdlib/test/collections/CollectionTest.kt +++ b/libraries/stdlib/test/collections/CollectionTest.kt @@ -9,6 +9,7 @@ import test.assertStaticAndRuntimeTypeIs import kotlin.test.* import test.collections.behaviors.* import test.comparisons.STRING_CASE_INSENSITIVE_ORDER +import kotlin.math.pow import kotlin.random.Random class CollectionTest { @@ -894,6 +895,63 @@ class CollectionTest { assertEquals(5, c) } + @Test fun minOf() { + assertEquals(null, emptyList().minOfOrNull { it } ) + assertFailsWith { emptyList().minOf { it } } + + assertEquals(1, listOf(1).minOf { it }) + assertEquals(-3, listOf(2, 3).minOf { -it }) + assertEquals("xa", listOf('a', 'b').minOf { "x$it" }) + assertEquals(1, listOf("b", "abc").minOf { it.length }) + + assertEquals(-32.0, listOf(1, 2, 3, 4, 5).minOf { (-2.0).pow(it) }) + assertEquals(-32.0F, listOf(1, 2, 3, 4, 5).minOf { (-2.0F).pow(it) }) + + 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) }) + } + + @Test fun minOfWith() { + val data = listOf("abca", "bcaa", "cabb") + val result = data.minOfWith(compareBy { it.reversed() }) { it.take(3) } + val resultOrNull = data.minOfWithOrNull(compareBy { it.reversed() }) { it.take(3) } + assertEquals("bca", result) + assertEquals(result, resultOrNull) + + assertEquals(null, emptyList().minOfWithOrNull(naturalOrder()) { it }) + // TODO: investigate why no unit-coercion happens here and an explicit 'Unit' is required + assertFailsWith { emptyList().minOfWith(naturalOrder()) { it }; Unit } + } + + @Test fun maxOf() { + assertEquals(null, emptyList().maxOfOrNull { it } ) + assertFailsWith { emptyList().maxOf { it } } + + assertEquals(1, listOf(1).maxOf { it }) + assertEquals(-2, listOf(2, 3).maxOf { -it }) + assertEquals("xb", listOf('a', 'b').maxOf { "x$it" }) + assertEquals(3, listOf("b", "abc").maxOf { it.length }) + + 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) }) + } + + @Test fun maxOfWith() { + val data = listOf("abca", "bcaa", "cabb") + val result = data.maxOfWith(compareBy { it.reversed() }) { it.take(3) } + val resultOrNull = data.maxOfWithOrNull(compareBy { it.reversed() }) { it.take(3) } + assertEquals("abc", result) + assertEquals(result, resultOrNull) + + 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) }) + } + + @Test fun sum() { expect(0) { arrayListOf().sum() } expect(14) { listOf(2, 3, 9).sum() } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt index 9b0a456253f..c66ee21adb0 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt @@ -544,6 +544,152 @@ object Aggregates : TemplateGroupBase() { } } + fun f_minMaxOf() = sequence { + fun def(op: String, selectorType: String, nullable: Boolean, orNull: String = "OrNull".ifOrEmpty(nullable)) = + fn("${op}Of$orNull(selector: (T) -> $selectorType)") { + includeDefault() + include(Maps, CharSequences, ArraysOfUnsigned) + } builder { + inlineOnly() + since("1.4") + annotation("@OptIn(kotlin.experimental.ExperimentalTypeInference::class)") + annotation("@OverloadResolutionByLambdaReturnType") + + val isFloat = selectorType != "R" + + doc { + """ + 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) + + """ + @throws NoSuchElementException if the ${f.collection} is empty. + """.ifOrEmpty(!nullable) + } + + if (!isFloat) typeParam("R : Comparable") + returns(selectorType + "?".ifOrEmpty(nullable)) + val doOnEmpty = if (nullable) "return null" else "throw NoSuchElementException()" + val acc = op + "Value" + val cmp = if (op == "max") "<" else ">" + 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 + } + } + return $acc + """ + } + body(CharSequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) { + """ + 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 + } + } + return $acc + """ + } + specialFor(Maps) { + inlineOnly() + body { "return entries.${op}Of$orNull(selector)" } + } + } + + + for (op in listOf("min", "max")) + for (selectorType in listOf("R", "Float", "Double")) + for (nullable in listOf(false, true)) + yield(def(op, selectorType, nullable)) + } + + fun f_minMaxOfWith() = sequence { + val selectorType = "R" + fun def(op: String, nullable: Boolean, orNull: String = "OrNull".ifOrEmpty(nullable)) = + fn("${op}OfWith$orNull(comparator: Comparator, selector: (T) -> $selectorType)") { + includeDefault() + include(Maps, CharSequences, ArraysOfUnsigned) + } builder { + inlineOnly() + since("1.4") + annotation("@OptIn(kotlin.experimental.ExperimentalTypeInference::class)") + annotation("@OverloadResolutionByLambdaReturnType") + + doc { + """ + Returns the ${if (op == "max") "largest" else "smallest"} value according to the provided [comparator] + 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)}. + """ + + """ + @throws NoSuchElementException if the ${f.collection} is empty. + """.ifOrEmpty(!nullable) + } + + typeParam(selectorType) + returns(selectorType + "?".ifOrEmpty(nullable)) + val doOnEmpty = if (nullable) "return null" else "throw NoSuchElementException()" + val acc = op + "Value" + val cmp = if (op == "max") "<" else ">" + body { + """ + val iterator = iterator() + if (!iterator.hasNext()) $doOnEmpty + var $acc = selector(iterator.next()) + while (iterator.hasNext()) { + val v = selector(iterator.next()) + if (comparator.compare($acc, v) $cmp 0) { + $acc = v + } + } + return $acc + """ + } + body(CharSequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) { + """ + 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) { + $acc = v + } + } + return $acc + """ + } + specialFor(Maps) { + body { "return entries.${op}OfWith$orNull(comparator, selector)" } + } + } + + for (op in listOf("min", "max")) + for (nullable in listOf(false, true)) + yield(def(op, nullable)) + } + + val f_foldIndexed = fn("foldIndexed(initial: R, operation: (index: Int, acc: R, T) -> R)") { includeDefault() include(CharSequences) diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/CommonTypes.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/CommonTypes.kt index fa3454daa17..52e288f96f2 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/CommonTypes.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/CommonTypes.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. */ @@ -139,4 +139,6 @@ enum class SequenceClass { data class Deprecation(val message: String, val replaceWith: String? = null, val level: DeprecationLevel = DeprecationLevel.WARNING) val forBinaryCompatibility = Deprecation("Provided for binary compatibility", level = DeprecationLevel.HIDDEN) -data class ThrowsException(val exceptionType: String, val reason: String) \ No newline at end of file +data class ThrowsException(val exceptionType: String, val reason: String) + +fun String.ifOrEmpty(condition: Boolean): String = if (condition) this else "" \ No newline at end of file