Introduce minOrNull and maxOrNull extension functions #KT-39064

This commit is contained in:
Abduqodiri Qurbonzoda
2020-05-20 04:56:52 +03:00
parent a8cd8ad8f8
commit 846a7823ad
14 changed files with 928 additions and 612 deletions
+336 -216
View File
@@ -13057,144 +13057,56 @@ public inline fun CharArray.forEachIndexed(action: (index: Int, Char) -> Unit):
for (item in this) action(index++, item)
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
@SinceKotlin("1.1")
public fun Array<out Double>.max(): Double? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
max = maxOf(max, e)
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
@SinceKotlin("1.1")
public fun Array<out Float>.max(): Float? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
max = maxOf(max, e)
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
public fun <T : Comparable<T>> Array<out T>.max(): T? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
public fun ByteArray.max(): Byte? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
public fun ShortArray.max(): Short? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
public fun IntArray.max(): Int? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
public fun LongArray.max(): Long? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
public fun FloatArray.max(): Float? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
max = maxOf(max, e)
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
public fun DoubleArray.max(): Double? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
max = maxOf(max, e)
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
public fun CharArray.max(): Char? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
return maxOrNull()
}
/**
@@ -14907,6 +14819,154 @@ public inline fun <R> CharArray.maxOfWithOrNull(comparator: Comparator<in R>, se
return maxValue
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.4")
public fun Array<out Double>.maxOrNull(): Double? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
max = maxOf(max, e)
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.4")
public fun Array<out Float>.maxOrNull(): Float? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
max = maxOf(max, e)
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun <T : Comparable<T>> Array<out T>.maxOrNull(): T? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun ByteArray.maxOrNull(): Byte? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun ShortArray.maxOrNull(): Short? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun IntArray.maxOrNull(): Int? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun LongArray.maxOrNull(): Long? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.4")
public fun FloatArray.maxOrNull(): Float? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
max = maxOf(max, e)
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.4")
public fun DoubleArray.maxOrNull(): Double? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
max = maxOf(max, e)
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun CharArray.maxOrNull(): Char? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
}
/**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*/
@@ -15024,144 +15084,56 @@ public fun CharArray.maxWith(comparator: Comparator<in Char>): Char? {
return max
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
@SinceKotlin("1.1")
public fun Array<out Double>.min(): Double? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
min = minOf(min, e)
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
@SinceKotlin("1.1")
public fun Array<out Float>.min(): Float? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
min = minOf(min, e)
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
public fun <T : Comparable<T>> Array<out T>.min(): T? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
public fun ByteArray.min(): Byte? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
public fun ShortArray.min(): Short? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
public fun IntArray.min(): Int? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
public fun LongArray.min(): Long? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
public fun FloatArray.min(): Float? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
min = minOf(min, e)
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
public fun DoubleArray.min(): Double? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
min = minOf(min, e)
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
public fun CharArray.min(): Char? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
return minOrNull()
}
/**
@@ -16874,6 +16846,154 @@ public inline fun <R> CharArray.minOfWithOrNull(comparator: Comparator<in R>, se
return minValue
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.4")
public fun Array<out Double>.minOrNull(): Double? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
min = minOf(min, e)
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.4")
public fun Array<out Float>.minOrNull(): Float? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
min = minOf(min, e)
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun <T : Comparable<T>> Array<out T>.minOrNull(): T? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun ByteArray.minOrNull(): Byte? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun ShortArray.minOrNull(): Short? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun IntArray.minOrNull(): Int? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun LongArray.minOrNull(): Long? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.4")
public fun FloatArray.minOrNull(): Float? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
min = minOf(min, e)
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.4")
public fun DoubleArray.minOrNull(): Double? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
min = minOf(min, e)
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun CharArray.minOrNull(): Char? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
}
/**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/
@@ -1719,52 +1719,21 @@ public inline fun <T> Iterable<T>.forEachIndexed(action: (index: Int, T) -> Unit
for (item in this) action(checkIndexOverflow(index++), item)
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
@SinceKotlin("1.1")
public fun Iterable<Double>.max(): Double? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
max = maxOf(max, e)
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
@SinceKotlin("1.1")
public fun Iterable<Float>.max(): Float? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
max = maxOf(max, e)
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
public fun <T : Comparable<T>> Iterable<T>.max(): T? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
if (max < e) max = e
}
return max
return maxOrNull()
}
/**
@@ -1965,6 +1934,55 @@ public inline fun <T, R> Iterable<T>.maxOfWithOrNull(comparator: Comparator<in R
return maxValue
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.4")
public fun Iterable<Double>.maxOrNull(): Double? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
max = maxOf(max, e)
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.4")
public fun Iterable<Float>.maxOrNull(): Float? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
max = maxOf(max, e)
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun <T : Comparable<T>> Iterable<T>.maxOrNull(): T? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
if (max < e) max = e
}
return max
}
/**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*/
@@ -1979,52 +1997,21 @@ public fun <T> Iterable<T>.maxWith(comparator: Comparator<in T>): T? {
return max
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
@SinceKotlin("1.1")
public fun Iterable<Double>.min(): Double? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
min = minOf(min, e)
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
@SinceKotlin("1.1")
public fun Iterable<Float>.min(): Float? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
min = minOf(min, e)
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
public fun <T : Comparable<T>> Iterable<T>.min(): T? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
if (min > e) min = e
}
return min
return minOrNull()
}
/**
@@ -2225,6 +2212,55 @@ public inline fun <T, R> Iterable<T>.minOfWithOrNull(comparator: Comparator<in R
return minValue
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.4")
public fun Iterable<Double>.minOrNull(): Double? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
min = minOf(min, e)
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.4")
public fun Iterable<Float>.minOrNull(): Float? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
min = minOf(min, e)
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
public fun <T : Comparable<T>> Iterable<T>.minOrNull(): T? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
if (min > e) min = e
}
return min
}
/**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/
@@ -1166,58 +1166,21 @@ public inline fun <T> Sequence<T>.forEachIndexed(action: (index: Int, T) -> Unit
for (item in this) action(checkIndexOverflow(index++), item)
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
@SinceKotlin("1.1")
public fun Sequence<Double>.max(): Double? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
max = maxOf(max, e)
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
@SinceKotlin("1.1")
public fun Sequence<Float>.max(): Float? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
max = maxOf(max, e)
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*
* The operation is _terminal_.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
public fun <T : Comparable<T>> Sequence<T>.max(): T? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
if (max < e) max = e
}
return max
return maxOrNull()
}
/**
@@ -1436,6 +1399,61 @@ public inline fun <T, R> Sequence<T>.maxOfWithOrNull(comparator: Comparator<in R
return maxValue
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
public fun Sequence<Double>.maxOrNull(): Double? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
max = maxOf(max, e)
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
public fun Sequence<Float>.maxOrNull(): Float? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
max = maxOf(max, e)
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
public fun <T : Comparable<T>> Sequence<T>.maxOrNull(): T? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
if (max < e) max = e
}
return max
}
/**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*
@@ -1452,58 +1470,21 @@ public fun <T> Sequence<T>.maxWith(comparator: Comparator<in T>): T? {
return max
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
@SinceKotlin("1.1")
public fun Sequence<Double>.min(): Double? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
min = minOf(min, e)
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
@SinceKotlin("1.1")
public fun Sequence<Float>.min(): Float? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
min = minOf(min, e)
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* The operation is _terminal_.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
public fun <T : Comparable<T>> Sequence<T>.min(): T? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
if (min > e) min = e
}
return min
return minOrNull()
}
/**
@@ -1722,6 +1703,61 @@ public inline fun <T, R> Sequence<T>.minOfWithOrNull(comparator: Comparator<in R
return minValue
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
public fun Sequence<Double>.minOrNull(): Double? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
min = minOf(min, e)
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
public fun Sequence<Float>.minOrNull(): Float? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
min = minOf(min, e)
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
public fun <T : Comparable<T>> Sequence<T>.minOrNull(): T? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
if (min > e) min = e
}
return min
}
/**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*
@@ -1088,17 +1088,9 @@ public inline fun CharSequence.forEachIndexed(action: (index: Int, Char) -> Unit
for (item in this) action(index++, item)
}
/**
* Returns the largest character or `null` if there are no characters.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
public fun CharSequence.max(): Char? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
return maxOrNull()
}
/**
@@ -1291,6 +1283,20 @@ public inline fun <R> CharSequence.maxOfWithOrNull(comparator: Comparator<in R>,
return maxValue
}
/**
* Returns the largest character or `null` if there are no characters.
*/
@SinceKotlin("1.4")
public fun CharSequence.maxOrNull(): Char? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
}
/**
* Returns the first character having the largest value according to the provided [comparator] or `null` if there are no characters.
*/
@@ -1304,17 +1310,9 @@ public fun CharSequence.maxWith(comparator: Comparator<in Char>): Char? {
return max
}
/**
* Returns the smallest character or `null` if there are no characters.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
public fun CharSequence.min(): Char? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
return minOrNull()
}
/**
@@ -1507,6 +1505,20 @@ public inline fun <R> CharSequence.minOfWithOrNull(comparator: Comparator<in R>,
return minValue
}
/**
* Returns the smallest character or `null` if there are no characters.
*/
@SinceKotlin("1.4")
public fun CharSequence.minOrNull(): Char? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
}
/**
* Returns the first character having the smallest value according to the provided [comparator] or `null` if there are no characters.
*/
+136 -80
View File
@@ -5702,64 +5702,32 @@ public inline fun UShortArray.forEachIndexed(action: (index: Int, UShort) -> Uni
for (item in this) action(index++, item)
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UIntArray.max(): UInt? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun ULongArray.max(): ULong? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UByteArray.max(): UByte? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
return maxOrNull()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UShortArray.max(): UShort? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
return maxOrNull()
}
/**
@@ -6566,6 +6534,66 @@ public inline fun <R> UShortArray.maxOfWithOrNull(comparator: Comparator<in R>,
return maxValue
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun UIntArray.maxOrNull(): UInt? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun ULongArray.maxOrNull(): ULong? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun UByteArray.maxOrNull(): UByte? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun UShortArray.maxOrNull(): UShort? {
if (isEmpty()) return null
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
}
/**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*/
@@ -6626,64 +6654,32 @@ public fun UShortArray.maxWith(comparator: Comparator<in UShort>): UShort? {
return max
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UIntArray.min(): UInt? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun ULongArray.min(): ULong? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UByteArray.min(): UByte? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
return minOrNull()
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UShortArray.min(): UShort? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
return minOrNull()
}
/**
@@ -7490,6 +7486,66 @@ public inline fun <R> UShortArray.minOfWithOrNull(comparator: Comparator<in R>,
return minValue
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun UIntArray.minOrNull(): UInt? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun ULongArray.minOrNull(): ULong? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun UByteArray.minOrNull(): UByte? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.4")
@ExperimentalUnsignedTypes
public fun UShortArray.minOrNull(): UShort? {
if (isEmpty()) return null
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
}
/**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/