Introduce minWithOrNull and maxWithOrNull extension functions #KT-38854
This commit is contained in:
@@ -15021,101 +15021,56 @@ public fun CharArray.maxOrNull(): Char? {
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
public fun <T> Array<out T>.maxWith(comparator: Comparator<in T>): T? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
public fun ByteArray.maxWith(comparator: Comparator<in Byte>): Byte? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
public fun ShortArray.maxWith(comparator: Comparator<in Short>): Short? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
public fun IntArray.maxWith(comparator: Comparator<in Int>): Int? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
public fun LongArray.maxWith(comparator: Comparator<in Long>): Long? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
public fun FloatArray.maxWith(comparator: Comparator<in Float>): Float? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
public fun DoubleArray.maxWith(comparator: Comparator<in Double>): Double? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
public fun BooleanArray.maxWith(comparator: Comparator<in Boolean>): Boolean? {
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
public fun CharArray.maxWith(comparator: Comparator<in Char>): Char? {
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun <T> Array<out T>.maxWithOrNull(comparator: Comparator<in T>): T? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -15128,7 +15083,106 @@ public fun BooleanArray.maxWith(comparator: Comparator<in Boolean>): Boolean? {
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
public fun CharArray.maxWith(comparator: Comparator<in Char>): Char? {
|
||||
@SinceKotlin("1.4")
|
||||
public fun ByteArray.maxWithOrNull(comparator: Comparator<in Byte>): Byte? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun ShortArray.maxWithOrNull(comparator: Comparator<in Short>): Short? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun IntArray.maxWithOrNull(comparator: Comparator<in Int>): Int? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun LongArray.maxWithOrNull(comparator: Comparator<in Long>): Long? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun FloatArray.maxWithOrNull(comparator: Comparator<in Float>): Float? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun DoubleArray.maxWithOrNull(comparator: Comparator<in Double>): Double? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun BooleanArray.maxWithOrNull(comparator: Comparator<in Boolean>): Boolean? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun CharArray.maxWithOrNull(comparator: Comparator<in Char>): Char? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -17102,101 +17156,56 @@ public fun CharArray.minOrNull(): Char? {
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
public fun <T> Array<out T>.minWith(comparator: Comparator<in T>): T? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
public fun ByteArray.minWith(comparator: Comparator<in Byte>): Byte? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
public fun ShortArray.minWith(comparator: Comparator<in Short>): Short? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
public fun IntArray.minWith(comparator: Comparator<in Int>): Int? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
public fun LongArray.minWith(comparator: Comparator<in Long>): Long? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
public fun FloatArray.minWith(comparator: Comparator<in Float>): Float? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
public fun DoubleArray.minWith(comparator: Comparator<in Double>): Double? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
public fun BooleanArray.minWith(comparator: Comparator<in Boolean>): Boolean? {
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
public fun CharArray.minWith(comparator: Comparator<in Char>): Char? {
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun <T> Array<out T>.minWithOrNull(comparator: Comparator<in T>): T? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -17209,7 +17218,106 @@ public fun BooleanArray.minWith(comparator: Comparator<in Boolean>): Boolean? {
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
public fun CharArray.minWith(comparator: Comparator<in Char>): Char? {
|
||||
@SinceKotlin("1.4")
|
||||
public fun ByteArray.minWithOrNull(comparator: Comparator<in Byte>): Byte? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun ShortArray.minWithOrNull(comparator: Comparator<in Short>): Short? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun IntArray.minWithOrNull(comparator: Comparator<in Int>): Int? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun LongArray.minWithOrNull(comparator: Comparator<in Long>): Long? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun FloatArray.minWithOrNull(comparator: Comparator<in Float>): Float? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun DoubleArray.minWithOrNull(comparator: Comparator<in Double>): Double? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun BooleanArray.minWithOrNull(comparator: Comparator<in Boolean>): Boolean? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public fun CharArray.minWithOrNull(comparator: Comparator<in Char>): Char? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
|
||||
@@ -1989,10 +1989,16 @@ public fun <T : Comparable<T>> Iterable<T>.maxOrNull(): T? {
|
||||
return max
|
||||
}
|
||||
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
public fun <T> Iterable<T>.maxWith(comparator: Comparator<in T>): T? {
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
public fun <T> Iterable<T>.maxWith(comparator: Comparator<in T>): T? {
|
||||
@SinceKotlin("1.4")
|
||||
public fun <T> Iterable<T>.maxWithOrNull(comparator: Comparator<in T>): T? {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
var max = iterator.next()
|
||||
@@ -2273,10 +2279,16 @@ public fun <T : Comparable<T>> Iterable<T>.minOrNull(): T? {
|
||||
return min
|
||||
}
|
||||
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
public fun <T> Iterable<T>.minWith(comparator: Comparator<in T>): T? {
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
public fun <T> Iterable<T>.minWith(comparator: Comparator<in T>): T? {
|
||||
@SinceKotlin("1.4")
|
||||
public fun <T> Iterable<T>.minWithOrNull(comparator: Comparator<in T>): T? {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
var min = iterator.next()
|
||||
|
||||
@@ -308,12 +308,19 @@ public inline fun <K, V, R> Map<out K, V>.maxOfWithOrNull(comparator: Comparator
|
||||
return entries.maxOfWithOrNull(comparator, selector)
|
||||
}
|
||||
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <K, V> Map<out K, V>.maxWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>? {
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first entry having the largest value according to the provided [comparator] or `null` if there are no entries.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <K, V> Map<out K, V>.maxWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>? {
|
||||
return entries.maxWith(comparator)
|
||||
public inline fun <K, V> Map<out K, V>.maxWithOrNull(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>? {
|
||||
return entries.maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
@Deprecated("Use minByOrNull instead.", ReplaceWith("minByOrNull(selector)"))
|
||||
@@ -444,11 +451,18 @@ public inline fun <K, V, R> Map<out K, V>.minOfWithOrNull(comparator: Comparator
|
||||
return entries.minOfWithOrNull(comparator, selector)
|
||||
}
|
||||
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
public fun <K, V> Map<out K, V>.minWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>? {
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first entry having the smallest value according to the provided [comparator] or `null` if there are no entries.
|
||||
*/
|
||||
public fun <K, V> Map<out K, V>.minWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>? {
|
||||
return entries.minWith(comparator)
|
||||
@SinceKotlin("1.4")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <K, V> Map<out K, V>.minWithOrNull(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>? {
|
||||
return entries.minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1460,12 +1460,18 @@ public fun <T : Comparable<T>> Sequence<T>.maxOrNull(): T? {
|
||||
return max
|
||||
}
|
||||
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
public fun <T> Sequence<T>.maxWith(comparator: Comparator<in T>): T? {
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public fun <T> Sequence<T>.maxWith(comparator: Comparator<in T>): T? {
|
||||
@SinceKotlin("1.4")
|
||||
public fun <T> Sequence<T>.maxWithOrNull(comparator: Comparator<in T>): T? {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
var max = iterator.next()
|
||||
@@ -1770,12 +1776,18 @@ public fun <T : Comparable<T>> Sequence<T>.minOrNull(): T? {
|
||||
return min
|
||||
}
|
||||
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
public fun <T> Sequence<T>.minWith(comparator: Comparator<in T>): T? {
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
public fun <T> Sequence<T>.minWith(comparator: Comparator<in T>): T? {
|
||||
@SinceKotlin("1.4")
|
||||
public fun <T> Sequence<T>.minWithOrNull(comparator: Comparator<in T>): T? {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
var min = iterator.next()
|
||||
|
||||
@@ -1303,10 +1303,16 @@ public fun CharSequence.maxOrNull(): Char? {
|
||||
return max
|
||||
}
|
||||
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
public fun CharSequence.maxWith(comparator: Comparator<in Char>): Char? {
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first character having the largest value according to the provided [comparator] or `null` if there are no characters.
|
||||
*/
|
||||
public fun CharSequence.maxWith(comparator: Comparator<in Char>): Char? {
|
||||
@SinceKotlin("1.4")
|
||||
public fun CharSequence.maxWithOrNull(comparator: Comparator<in Char>): Char? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -1531,10 +1537,16 @@ public fun CharSequence.minOrNull(): Char? {
|
||||
return min
|
||||
}
|
||||
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
public fun CharSequence.minWith(comparator: Comparator<in Char>): Char? {
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first character having the smallest value according to the provided [comparator] or `null` if there are no characters.
|
||||
*/
|
||||
public fun CharSequence.minWith(comparator: Comparator<in Char>): Char? {
|
||||
@SinceKotlin("1.4")
|
||||
public fun CharSequence.minWithOrNull(comparator: Comparator<in Char>): Char? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
|
||||
@@ -6626,42 +6626,40 @@ public fun UShortArray.maxOrNull(): UShort? {
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UIntArray.maxWith(comparator: Comparator<in UInt>): UInt? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun ULongArray.maxWith(comparator: Comparator<in ULong>): ULong? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UByteArray.maxWith(comparator: Comparator<in UByte>): UByte? {
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UShortArray.maxWith(comparator: Comparator<in UShort>): UShort? {
|
||||
return maxWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UIntArray.maxWithOrNull(comparator: Comparator<in UInt>): UInt? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -6674,9 +6672,39 @@ public fun UByteArray.maxWith(comparator: Comparator<in UByte>): UByte? {
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UShortArray.maxWith(comparator: Comparator<in UShort>): UShort? {
|
||||
public fun ULongArray.maxWithOrNull(comparator: Comparator<in ULong>): ULong? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UByteArray.maxWithOrNull(comparator: Comparator<in UByte>): UByte? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UShortArray.maxWithOrNull(comparator: Comparator<in UShort>): UShort? {
|
||||
if (isEmpty()) return null
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -7610,42 +7638,40 @@ public fun UShortArray.minOrNull(): UShort? {
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UIntArray.minWith(comparator: Comparator<in UInt>): UInt? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun ULongArray.minWith(comparator: Comparator<in ULong>): ULong? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UByteArray.minWith(comparator: Comparator<in UByte>): UByte? {
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UShortArray.minWith(comparator: Comparator<in UShort>): UShort? {
|
||||
return minWithOrNull(comparator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UIntArray.minWithOrNull(comparator: Comparator<in UInt>): UInt? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -7658,9 +7684,39 @@ public fun UByteArray.minWith(comparator: Comparator<in UByte>): UByte? {
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UShortArray.minWith(comparator: Comparator<in UShort>): UShort? {
|
||||
public fun ULongArray.minWithOrNull(comparator: Comparator<in ULong>): ULong? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UByteArray.minWithOrNull(comparator: Comparator<in UByte>): UByte? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun UShortArray.minWithOrNull(comparator: Comparator<in UShort>): UShort? {
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
|
||||
Reference in New Issue
Block a user