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) {
|
||||
|
||||
@@ -390,26 +390,26 @@ class ArraysTest {
|
||||
expect('b', { charArrayOf('a', 'b').maxOrNull() })
|
||||
}
|
||||
|
||||
@Test fun minWith() {
|
||||
assertEquals(null, arrayOf<Int>().minWith(naturalOrder()) )
|
||||
assertEquals("a", arrayOf("a", "B").minWith(STRING_CASE_INSENSITIVE_ORDER))
|
||||
@Test fun minWithOrNull() {
|
||||
assertEquals(null, arrayOf<Int>().minWithOrNull(naturalOrder()))
|
||||
assertEquals("a", arrayOf("a", "B").minWithOrNull(STRING_CASE_INSENSITIVE_ORDER))
|
||||
}
|
||||
|
||||
@Test fun minWithInPrimitiveArrays() {
|
||||
expect(null, { intArrayOf().minWith(naturalOrder()) })
|
||||
expect(1, { intArrayOf(1).minWith(naturalOrder()) })
|
||||
expect(4, { intArrayOf(2, 3, 4).minWith(compareBy { it % 4 }) })
|
||||
@Test fun minWithOrNullInPrimitiveArrays() {
|
||||
expect(null, { intArrayOf().minWithOrNull(naturalOrder()) })
|
||||
expect(1, { intArrayOf(1).minWithOrNull(naturalOrder()) })
|
||||
expect(4, { intArrayOf(2, 3, 4).minWithOrNull(compareBy { it % 4 }) })
|
||||
}
|
||||
|
||||
@Test fun maxWith() {
|
||||
assertEquals(null, arrayOf<Int>().maxWith(naturalOrder()) )
|
||||
assertEquals("B", arrayOf("a", "B").maxWith(STRING_CASE_INSENSITIVE_ORDER))
|
||||
@Test fun maxWithOrNull() {
|
||||
assertEquals(null, arrayOf<Int>().maxWithOrNull(naturalOrder()))
|
||||
assertEquals("B", arrayOf("a", "B").maxWithOrNull(STRING_CASE_INSENSITIVE_ORDER))
|
||||
}
|
||||
|
||||
@Test fun maxWithInPrimitiveArrays() {
|
||||
expect(null, { intArrayOf().maxWith(naturalOrder()) })
|
||||
expect(1, { intArrayOf(1).maxWith(naturalOrder()) })
|
||||
expect(-4, { intArrayOf(2, 3, -4).maxWith(compareBy { it*it }) })
|
||||
@Test fun maxWithOrNullInPrimitiveArrays() {
|
||||
expect(null, { intArrayOf().maxWithOrNull(naturalOrder()) })
|
||||
expect(1, { intArrayOf(1).maxWithOrNull(naturalOrder()) })
|
||||
expect(-4, { intArrayOf(2, 3, -4).maxWithOrNull(compareBy { it * it }) })
|
||||
}
|
||||
|
||||
@Test fun minByOrNull() {
|
||||
|
||||
@@ -851,18 +851,18 @@ class CollectionTest {
|
||||
assertIsPositiveZero(listOf(0.0F, -0.0F).shuffled().maxOrNull()!!.toDouble())
|
||||
}
|
||||
|
||||
@Test fun minWith() {
|
||||
expect(null, { listOf<Int>().minWith(naturalOrder()) })
|
||||
expect(1, { listOf(1).minWith(naturalOrder()) })
|
||||
expect("a", { listOf("a", "B").minWith(STRING_CASE_INSENSITIVE_ORDER) })
|
||||
expect("a", { listOf("a", "B").asSequence().minWith(STRING_CASE_INSENSITIVE_ORDER) })
|
||||
@Test fun minWithOrNull() {
|
||||
expect(null, { listOf<Int>().minWithOrNull(naturalOrder()) })
|
||||
expect(1, { listOf(1).minWithOrNull(naturalOrder()) })
|
||||
expect("a", { listOf("a", "B").minWithOrNull(STRING_CASE_INSENSITIVE_ORDER) })
|
||||
expect("a", { listOf("a", "B").asSequence().minWithOrNull(STRING_CASE_INSENSITIVE_ORDER) })
|
||||
}
|
||||
|
||||
@Test fun maxWith() {
|
||||
expect(null, { listOf<Int>().maxWith(naturalOrder()) })
|
||||
expect(1, { listOf(1).maxWith(naturalOrder()) })
|
||||
expect("B", { listOf("a", "B").maxWith(STRING_CASE_INSENSITIVE_ORDER) })
|
||||
expect("B", { listOf("a", "B").asSequence().maxWith(STRING_CASE_INSENSITIVE_ORDER) })
|
||||
@Test fun maxWithOrNull() {
|
||||
expect(null, { listOf<Int>().maxWithOrNull(naturalOrder()) })
|
||||
expect(1, { listOf(1).maxWithOrNull(naturalOrder()) })
|
||||
expect("B", { listOf("a", "B").maxWithOrNull(STRING_CASE_INSENSITIVE_ORDER) })
|
||||
expect("B", { listOf("a", "B").asSequence().maxWithOrNull(STRING_CASE_INSENSITIVE_ORDER) })
|
||||
}
|
||||
|
||||
@Test fun minByOrNull() {
|
||||
|
||||
@@ -451,35 +451,35 @@ class UnsignedArraysTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun minWith() {
|
||||
expect(null) { arrayOf<UByte>().minWith(naturalOrder()) }
|
||||
expect(1u) { arrayOf<UShort>(1).minWith(naturalOrder()) }
|
||||
expect(2u) { arrayOf<UInt>(2, 3).minWith(naturalOrder()) }
|
||||
expect(2uL) { arrayOf<ULong>(3, 2).minWith(naturalOrder()) }
|
||||
fun minWitOrNullh() {
|
||||
expect(null) { arrayOf<UByte>().minWithOrNull(naturalOrder()) }
|
||||
expect(1u) { arrayOf<UShort>(1).minWithOrNull(naturalOrder()) }
|
||||
expect(2u) { arrayOf<UInt>(2, 3).minWithOrNull(naturalOrder()) }
|
||||
expect(2uL) { arrayOf<ULong>(3, 2).minWithOrNull(naturalOrder()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun minWithInUnsignedArrays() {
|
||||
expect(null) { ubyteArrayOf().minWith(reverseOrder()) }
|
||||
expect(1u) { ushortArrayOf(1).minWith(reverseOrder()) }
|
||||
expect(3u) { uintArrayOf(2, 3).minWith(reverseOrder()) }
|
||||
expect(3uL) { ulongArrayOf(3, 2).minWith(reverseOrder()) }
|
||||
fun minWithOrNullInUnsignedArrays() {
|
||||
expect(null) { ubyteArrayOf().minWithOrNull(reverseOrder()) }
|
||||
expect(1u) { ushortArrayOf(1).minWithOrNull(reverseOrder()) }
|
||||
expect(3u) { uintArrayOf(2, 3).minWithOrNull(reverseOrder()) }
|
||||
expect(3uL) { ulongArrayOf(3, 2).minWithOrNull(reverseOrder()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun maxWith() {
|
||||
expect(null) { arrayOf<UByte>().maxWith(naturalOrder()) }
|
||||
expect(1u) { arrayOf<UShort>(1).maxWith(naturalOrder()) }
|
||||
expect(3u) { arrayOf<UInt>(2, 3).maxWith(naturalOrder()) }
|
||||
expect(3uL) { arrayOf<ULong>(3, 2).maxWith(naturalOrder()) }
|
||||
fun maxWithOrNull() {
|
||||
expect(null) { arrayOf<UByte>().maxWithOrNull(naturalOrder()) }
|
||||
expect(1u) { arrayOf<UShort>(1).maxWithOrNull(naturalOrder()) }
|
||||
expect(3u) { arrayOf<UInt>(2, 3).maxWithOrNull(naturalOrder()) }
|
||||
expect(3uL) { arrayOf<ULong>(3, 2).maxWithOrNull(naturalOrder()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun maxWithInUnsignedArrays() {
|
||||
expect(null) { ubyteArrayOf().maxWith(reverseOrder()) }
|
||||
expect(1u) { ushortArrayOf(1).maxWith(reverseOrder()) }
|
||||
expect(2u) { uintArrayOf(2, 3).maxWith(reverseOrder()) }
|
||||
expect(2uL) { ulongArrayOf(3, 2).maxWith(reverseOrder()) }
|
||||
fun maxWithOrNullInUnsignedArrays() {
|
||||
expect(null) { ubyteArrayOf().maxWithOrNull(reverseOrder()) }
|
||||
expect(1u) { ushortArrayOf(1).maxWithOrNull(reverseOrder()) }
|
||||
expect(2u) { uintArrayOf(2, 3).maxWithOrNull(reverseOrder()) }
|
||||
expect(2uL) { ulongArrayOf(3, 2).maxWithOrNull(reverseOrder()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user