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
|
||||
|
||||
+32
@@ -1421,6 +1421,15 @@ public final class kotlin/collections/ArraysKt {
|
||||
public static final fun maxWith ([Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object;
|
||||
public static final fun maxWith ([SLjava/util/Comparator;)Ljava/lang/Short;
|
||||
public static final fun maxWith ([ZLjava/util/Comparator;)Ljava/lang/Boolean;
|
||||
public static final fun maxWithOrNull ([BLjava/util/Comparator;)Ljava/lang/Byte;
|
||||
public static final fun maxWithOrNull ([CLjava/util/Comparator;)Ljava/lang/Character;
|
||||
public static final fun maxWithOrNull ([DLjava/util/Comparator;)Ljava/lang/Double;
|
||||
public static final fun maxWithOrNull ([FLjava/util/Comparator;)Ljava/lang/Float;
|
||||
public static final fun maxWithOrNull ([ILjava/util/Comparator;)Ljava/lang/Integer;
|
||||
public static final fun maxWithOrNull ([JLjava/util/Comparator;)Ljava/lang/Long;
|
||||
public static final fun maxWithOrNull ([Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object;
|
||||
public static final fun maxWithOrNull ([SLjava/util/Comparator;)Ljava/lang/Short;
|
||||
public static final fun maxWithOrNull ([ZLjava/util/Comparator;)Ljava/lang/Boolean;
|
||||
public static final fun min ([B)Ljava/lang/Byte;
|
||||
public static final fun min ([C)Ljava/lang/Character;
|
||||
public static final fun min ([D)Ljava/lang/Double;
|
||||
@@ -1468,6 +1477,15 @@ public final class kotlin/collections/ArraysKt {
|
||||
public static final fun minWith ([Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object;
|
||||
public static final fun minWith ([SLjava/util/Comparator;)Ljava/lang/Short;
|
||||
public static final fun minWith ([ZLjava/util/Comparator;)Ljava/lang/Boolean;
|
||||
public static final fun minWithOrNull ([BLjava/util/Comparator;)Ljava/lang/Byte;
|
||||
public static final fun minWithOrNull ([CLjava/util/Comparator;)Ljava/lang/Character;
|
||||
public static final fun minWithOrNull ([DLjava/util/Comparator;)Ljava/lang/Double;
|
||||
public static final fun minWithOrNull ([FLjava/util/Comparator;)Ljava/lang/Float;
|
||||
public static final fun minWithOrNull ([ILjava/util/Comparator;)Ljava/lang/Integer;
|
||||
public static final fun minWithOrNull ([JLjava/util/Comparator;)Ljava/lang/Long;
|
||||
public static final fun minWithOrNull ([Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object;
|
||||
public static final fun minWithOrNull ([SLjava/util/Comparator;)Ljava/lang/Short;
|
||||
public static final fun minWithOrNull ([ZLjava/util/Comparator;)Ljava/lang/Boolean;
|
||||
public static final fun none ([B)Z
|
||||
public static final fun none ([BLkotlin/jvm/functions/Function1;)Z
|
||||
public static final fun none ([C)Z
|
||||
@@ -2238,6 +2256,7 @@ public final class kotlin/collections/CollectionsKt {
|
||||
public static final fun maxOrNull (Ljava/lang/Iterable;)Ljava/lang/Double;
|
||||
public static final fun maxOrNull (Ljava/lang/Iterable;)Ljava/lang/Float;
|
||||
public static final fun maxWith (Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/lang/Object;
|
||||
public static final fun maxWithOrNull (Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/lang/Object;
|
||||
public static final fun min (Ljava/lang/Iterable;)Ljava/lang/Comparable;
|
||||
public static final fun min (Ljava/lang/Iterable;)Ljava/lang/Double;
|
||||
public static final fun min (Ljava/lang/Iterable;)Ljava/lang/Float;
|
||||
@@ -2247,6 +2266,7 @@ public final class kotlin/collections/CollectionsKt {
|
||||
public static final fun minOrNull (Ljava/lang/Iterable;)Ljava/lang/Double;
|
||||
public static final fun minOrNull (Ljava/lang/Iterable;)Ljava/lang/Float;
|
||||
public static final fun minWith (Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/lang/Object;
|
||||
public static final fun minWithOrNull (Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/lang/Object;
|
||||
public static final fun minus (Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
|
||||
public static final fun minus (Ljava/lang/Iterable;Ljava/lang/Object;)Ljava/util/List;
|
||||
public static final fun minus (Ljava/lang/Iterable;Lkotlin/sequences/Sequence;)Ljava/util/List;
|
||||
@@ -2669,6 +2689,10 @@ public final class kotlin/collections/unsigned/UArraysKt {
|
||||
public static final fun maxWith-YmdZ_VM ([ILjava/util/Comparator;)Lkotlin/UInt;
|
||||
public static final fun maxWith-eOHTfZs ([SLjava/util/Comparator;)Lkotlin/UShort;
|
||||
public static final fun maxWith-zrEWJaI ([JLjava/util/Comparator;)Lkotlin/ULong;
|
||||
public static final fun maxWithOrNull-XMRcp5o ([BLjava/util/Comparator;)Lkotlin/UByte;
|
||||
public static final fun maxWithOrNull-YmdZ_VM ([ILjava/util/Comparator;)Lkotlin/UInt;
|
||||
public static final fun maxWithOrNull-eOHTfZs ([SLjava/util/Comparator;)Lkotlin/UShort;
|
||||
public static final fun maxWithOrNull-zrEWJaI ([JLjava/util/Comparator;)Lkotlin/ULong;
|
||||
public static final fun min--ajY-9A ([I)Lkotlin/UInt;
|
||||
public static final fun min-GBYM_sE ([B)Lkotlin/UByte;
|
||||
public static final fun min-QwZRm1k ([J)Lkotlin/ULong;
|
||||
@@ -2681,6 +2705,10 @@ public final class kotlin/collections/unsigned/UArraysKt {
|
||||
public static final fun minWith-YmdZ_VM ([ILjava/util/Comparator;)Lkotlin/UInt;
|
||||
public static final fun minWith-eOHTfZs ([SLjava/util/Comparator;)Lkotlin/UShort;
|
||||
public static final fun minWith-zrEWJaI ([JLjava/util/Comparator;)Lkotlin/ULong;
|
||||
public static final fun minWithOrNull-XMRcp5o ([BLjava/util/Comparator;)Lkotlin/UByte;
|
||||
public static final fun minWithOrNull-YmdZ_VM ([ILjava/util/Comparator;)Lkotlin/UInt;
|
||||
public static final fun minWithOrNull-eOHTfZs ([SLjava/util/Comparator;)Lkotlin/UShort;
|
||||
public static final fun minWithOrNull-zrEWJaI ([JLjava/util/Comparator;)Lkotlin/ULong;
|
||||
public static final fun plus-CFIt9YE ([ILjava/util/Collection;)[I
|
||||
public static final fun plus-kzHmqpY ([JLjava/util/Collection;)[J
|
||||
public static final fun plus-ojwP5H8 ([SLjava/util/Collection;)[S
|
||||
@@ -4897,6 +4925,7 @@ public final class kotlin/sequences/SequencesKt {
|
||||
public static final fun maxOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Double;
|
||||
public static final fun maxOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Float;
|
||||
public static final fun maxWith (Lkotlin/sequences/Sequence;Ljava/util/Comparator;)Ljava/lang/Object;
|
||||
public static final fun maxWithOrNull (Lkotlin/sequences/Sequence;Ljava/util/Comparator;)Ljava/lang/Object;
|
||||
public static final fun min (Lkotlin/sequences/Sequence;)Ljava/lang/Comparable;
|
||||
public static final fun min (Lkotlin/sequences/Sequence;)Ljava/lang/Double;
|
||||
public static final fun min (Lkotlin/sequences/Sequence;)Ljava/lang/Float;
|
||||
@@ -4906,6 +4935,7 @@ public final class kotlin/sequences/SequencesKt {
|
||||
public static final fun minOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Double;
|
||||
public static final fun minOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Float;
|
||||
public static final fun minWith (Lkotlin/sequences/Sequence;Ljava/util/Comparator;)Ljava/lang/Object;
|
||||
public static final fun minWithOrNull (Lkotlin/sequences/Sequence;Ljava/util/Comparator;)Ljava/lang/Object;
|
||||
public static final fun minus (Lkotlin/sequences/Sequence;Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
|
||||
public static final fun minus (Lkotlin/sequences/Sequence;Ljava/lang/Object;)Lkotlin/sequences/Sequence;
|
||||
public static final fun minus (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence;
|
||||
@@ -5306,11 +5336,13 @@ public final class kotlin/text/StringsKt {
|
||||
public static final fun maxByOrNull (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/Character;
|
||||
public static final fun maxOrNull (Ljava/lang/CharSequence;)Ljava/lang/Character;
|
||||
public static final fun maxWith (Ljava/lang/CharSequence;Ljava/util/Comparator;)Ljava/lang/Character;
|
||||
public static final fun maxWithOrNull (Ljava/lang/CharSequence;Ljava/util/Comparator;)Ljava/lang/Character;
|
||||
public static final fun min (Ljava/lang/CharSequence;)Ljava/lang/Character;
|
||||
public static final fun minBy (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/Character;
|
||||
public static final fun minByOrNull (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/Character;
|
||||
public static final fun minOrNull (Ljava/lang/CharSequence;)Ljava/lang/Character;
|
||||
public static final fun minWith (Ljava/lang/CharSequence;Ljava/util/Comparator;)Ljava/lang/Character;
|
||||
public static final fun minWithOrNull (Ljava/lang/CharSequence;Ljava/util/Comparator;)Ljava/lang/Character;
|
||||
public static final fun none (Ljava/lang/CharSequence;)Z
|
||||
public static final fun none (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Z
|
||||
public static final fun onEach (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/CharSequence;
|
||||
|
||||
@@ -448,74 +448,56 @@ object Aggregates : TemplateGroupBase() {
|
||||
yield(def(op, nullable))
|
||||
}
|
||||
|
||||
val f_minWith = fn("minWith(comparator: Comparator<in T>)") {
|
||||
includeDefault()
|
||||
include(Maps, CharSequences, ArraysOfUnsigned)
|
||||
} builder {
|
||||
doc { "Returns the first ${f.element} having the smallest value according to the provided [comparator] or `null` if there are no ${f.element.pluralize()}." }
|
||||
returns("T?")
|
||||
body {
|
||||
"""
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
val f_minMaxWith = sequence {
|
||||
fun def(op: String, nullable: Boolean, orNull: String = "OrNull".ifOrEmpty(nullable)) =
|
||||
fn("$op$orNull(comparator: Comparator<in T>)") {
|
||||
includeDefault()
|
||||
include(Maps, CharSequences, ArraysOfUnsigned)
|
||||
} builder {
|
||||
specialFor(Maps) { if (op == "maxWith" || nullable) inlineOnly() }
|
||||
returns("T?")
|
||||
|
||||
var min = iterator.next()
|
||||
while (iterator.hasNext()) {
|
||||
val e = iterator.next()
|
||||
if (comparator.compare(min, e) > 0) min = e
|
||||
if (!nullable) {
|
||||
deprecate(Deprecation("Use ${op}OrNull instead.", "${op}OrNull(comparator)", DeprecationLevel.WARNING))
|
||||
body { "return ${op}OrNull(comparator)" }
|
||||
return@builder
|
||||
}
|
||||
|
||||
since("1.4")
|
||||
|
||||
doc { "Returns the first ${f.element} having the ${if (op == "maxWith") "largest" else "smallest"} value according to the provided [comparator] or `null` if there are no ${f.element.pluralize()}." }
|
||||
|
||||
val (acc, cmp) = if (op == "minWith") Pair("min", ">") else Pair("max", "<")
|
||||
body {
|
||||
"""
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
|
||||
var $acc = iterator.next()
|
||||
while (iterator.hasNext()) {
|
||||
val e = iterator.next()
|
||||
if (comparator.compare($acc, e) $cmp 0) $acc = e
|
||||
}
|
||||
return $acc
|
||||
"""
|
||||
}
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
|
||||
"""
|
||||
if (isEmpty()) return null
|
||||
var $acc = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (comparator.compare($acc, e) $cmp 0) $acc = e
|
||||
}
|
||||
return $acc
|
||||
"""
|
||||
}
|
||||
body(Maps) { "return entries.$op$orNull(comparator)" }
|
||||
}
|
||||
return min
|
||||
"""
|
||||
}
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
|
||||
"""
|
||||
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
|
||||
"""
|
||||
}
|
||||
body(Maps) { "return entries.minWith(comparator)" }
|
||||
}
|
||||
|
||||
val f_maxWith = fn("maxWith(comparator: Comparator<in T>)") {
|
||||
includeDefault()
|
||||
include(Maps, CharSequences, ArraysOfUnsigned)
|
||||
} builder {
|
||||
doc { "Returns the first ${f.element} having the largest value according to the provided [comparator] or `null` if there are no ${f.element.pluralize()}." }
|
||||
returns("T?")
|
||||
body {
|
||||
"""
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
|
||||
var max = iterator.next()
|
||||
while (iterator.hasNext()) {
|
||||
val e = iterator.next()
|
||||
if (comparator.compare(max, e) < 0) max = e
|
||||
}
|
||||
return max
|
||||
"""
|
||||
}
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
|
||||
"""
|
||||
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
|
||||
"""
|
||||
}
|
||||
specialFor(Maps) {
|
||||
inlineOnly()
|
||||
body { "return entries.maxWith(comparator)" }
|
||||
}
|
||||
for (op in listOf("minWith", "maxWith"))
|
||||
for (nullable in listOf(false, true))
|
||||
yield(def(op, nullable))
|
||||
}
|
||||
|
||||
fun f_minMaxOf() = sequence {
|
||||
|
||||
Reference in New Issue
Block a user