提交 16b62b8e 编写于 作者: A Abduqodiri Qurbonzoda

Introduce minWithOrNull and maxWithOrNull extension functions #KT-38854

上级 194791a1
...@@ -15021,10 +15021,56 @@ public fun CharArray.maxOrNull(): Char? { ...@@ -15021,10 +15021,56 @@ public fun CharArray.maxOrNull(): Char? {
return max return max
} }
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
public fun <T> Array<out T>.maxWith(comparator: Comparator<in T>): T? {
return maxWithOrNull(comparator)
}
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
public fun ByteArray.maxWith(comparator: Comparator<in Byte>): Byte? {
return maxWithOrNull(comparator)
}
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
public fun ShortArray.maxWith(comparator: Comparator<in Short>): Short? {
return maxWithOrNull(comparator)
}
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
public fun IntArray.maxWith(comparator: Comparator<in Int>): Int? {
return maxWithOrNull(comparator)
}
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
public fun LongArray.maxWith(comparator: Comparator<in Long>): Long? {
return maxWithOrNull(comparator)
}
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
public fun FloatArray.maxWith(comparator: Comparator<in Float>): Float? {
return maxWithOrNull(comparator)
}
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
public fun DoubleArray.maxWith(comparator: Comparator<in Double>): Double? {
return maxWithOrNull(comparator)
}
@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. * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun <T> Array<out T>.maxWith(comparator: Comparator<in T>): T? { @SinceKotlin("1.4")
public fun <T> Array<out T>.maxWithOrNull(comparator: Comparator<in T>): T? {
if (isEmpty()) return null if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -15037,7 +15083,8 @@ public fun <T> Array<out T>.maxWith(comparator: Comparator<in T>): T? { ...@@ -15037,7 +15083,8 @@ public fun <T> Array<out T>.maxWith(comparator: Comparator<in T>): T? {
/** /**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun ByteArray.maxWith(comparator: Comparator<in Byte>): Byte? { @SinceKotlin("1.4")
public fun ByteArray.maxWithOrNull(comparator: Comparator<in Byte>): Byte? {
if (isEmpty()) return null if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -15050,7 +15097,8 @@ public fun ByteArray.maxWith(comparator: Comparator<in Byte>): Byte? { ...@@ -15050,7 +15097,8 @@ public fun ByteArray.maxWith(comparator: Comparator<in Byte>): Byte? {
/** /**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun ShortArray.maxWith(comparator: Comparator<in Short>): Short? { @SinceKotlin("1.4")
public fun ShortArray.maxWithOrNull(comparator: Comparator<in Short>): Short? {
if (isEmpty()) return null if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -15063,7 +15111,8 @@ public fun ShortArray.maxWith(comparator: Comparator<in Short>): Short? { ...@@ -15063,7 +15111,8 @@ public fun ShortArray.maxWith(comparator: Comparator<in Short>): Short? {
/** /**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun IntArray.maxWith(comparator: Comparator<in Int>): Int? { @SinceKotlin("1.4")
public fun IntArray.maxWithOrNull(comparator: Comparator<in Int>): Int? {
if (isEmpty()) return null if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -15076,7 +15125,8 @@ public fun IntArray.maxWith(comparator: Comparator<in Int>): Int? { ...@@ -15076,7 +15125,8 @@ public fun IntArray.maxWith(comparator: Comparator<in Int>): Int? {
/** /**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun LongArray.maxWith(comparator: Comparator<in Long>): Long? { @SinceKotlin("1.4")
public fun LongArray.maxWithOrNull(comparator: Comparator<in Long>): Long? {
if (isEmpty()) return null if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -15089,7 +15139,8 @@ public fun LongArray.maxWith(comparator: Comparator<in Long>): Long? { ...@@ -15089,7 +15139,8 @@ public fun LongArray.maxWith(comparator: Comparator<in Long>): Long? {
/** /**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun FloatArray.maxWith(comparator: Comparator<in Float>): Float? { @SinceKotlin("1.4")
public fun FloatArray.maxWithOrNull(comparator: Comparator<in Float>): Float? {
if (isEmpty()) return null if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -15102,7 +15153,8 @@ public fun FloatArray.maxWith(comparator: Comparator<in Float>): Float? { ...@@ -15102,7 +15153,8 @@ public fun FloatArray.maxWith(comparator: Comparator<in Float>): Float? {
/** /**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun DoubleArray.maxWith(comparator: Comparator<in Double>): Double? { @SinceKotlin("1.4")
public fun DoubleArray.maxWithOrNull(comparator: Comparator<in Double>): Double? {
if (isEmpty()) return null if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -15115,7 +15167,8 @@ public fun DoubleArray.maxWith(comparator: Comparator<in Double>): Double? { ...@@ -15115,7 +15167,8 @@ public fun DoubleArray.maxWith(comparator: Comparator<in Double>): Double? {
/** /**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun BooleanArray.maxWith(comparator: Comparator<in Boolean>): Boolean? { @SinceKotlin("1.4")
public fun BooleanArray.maxWithOrNull(comparator: Comparator<in Boolean>): Boolean? {
if (isEmpty()) return null if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -15128,7 +15181,8 @@ public fun BooleanArray.maxWith(comparator: Comparator<in Boolean>): Boolean? { ...@@ -15128,7 +15181,8 @@ 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. * 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 CharArray.maxWithOrNull(comparator: Comparator<in Char>): Char? {
if (isEmpty()) return null if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -17102,10 +17156,56 @@ public fun CharArray.minOrNull(): Char? { ...@@ -17102,10 +17156,56 @@ public fun CharArray.minOrNull(): Char? {
return min return min
} }
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
public fun <T> Array<out T>.minWith(comparator: Comparator<in T>): T? {
return minWithOrNull(comparator)
}
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
public fun ByteArray.minWith(comparator: Comparator<in Byte>): Byte? {
return minWithOrNull(comparator)
}
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
public fun ShortArray.minWith(comparator: Comparator<in Short>): Short? {
return minWithOrNull(comparator)
}
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
public fun IntArray.minWith(comparator: Comparator<in Int>): Int? {
return minWithOrNull(comparator)
}
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
public fun LongArray.minWith(comparator: Comparator<in Long>): Long? {
return minWithOrNull(comparator)
}
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
public fun FloatArray.minWith(comparator: Comparator<in Float>): Float? {
return minWithOrNull(comparator)
}
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
public fun DoubleArray.minWith(comparator: Comparator<in Double>): Double? {
return minWithOrNull(comparator)
}
@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. * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun <T> Array<out T>.minWith(comparator: Comparator<in T>): T? { @SinceKotlin("1.4")
public fun <T> Array<out T>.minWithOrNull(comparator: Comparator<in T>): T? {
if (isEmpty()) return null if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -17118,7 +17218,8 @@ public fun <T> Array<out T>.minWith(comparator: Comparator<in T>): T? { ...@@ -17118,7 +17218,8 @@ public fun <T> Array<out T>.minWith(comparator: Comparator<in T>): T? {
/** /**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun ByteArray.minWith(comparator: Comparator<in Byte>): Byte? { @SinceKotlin("1.4")
public fun ByteArray.minWithOrNull(comparator: Comparator<in Byte>): Byte? {
if (isEmpty()) return null if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -17131,7 +17232,8 @@ public fun ByteArray.minWith(comparator: Comparator<in Byte>): Byte? { ...@@ -17131,7 +17232,8 @@ public fun ByteArray.minWith(comparator: Comparator<in Byte>): Byte? {
/** /**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun ShortArray.minWith(comparator: Comparator<in Short>): Short? { @SinceKotlin("1.4")
public fun ShortArray.minWithOrNull(comparator: Comparator<in Short>): Short? {
if (isEmpty()) return null if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -17144,7 +17246,8 @@ public fun ShortArray.minWith(comparator: Comparator<in Short>): Short? { ...@@ -17144,7 +17246,8 @@ public fun ShortArray.minWith(comparator: Comparator<in Short>): Short? {
/** /**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun IntArray.minWith(comparator: Comparator<in Int>): Int? { @SinceKotlin("1.4")
public fun IntArray.minWithOrNull(comparator: Comparator<in Int>): Int? {
if (isEmpty()) return null if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -17157,7 +17260,8 @@ public fun IntArray.minWith(comparator: Comparator<in Int>): Int? { ...@@ -17157,7 +17260,8 @@ public fun IntArray.minWith(comparator: Comparator<in Int>): Int? {
/** /**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun LongArray.minWith(comparator: Comparator<in Long>): Long? { @SinceKotlin("1.4")
public fun LongArray.minWithOrNull(comparator: Comparator<in Long>): Long? {
if (isEmpty()) return null if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -17170,7 +17274,8 @@ public fun LongArray.minWith(comparator: Comparator<in Long>): Long? { ...@@ -17170,7 +17274,8 @@ public fun LongArray.minWith(comparator: Comparator<in Long>): Long? {
/** /**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun FloatArray.minWith(comparator: Comparator<in Float>): Float? { @SinceKotlin("1.4")
public fun FloatArray.minWithOrNull(comparator: Comparator<in Float>): Float? {
if (isEmpty()) return null if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -17183,7 +17288,8 @@ public fun FloatArray.minWith(comparator: Comparator<in Float>): Float? { ...@@ -17183,7 +17288,8 @@ public fun FloatArray.minWith(comparator: Comparator<in Float>): Float? {
/** /**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun DoubleArray.minWith(comparator: Comparator<in Double>): Double? { @SinceKotlin("1.4")
public fun DoubleArray.minWithOrNull(comparator: Comparator<in Double>): Double? {
if (isEmpty()) return null if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -17196,7 +17302,8 @@ public fun DoubleArray.minWith(comparator: Comparator<in Double>): Double? { ...@@ -17196,7 +17302,8 @@ public fun DoubleArray.minWith(comparator: Comparator<in Double>): Double? {
/** /**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements. * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/ */
public fun BooleanArray.minWith(comparator: Comparator<in Boolean>): Boolean? { @SinceKotlin("1.4")
public fun BooleanArray.minWithOrNull(comparator: Comparator<in Boolean>): Boolean? {
if (isEmpty()) return null if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -17209,7 +17316,8 @@ public fun BooleanArray.minWith(comparator: Comparator<in Boolean>): Boolean? { ...@@ -17209,7 +17316,8 @@ 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. * 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 CharArray.minWithOrNull(comparator: Comparator<in Char>): Char? {
if (isEmpty()) return null if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
......
...@@ -1989,10 +1989,16 @@ public fun <T : Comparable<T>> Iterable<T>.maxOrNull(): T? { ...@@ -1989,10 +1989,16 @@ public fun <T : Comparable<T>> Iterable<T>.maxOrNull(): T? {
return max 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. * 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() val iterator = iterator()
if (!iterator.hasNext()) return null if (!iterator.hasNext()) return null
var max = iterator.next() var max = iterator.next()
...@@ -2273,10 +2279,16 @@ public fun <T : Comparable<T>> Iterable<T>.minOrNull(): T? { ...@@ -2273,10 +2279,16 @@ public fun <T : Comparable<T>> Iterable<T>.minOrNull(): T? {
return min 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. * 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() val iterator = iterator()
if (!iterator.hasNext()) return null if (!iterator.hasNext()) return null
var min = iterator.next() var min = iterator.next()
......
...@@ -308,12 +308,19 @@ public inline fun <K, V, R> Map<out K, V>.maxOfWithOrNull(comparator: Comparator ...@@ -308,12 +308,19 @@ public inline fun <K, V, R> Map<out K, V>.maxOfWithOrNull(comparator: Comparator
return entries.maxOfWithOrNull(comparator, selector) 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. * 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 @kotlin.internal.InlineOnly
public inline fun <K, V> Map<out K, V>.maxWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>? { public inline fun <K, V> Map<out K, V>.maxWithOrNull(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>? {
return entries.maxWith(comparator) return entries.maxWithOrNull(comparator)
} }
@Deprecated("Use minByOrNull instead.", ReplaceWith("minByOrNull(selector)")) @Deprecated("Use minByOrNull instead.", ReplaceWith("minByOrNull(selector)"))
...@@ -444,11 +451,18 @@ public inline fun <K, V, R> Map<out K, V>.minOfWithOrNull(comparator: Comparator ...@@ -444,11 +451,18 @@ public inline fun <K, V, R> Map<out K, V>.minOfWithOrNull(comparator: Comparator
return entries.minOfWithOrNull(comparator, selector) 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. * 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>? { @SinceKotlin("1.4")
return entries.minWith(comparator) @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? { ...@@ -1460,12 +1460,18 @@ public fun <T : Comparable<T>> Sequence<T>.maxOrNull(): T? {
return max 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. * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
* *
* The operation is _terminal_. * 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() val iterator = iterator()
if (!iterator.hasNext()) return null if (!iterator.hasNext()) return null
var max = iterator.next() var max = iterator.next()
...@@ -1770,12 +1776,18 @@ public fun <T : Comparable<T>> Sequence<T>.minOrNull(): T? { ...@@ -1770,12 +1776,18 @@ public fun <T : Comparable<T>> Sequence<T>.minOrNull(): T? {
return min 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. * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
* *
* The operation is _terminal_. * 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() val iterator = iterator()
if (!iterator.hasNext()) return null if (!iterator.hasNext()) return null
var min = iterator.next() var min = iterator.next()
......
...@@ -1303,10 +1303,16 @@ public fun CharSequence.maxOrNull(): Char? { ...@@ -1303,10 +1303,16 @@ public fun CharSequence.maxOrNull(): Char? {
return max 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. * 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 if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -1531,10 +1537,16 @@ public fun CharSequence.minOrNull(): Char? { ...@@ -1531,10 +1537,16 @@ public fun CharSequence.minOrNull(): Char? {
return min 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. * 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 if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
......
...@@ -6626,12 +6626,40 @@ public fun UShortArray.maxOrNull(): UShort? { ...@@ -6626,12 +6626,40 @@ public fun UShortArray.maxOrNull(): UShort? {
return max return max
} }
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UIntArray.maxWith(comparator: Comparator<in UInt>): UInt? {
return maxWithOrNull(comparator)
}
@Deprecated("Use maxWithOrNull instead.", ReplaceWith("maxWithOrNull(comparator)"))
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun ULongArray.maxWith(comparator: Comparator<in ULong>): ULong? {
return maxWithOrNull(comparator)
}
@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. * 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 @ExperimentalUnsignedTypes
public fun UIntArray.maxWith(comparator: Comparator<in UInt>): UInt? { public fun UIntArray.maxWithOrNull(comparator: Comparator<in UInt>): UInt? {
if (isEmpty()) return null if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -6644,9 +6672,9 @@ public fun UIntArray.maxWith(comparator: Comparator<in UInt>): UInt? { ...@@ -6644,9 +6672,9 @@ public fun UIntArray.maxWith(comparator: Comparator<in UInt>): UInt? {
/** /**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements. * 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 @ExperimentalUnsignedTypes
public fun ULongArray.maxWith(comparator: Comparator<in ULong>): ULong? { public fun ULongArray.maxWithOrNull(comparator: Comparator<in ULong>): ULong? {
if (isEmpty()) return null if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -6659,9 +6687,9 @@ public fun ULongArray.maxWith(comparator: Comparator<in ULong>): ULong? { ...@@ -6659,9 +6687,9 @@ public fun ULongArray.maxWith(comparator: Comparator<in ULong>): ULong? {
/** /**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements. * 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 @ExperimentalUnsignedTypes
public fun UByteArray.maxWith(comparator: Comparator<in UByte>): UByte? { public fun UByteArray.maxWithOrNull(comparator: Comparator<in UByte>): UByte? {
if (isEmpty()) return null if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -6674,9 +6702,9 @@ public fun UByteArray.maxWith(comparator: Comparator<in UByte>): UByte? { ...@@ -6674,9 +6702,9 @@ 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. * 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 @ExperimentalUnsignedTypes
public fun UShortArray.maxWith(comparator: Comparator<in UShort>): UShort? { public fun UShortArray.maxWithOrNull(comparator: Comparator<in UShort>): UShort? {
if (isEmpty()) return null if (isEmpty()) return null
var max = this[0] var max = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -7610,12 +7638,40 @@ public fun UShortArray.minOrNull(): UShort? { ...@@ -7610,12 +7638,40 @@ public fun UShortArray.minOrNull(): UShort? {
return min return min
} }
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UIntArray.minWith(comparator: Comparator<in UInt>): UInt? {
return minWithOrNull(comparator)
}
@Deprecated("Use minWithOrNull instead.", ReplaceWith("minWithOrNull(comparator)"))
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun ULongArray.minWith(comparator: Comparator<in ULong>): ULong? {
return minWithOrNull(comparator)
}
@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. * 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 @ExperimentalUnsignedTypes
public fun UIntArray.minWith(comparator: Comparator<in UInt>): UInt? { public fun UIntArray.minWithOrNull(comparator: Comparator<in UInt>): UInt? {
if (isEmpty()) return null if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -7628,9 +7684,9 @@ public fun UIntArray.minWith(comparator: Comparator<in UInt>): UInt? { ...@@ -7628,9 +7684,9 @@ public fun UIntArray.minWith(comparator: Comparator<in UInt>): UInt? {
/** /**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements. * 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 @ExperimentalUnsignedTypes
public fun ULongArray.minWith(comparator: Comparator<in ULong>): ULong? { public fun ULongArray.minWithOrNull(comparator: Comparator<in ULong>): ULong? {
if (isEmpty()) return null if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -7643,9 +7699,9 @@ public fun ULongArray.minWith(comparator: Comparator<in ULong>): ULong? { ...@@ -7643,9 +7699,9 @@ public fun ULongArray.minWith(comparator: Comparator<in ULong>): ULong? {
/** /**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements. * 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 @ExperimentalUnsignedTypes
public fun UByteArray.minWith(comparator: Comparator<in UByte>): UByte? { public fun UByteArray.minWithOrNull(comparator: Comparator<in UByte>): UByte? {
if (isEmpty()) return null if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
...@@ -7658,9 +7714,9 @@ public fun UByteArray.minWith(comparator: Comparator<in UByte>): UByte? { ...@@ -7658,9 +7714,9 @@ 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. * 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 @ExperimentalUnsignedTypes
public fun UShortArray.minWith(comparator: Comparator<in UShort>): UShort? { public fun UShortArray.minWithOrNull(comparator: Comparator<in UShort>): UShort? {
if (isEmpty()) return null if (isEmpty()) return null
var min = this[0] var min = this[0]
for (i in 1..lastIndex) { for (i in 1..lastIndex) {
......
...@@ -390,26 +390,26 @@ class ArraysTest { ...@@ -390,26 +390,26 @@ class ArraysTest {
expect('b', { charArrayOf('a', 'b').maxOrNull() }) expect('b', { charArrayOf('a', 'b').maxOrNull() })
} }
@Test fun minWith() { @Test fun minWithOrNull() {
assertEquals(null, arrayOf<Int>().minWith(naturalOrder()) ) assertEquals(null, arrayOf<Int>().minWithOrNull(naturalOrder()))
assertEquals("a", arrayOf("a", "B").minWith(STRING_CASE_INSENSITIVE_ORDER)) assertEquals("a", arrayOf("a", "B").minWithOrNull(STRING_CASE_INSENSITIVE_ORDER))
} }
@Test fun minWithInPrimitiveArrays() { @Test fun minWithOrNullInPrimitiveArrays() {
expect(null, { intArrayOf().minWith(naturalOrder()) }) expect(null, { intArrayOf().minWithOrNull(naturalOrder()) })
expect(1, { intArrayOf(1).minWith(naturalOrder()) }) expect(1, { intArrayOf(1).minWithOrNull(naturalOrder()) })
expect(4, { intArrayOf(2, 3, 4).minWith(compareBy { it % 4 }) }) expect(4, { intArrayOf(2, 3, 4).minWithOrNull(compareBy { it % 4 }) })
} }
@Test fun maxWith() { @Test fun maxWithOrNull() {
assertEquals(null, arrayOf<Int>().maxWith(naturalOrder()) ) assertEquals(null, arrayOf<Int>().maxWithOrNull(naturalOrder()))
assertEquals("B", arrayOf("a", "B").maxWith(STRING_CASE_INSENSITIVE_ORDER)) assertEquals("B", arrayOf("a", "B").maxWithOrNull(STRING_CASE_INSENSITIVE_ORDER))
} }
@Test fun maxWithInPrimitiveArrays() { @Test fun maxWithOrNullInPrimitiveArrays() {
expect(null, { intArrayOf().maxWith(naturalOrder()) }) expect(null, { intArrayOf().maxWithOrNull(naturalOrder()) })
expect(1, { intArrayOf(1).maxWith(naturalOrder()) }) expect(1, { intArrayOf(1).maxWithOrNull(naturalOrder()) })
expect(-4, { intArrayOf(2, 3, -4).maxWith(compareBy { it*it }) }) expect(-4, { intArrayOf(2, 3, -4).maxWithOrNull(compareBy { it * it }) })
} }
@Test fun minByOrNull() { @Test fun minByOrNull() {
......
...@@ -851,18 +851,18 @@ class CollectionTest { ...@@ -851,18 +851,18 @@ class CollectionTest {
assertIsPositiveZero(listOf(0.0F, -0.0F).shuffled().maxOrNull()!!.toDouble()) assertIsPositiveZero(listOf(0.0F, -0.0F).shuffled().maxOrNull()!!.toDouble())
} }
@Test fun minWith() { @Test fun minWithOrNull() {
expect(null, { listOf<Int>().minWith(naturalOrder()) }) expect(null, { listOf<Int>().minWithOrNull(naturalOrder()) })
expect(1, { listOf(1).minWith(naturalOrder()) }) expect(1, { listOf(1).minWithOrNull(naturalOrder()) })
expect("a", { listOf("a", "B").minWith(STRING_CASE_INSENSITIVE_ORDER) }) expect("a", { listOf("a", "B").minWithOrNull(STRING_CASE_INSENSITIVE_ORDER) })
expect("a", { listOf("a", "B").asSequence().minWith(STRING_CASE_INSENSITIVE_ORDER) }) expect("a", { listOf("a", "B").asSequence().minWithOrNull(STRING_CASE_INSENSITIVE_ORDER) })
} }
@Test fun maxWith() { @Test fun maxWithOrNull() {
expect(null, { listOf<Int>().maxWith(naturalOrder()) }) expect(null, { listOf<Int>().maxWithOrNull(naturalOrder()) })
expect(1, { listOf(1).maxWith(naturalOrder()) }) expect(1, { listOf(1).maxWithOrNull(naturalOrder()) })
expect("B", { listOf("a", "B").maxWith(STRING_CASE_INSENSITIVE_ORDER) }) expect("B", { listOf("a", "B").maxWithOrNull(STRING_CASE_INSENSITIVE_ORDER) })
expect("B", { listOf("a", "B").asSequence().maxWith(STRING_CASE_INSENSITIVE_ORDER) }) expect("B", { listOf("a", "B").asSequence().maxWithOrNull(STRING_CASE_INSENSITIVE_ORDER) })
} }
@Test fun minByOrNull() { @Test fun minByOrNull() {
......
...@@ -451,35 +451,35 @@ class UnsignedArraysTest { ...@@ -451,35 +451,35 @@ class UnsignedArraysTest {
} }
@Test @Test
fun minWith() { fun minWitOrNullh() {
expect(null) { arrayOf<UByte>().minWith(naturalOrder()) } expect(null) { arrayOf<UByte>().minWithOrNull(naturalOrder()) }
expect(1u) { arrayOf<UShort>(1).minWith(naturalOrder()) } expect(1u) { arrayOf<UShort>(1).minWithOrNull(naturalOrder()) }
expect(2u) { arrayOf<UInt>(2, 3).minWith(naturalOrder()) } expect(2u) { arrayOf<UInt>(2, 3).minWithOrNull(naturalOrder()) }
expect(2uL) { arrayOf<ULong>(3, 2).minWith(naturalOrder()) } expect(2uL) { arrayOf<ULong>(3, 2).minWithOrNull(naturalOrder()) }
} }
@Test @Test
fun minWithInUnsignedArrays() { fun minWithOrNullInUnsignedArrays() {
expect(null) { ubyteArrayOf().minWith(reverseOrder()) } expect(null) { ubyteArrayOf().minWithOrNull(reverseOrder()) }
expect(1u) { ushortArrayOf(1).minWith(reverseOrder()) } expect(1u) { ushortArrayOf(1).minWithOrNull(reverseOrder()) }
expect(3u) { uintArrayOf(2, 3).minWith(reverseOrder()) } expect(3u) { uintArrayOf(2, 3).minWithOrNull(reverseOrder()) }
expect(3uL) { ulongArrayOf(3, 2).minWith(reverseOrder()) } expect(3uL) { ulongArrayOf(3, 2).minWithOrNull(reverseOrder()) }
} }
@Test @Test
fun maxWith() { fun maxWithOrNull() {
expect(null) { arrayOf<UByte>().maxWith(naturalOrder()) } expect(null) { arrayOf<UByte>().maxWithOrNull(naturalOrder()) }
expect(1u) { arrayOf<UShort>(1).maxWith(naturalOrder()) } expect(1u) { arrayOf<UShort>(1).maxWithOrNull(naturalOrder()) }
expect(3u) { arrayOf<UInt>(2, 3).maxWith(naturalOrder()) } expect(3u) { arrayOf<UInt>(2, 3).maxWithOrNull(naturalOrder()) }
expect(3uL) { arrayOf<ULong>(3, 2).maxWith(naturalOrder()) } expect(3uL) { arrayOf<ULong>(3, 2).maxWithOrNull(naturalOrder()) }
} }
@Test @Test
fun maxWithInUnsignedArrays() { fun maxWithOrNullInUnsignedArrays() {
expect(null) { ubyteArrayOf().maxWith(reverseOrder()) } expect(null) { ubyteArrayOf().maxWithOrNull(reverseOrder()) }
expect(1u) { ushortArrayOf(1).maxWith(reverseOrder()) } expect(1u) { ushortArrayOf(1).maxWithOrNull(reverseOrder()) }
expect(2u) { uintArrayOf(2, 3).maxWith(reverseOrder()) } expect(2u) { uintArrayOf(2, 3).maxWithOrNull(reverseOrder()) }
expect(2uL) { ulongArrayOf(3, 2).maxWith(reverseOrder()) } expect(2uL) { ulongArrayOf(3, 2).maxWithOrNull(reverseOrder()) }
} }
@Test @Test
......
...@@ -1421,6 +1421,15 @@ public final class kotlin/collections/ArraysKt { ...@@ -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 ([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 ([SLjava/util/Comparator;)Ljava/lang/Short;
public static final fun maxWith ([ZLjava/util/Comparator;)Ljava/lang/Boolean; 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 ([B)Ljava/lang/Byte;
public static final fun min ([C)Ljava/lang/Character; public static final fun min ([C)Ljava/lang/Character;
public static final fun min ([D)Ljava/lang/Double; public static final fun min ([D)Ljava/lang/Double;
...@@ -1468,6 +1477,15 @@ public final class kotlin/collections/ArraysKt { ...@@ -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 ([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 ([SLjava/util/Comparator;)Ljava/lang/Short;
public static final fun minWith ([ZLjava/util/Comparator;)Ljava/lang/Boolean; 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 ([B)Z
public static final fun none ([BLkotlin/jvm/functions/Function1;)Z public static final fun none ([BLkotlin/jvm/functions/Function1;)Z
public static final fun none ([C)Z public static final fun none ([C)Z
...@@ -2238,6 +2256,7 @@ public final class kotlin/collections/CollectionsKt { ...@@ -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/Double;
public static final fun maxOrNull (Ljava/lang/Iterable;)Ljava/lang/Float; 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 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/Comparable;
public static final fun min (Ljava/lang/Iterable;)Ljava/lang/Double; public static final fun min (Ljava/lang/Iterable;)Ljava/lang/Double;
public static final fun min (Ljava/lang/Iterable;)Ljava/lang/Float; public static final fun min (Ljava/lang/Iterable;)Ljava/lang/Float;
...@@ -2247,6 +2266,7 @@ public final class kotlin/collections/CollectionsKt { ...@@ -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/Double;
public static final fun minOrNull (Ljava/lang/Iterable;)Ljava/lang/Float; 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 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/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;Ljava/lang/Object;)Ljava/util/List;
public static final fun minus (Ljava/lang/Iterable;Lkotlin/sequences/Sequence;)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 { ...@@ -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-YmdZ_VM ([ILjava/util/Comparator;)Lkotlin/UInt;
public static final fun maxWith-eOHTfZs ([SLjava/util/Comparator;)Lkotlin/UShort; 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 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--ajY-9A ([I)Lkotlin/UInt;
public static final fun min-GBYM_sE ([B)Lkotlin/UByte; public static final fun min-GBYM_sE ([B)Lkotlin/UByte;
public static final fun min-QwZRm1k ([J)Lkotlin/ULong; public static final fun min-QwZRm1k ([J)Lkotlin/ULong;
...@@ -2681,6 +2705,10 @@ public final class kotlin/collections/unsigned/UArraysKt { ...@@ -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-YmdZ_VM ([ILjava/util/Comparator;)Lkotlin/UInt;
public static final fun minWith-eOHTfZs ([SLjava/util/Comparator;)Lkotlin/UShort; 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 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-CFIt9YE ([ILjava/util/Collection;)[I
public static final fun plus-kzHmqpY ([JLjava/util/Collection;)[J public static final fun plus-kzHmqpY ([JLjava/util/Collection;)[J
public static final fun plus-ojwP5H8 ([SLjava/util/Collection;)[S public static final fun plus-ojwP5H8 ([SLjava/util/Collection;)[S
...@@ -4897,6 +4925,7 @@ public final class kotlin/sequences/SequencesKt { ...@@ -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/Double;
public static final fun maxOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Float; 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 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/Comparable;
public static final fun min (Lkotlin/sequences/Sequence;)Ljava/lang/Double; public static final fun min (Lkotlin/sequences/Sequence;)Ljava/lang/Double;
public static final fun min (Lkotlin/sequences/Sequence;)Ljava/lang/Float; public static final fun min (Lkotlin/sequences/Sequence;)Ljava/lang/Float;
...@@ -4906,6 +4935,7 @@ public final class kotlin/sequences/SequencesKt { ...@@ -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/Double;
public static final fun minOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Float; 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 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/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;Ljava/lang/Object;)Lkotlin/sequences/Sequence;
public static final fun minus (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;)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 { ...@@ -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 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 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 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 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 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 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 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 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;)Z
public static final fun none (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)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; public static final fun onEach (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/CharSequence;
......
...@@ -448,74 +448,56 @@ object Aggregates : TemplateGroupBase() { ...@@ -448,74 +448,56 @@ object Aggregates : TemplateGroupBase() {
yield(def(op, nullable)) yield(def(op, nullable))
} }
val f_minWith = fn("minWith(comparator: Comparator<in T>)") { val f_minMaxWith = sequence {
includeDefault() fun def(op: String, nullable: Boolean, orNull: String = "OrNull".ifOrEmpty(nullable)) =
include(Maps, CharSequences, ArraysOfUnsigned) fn("$op$orNull(comparator: Comparator<in T>)") {
} builder { includeDefault()
doc { "Returns the first ${f.element} having the smallest value according to the provided [comparator] or `null` if there are no ${f.element.pluralize()}." } include(Maps, CharSequences, ArraysOfUnsigned)
returns("T?") } builder {
body { specialFor(Maps) { if (op == "maxWith" || nullable) inlineOnly() }
""" returns("T?")
val iterator = iterator()
if (!iterator.hasNext()) return null
var min = iterator.next() if (!nullable) {
while (iterator.hasNext()) { deprecate(Deprecation("Use ${op}OrNull instead.", "${op}OrNull(comparator)", DeprecationLevel.WARNING))
val e = iterator.next() body { "return ${op}OrNull(comparator)" }
if (comparator.compare(min, e) > 0) min = e return@builder
} }
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>)") { since("1.4")
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() 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()}." }
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] val (acc, cmp) = if (op == "minWith") Pair("min", ">") else Pair("max", "<")
for (i in 1..lastIndex) { body {
val e = this[i] """
if (comparator.compare(max, e) < 0) max = e 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 max
""" for (op in listOf("minWith", "maxWith"))
} for (nullable in listOf(false, true))
specialFor(Maps) { yield(def(op, nullable))
inlineOnly()
body { "return entries.maxWith(comparator)" }
}
} }
fun f_minMaxOf() = sequence { fun f_minMaxOf() = sequence {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册