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) for (item in this) action(index++, item)
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.1") @SinceKotlin("1.1")
public fun Array<out Double>.max(): Double? { public fun Array<out Double>.max(): Double? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
max = maxOf(max, e)
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.1") @SinceKotlin("1.1")
public fun Array<out Float>.max(): Float? { public fun Array<out Float>.max(): Float? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
max = maxOf(max, e)
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*/
public fun <T : Comparable<T>> Array<out T>.max(): T? { public fun <T : Comparable<T>> Array<out T>.max(): T? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*/
public fun ByteArray.max(): Byte? { public fun ByteArray.max(): Byte? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*/
public fun ShortArray.max(): Short? { public fun ShortArray.max(): Short? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*/
public fun IntArray.max(): Int? { public fun IntArray.max(): Int? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*/
public fun LongArray.max(): Long? { public fun LongArray.max(): Long? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
public fun FloatArray.max(): Float? { public fun FloatArray.max(): Float? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
max = maxOf(max, e)
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
public fun DoubleArray.max(): Double? { public fun DoubleArray.max(): Double? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
max = maxOf(max, e)
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*/
public fun CharArray.max(): Char? { public fun CharArray.max(): Char? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
} }
/** /**
@@ -14907,6 +14819,154 @@ public inline fun <R> CharArray.maxOfWithOrNull(comparator: Comparator<in R>, se
return maxValue 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. * 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 return max
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.1") @SinceKotlin("1.1")
public fun Array<out Double>.min(): Double? { public fun Array<out Double>.min(): Double? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
min = minOf(min, e)
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.1") @SinceKotlin("1.1")
public fun Array<out Float>.min(): Float? { public fun Array<out Float>.min(): Float? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
min = minOf(min, e)
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*/
public fun <T : Comparable<T>> Array<out T>.min(): T? { public fun <T : Comparable<T>> Array<out T>.min(): T? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*/
public fun ByteArray.min(): Byte? { public fun ByteArray.min(): Byte? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*/
public fun ShortArray.min(): Short? { public fun ShortArray.min(): Short? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*/
public fun IntArray.min(): Int? { public fun IntArray.min(): Int? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*/
public fun LongArray.min(): Long? { public fun LongArray.min(): Long? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
public fun FloatArray.min(): Float? { public fun FloatArray.min(): Float? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
min = minOf(min, e)
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
public fun DoubleArray.min(): Double? { public fun DoubleArray.min(): Double? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
min = minOf(min, e)
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*/
public fun CharArray.min(): Char? { public fun CharArray.min(): Char? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
} }
/** /**
@@ -16874,6 +16846,154 @@ public inline fun <R> CharArray.minOfWithOrNull(comparator: Comparator<in R>, se
return minValue 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. * 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) for (item in this) action(checkIndexOverflow(index++), item)
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.1") @SinceKotlin("1.1")
public fun Iterable<Double>.max(): Double? { public fun Iterable<Double>.max(): Double? {
val iterator = iterator() return maxOrNull()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
max = maxOf(max, e)
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.1") @SinceKotlin("1.1")
public fun Iterable<Float>.max(): Float? { public fun Iterable<Float>.max(): Float? {
val iterator = iterator() return maxOrNull()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
max = maxOf(max, e)
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*/
public fun <T : Comparable<T>> Iterable<T>.max(): T? { public fun <T : Comparable<T>> Iterable<T>.max(): T? {
val iterator = iterator() return maxOrNull()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
if (max < e) max = e
}
return max
} }
/** /**
@@ -1965,6 +1934,55 @@ public inline fun <T, R> Iterable<T>.maxOfWithOrNull(comparator: Comparator<in R
return maxValue 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. * 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 return max
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.1") @SinceKotlin("1.1")
public fun Iterable<Double>.min(): Double? { public fun Iterable<Double>.min(): Double? {
val iterator = iterator() return minOrNull()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
min = minOf(min, e)
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin("1.1") @SinceKotlin("1.1")
public fun Iterable<Float>.min(): Float? { public fun Iterable<Float>.min(): Float? {
val iterator = iterator() return minOrNull()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
min = minOf(min, e)
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*/
public fun <T : Comparable<T>> Iterable<T>.min(): T? { public fun <T : Comparable<T>> Iterable<T>.min(): T? {
val iterator = iterator() return minOrNull()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
if (min > e) min = e
}
return min
} }
/** /**
@@ -2225,6 +2212,55 @@ public inline fun <T, R> Iterable<T>.minOfWithOrNull(comparator: Comparator<in R
return minValue 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. * 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) for (item in this) action(checkIndexOverflow(index++), item)
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* 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.1") @SinceKotlin("1.1")
public fun Sequence<Double>.max(): Double? { public fun Sequence<Double>.max(): Double? {
val iterator = iterator() return maxOrNull()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
max = maxOf(max, e)
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* 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.1") @SinceKotlin("1.1")
public fun Sequence<Float>.max(): Float? { public fun Sequence<Float>.max(): Float? {
val iterator = iterator() return maxOrNull()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
max = maxOf(max, e)
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*
* The operation is _terminal_.
*/
public fun <T : Comparable<T>> Sequence<T>.max(): T? { public fun <T : Comparable<T>> Sequence<T>.max(): T? {
val iterator = iterator() return maxOrNull()
if (!iterator.hasNext()) return null
var max = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
if (max < e) max = e
}
return max
} }
/** /**
@@ -1436,6 +1399,61 @@ public inline fun <T, R> Sequence<T>.maxOfWithOrNull(comparator: Comparator<in R
return maxValue 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. * 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 return max
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* 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.1") @SinceKotlin("1.1")
public fun Sequence<Double>.min(): Double? { public fun Sequence<Double>.min(): Double? {
val iterator = iterator() return minOrNull()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
min = minOf(min, e)
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* 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.1") @SinceKotlin("1.1")
public fun Sequence<Float>.min(): Float? { public fun Sequence<Float>.min(): Float? {
val iterator = iterator() return minOrNull()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
min = minOf(min, e)
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*
* The operation is _terminal_.
*/
public fun <T : Comparable<T>> Sequence<T>.min(): T? { public fun <T : Comparable<T>> Sequence<T>.min(): T? {
val iterator = iterator() return minOrNull()
if (!iterator.hasNext()) return null
var min = iterator.next()
while (iterator.hasNext()) {
val e = iterator.next()
if (min > e) min = e
}
return min
} }
/** /**
@@ -1722,6 +1703,61 @@ public inline fun <T, R> Sequence<T>.minOfWithOrNull(comparator: Comparator<in R
return minValue 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. * 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) for (item in this) action(index++, item)
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest character or `null` if there are no characters.
*/
public fun CharSequence.max(): Char? { public fun CharSequence.max(): Char? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
} }
/** /**
@@ -1291,6 +1283,20 @@ public inline fun <R> CharSequence.maxOfWithOrNull(comparator: Comparator<in R>,
return maxValue 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. * 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 return max
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest character or `null` if there are no characters.
*/
public fun CharSequence.min(): Char? { public fun CharSequence.min(): Char? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
} }
/** /**
@@ -1507,6 +1505,20 @@ public inline fun <R> CharSequence.minOfWithOrNull(comparator: Comparator<in R>,
return minValue 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. * 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) for (item in this) action(index++, item)
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.3") @SinceKotlin("1.3")
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
public fun UIntArray.max(): UInt? { public fun UIntArray.max(): UInt? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.3") @SinceKotlin("1.3")
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
public fun ULongArray.max(): ULong? { public fun ULongArray.max(): ULong? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.3") @SinceKotlin("1.3")
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
public fun UByteArray.max(): UByte? { public fun UByteArray.max(): UByte? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
} }
/** @Deprecated("Use maxOrNull instead.", ReplaceWith("maxOrNull()"))
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.3") @SinceKotlin("1.3")
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
public fun UShortArray.max(): UShort? { public fun UShortArray.max(): UShort? {
if (isEmpty()) return null return maxOrNull()
var max = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (max < e) max = e
}
return max
} }
/** /**
@@ -6566,6 +6534,66 @@ public inline fun <R> UShortArray.maxOfWithOrNull(comparator: Comparator<in R>,
return maxValue 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. * 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 return max
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.3") @SinceKotlin("1.3")
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
public fun UIntArray.min(): UInt? { public fun UIntArray.min(): UInt? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.3") @SinceKotlin("1.3")
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
public fun ULongArray.min(): ULong? { public fun ULongArray.min(): ULong? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.3") @SinceKotlin("1.3")
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
public fun UByteArray.min(): UByte? { public fun UByteArray.min(): UByte? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
} }
/** @Deprecated("Use minOrNull instead.", ReplaceWith("minOrNull()"))
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.3") @SinceKotlin("1.3")
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
public fun UShortArray.min(): UShort? { public fun UShortArray.min(): UShort? {
if (isEmpty()) return null return minOrNull()
var min = this[0]
for (i in 1..lastIndex) {
val e = this[i]
if (min > e) min = e
}
return min
} }
/** /**
@@ -7490,6 +7486,66 @@ public inline fun <R> UShortArray.minOfWithOrNull(comparator: Comparator<in R>,
return minValue 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. * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/ */
+1 -1
View File
@@ -71,7 +71,7 @@ public fun String.replaceIndent(newIndent: String = ""): String {
val minCommonIndent = lines val minCommonIndent = lines
.filter(String::isNotBlank) .filter(String::isNotBlank)
.map(String::indentWidth) .map(String::indentWidth)
.min() ?: 0 .minOrNull() ?: 0
return lines.reindent(length + newIndent.length * lines.size, getIndentFunction(newIndent), { line -> line.drop(minCommonIndent) }) return lines.reindent(length + newIndent.length * lines.size, getIndentFunction(newIndent), { line -> line.drop(minCommonIndent) })
} }
+34 -34
View File
@@ -348,46 +348,46 @@ class ArraysTest {
@Test fun min() { @Test fun minOrNull() {
expect(null, { arrayOf<Int>().min() }) expect(null, { arrayOf<Int>().minOrNull() })
expect(1, { arrayOf(1).min() }) expect(1, { arrayOf(1).minOrNull() })
expect(2, { arrayOf(2, 3).min() }) expect(2, { arrayOf(2, 3).minOrNull() })
expect(2000000000000, { arrayOf(3000000000000, 2000000000000).min() }) expect(2000000000000, { arrayOf(3000000000000, 2000000000000).minOrNull() })
expect('a', { arrayOf('a', 'b').min() }) expect('a', { arrayOf('a', 'b').minOrNull() })
expect("a", { arrayOf("a", "b").min() }) expect("a", { arrayOf("a", "b").minOrNull() })
} }
@Test fun minInPrimitiveArrays() { @Test fun minOrNullInPrimitiveArrays() {
expect(null, { intArrayOf().min() }) expect(null, { intArrayOf().minOrNull() })
expect(1, { intArrayOf(1).min() }) expect(1, { intArrayOf(1).minOrNull() })
expect(2, { intArrayOf(2, 3).min() }) expect(2, { intArrayOf(2, 3).minOrNull() })
expect(2000000000000, { longArrayOf(3000000000000, 2000000000000).min() }) expect(2000000000000, { longArrayOf(3000000000000, 2000000000000).minOrNull() })
expect(1, { byteArrayOf(1, 3, 2).min() }) expect(1, { byteArrayOf(1, 3, 2).minOrNull() })
expect(2, { shortArrayOf(3, 2).min() }) expect(2, { shortArrayOf(3, 2).minOrNull() })
expect(2.0F, { floatArrayOf(3.0F, 2.0F).min() }) expect(2.0F, { floatArrayOf(3.0F, 2.0F).minOrNull() })
expect(2.0, { doubleArrayOf(2.0, 3.0).min() }) expect(2.0, { doubleArrayOf(2.0, 3.0).minOrNull() })
expect('a', { charArrayOf('a', 'b').min() }) expect('a', { charArrayOf('a', 'b').minOrNull() })
} }
@Test fun max() { @Test fun maxOrNull() {
expect(null, { arrayOf<Int>().max() }) expect(null, { arrayOf<Int>().maxOrNull() })
expect(1, { arrayOf(1).max() }) expect(1, { arrayOf(1).maxOrNull() })
expect(3, { arrayOf(2, 3).max() }) expect(3, { arrayOf(2, 3).maxOrNull() })
expect(3000000000000, { arrayOf(3000000000000, 2000000000000).max() }) expect(3000000000000, { arrayOf(3000000000000, 2000000000000).maxOrNull() })
expect('b', { arrayOf('a', 'b').max() }) expect('b', { arrayOf('a', 'b').maxOrNull() })
expect("b", { arrayOf("a", "b").max() }) expect("b", { arrayOf("a", "b").maxOrNull() })
} }
@Test fun maxInPrimitiveArrays() { @Test fun maxOrNullInPrimitiveArrays() {
expect(null, { intArrayOf().max() }) expect(null, { intArrayOf().maxOrNull() })
expect(1, { intArrayOf(1).max() }) expect(1, { intArrayOf(1).maxOrNull() })
expect(3, { intArrayOf(2, 3).max() }) expect(3, { intArrayOf(2, 3).maxOrNull() })
expect(3000000000000, { longArrayOf(3000000000000, 2000000000000).max() }) expect(3000000000000, { longArrayOf(3000000000000, 2000000000000).maxOrNull() })
expect(3, { byteArrayOf(1, 3, 2).max() }) expect(3, { byteArrayOf(1, 3, 2).maxOrNull() })
expect(3, { shortArrayOf(3, 2).max() }) expect(3, { shortArrayOf(3, 2).maxOrNull() })
expect(3.0F, { floatArrayOf(3.0F, 2.0F).max() }) expect(3.0F, { floatArrayOf(3.0F, 2.0F).maxOrNull() })
expect(3.0, { doubleArrayOf(2.0, 3.0).max() }) expect(3.0, { doubleArrayOf(2.0, 3.0).maxOrNull() })
expect('b', { charArrayOf('a', 'b').max() }) expect('b', { charArrayOf('a', 'b').maxOrNull() })
} }
@Test fun minWith() { @Test fun minWith() {
@@ -823,32 +823,32 @@ class CollectionTest {
assertTrue(hashSetOf(45, 14, 13).toIterable().contains(14)) assertTrue(hashSetOf(45, 14, 13).toIterable().contains(14))
} }
@Test fun min() { @Test fun minOrNull() {
expect(null, { listOf<Int>().min() }) expect(null, { listOf<Int>().minOrNull() })
expect(1, { listOf(1).min() }) expect(1, { listOf(1).minOrNull() })
expect(2, { listOf(2, 3).min() }) expect(2, { listOf(2, 3).minOrNull() })
expect(2000000000000, { listOf(3000000000000, 2000000000000).min() }) expect(2000000000000, { listOf(3000000000000, 2000000000000).minOrNull() })
expect('a', { listOf('a', 'b').min() }) expect('a', { listOf('a', 'b').minOrNull() })
expect("a", { listOf("a", "b").min() }) expect("a", { listOf("a", "b").minOrNull() })
expect(null, { listOf<Int>().asSequence().min() }) expect(null, { listOf<Int>().asSequence().minOrNull() })
expect(2, { listOf(2, 3).asSequence().min() }) expect(2, { listOf(2, 3).asSequence().minOrNull() })
assertIsNegativeZero(listOf(0.0, -0.0).shuffled().min()!!) assertIsNegativeZero(listOf(0.0, -0.0).shuffled().minOrNull()!!)
assertIsNegativeZero(listOf(0.0F, -0.0F).shuffled().min()!!.toDouble()) assertIsNegativeZero(listOf(0.0F, -0.0F).shuffled().minOrNull()!!.toDouble())
} }
@Test fun max() { @Test fun max() {
expect(null, { listOf<Int>().max() }) expect(null, { listOf<Int>().maxOrNull() })
expect(1, { listOf(1).max() }) expect(1, { listOf(1).maxOrNull() })
expect(3, { listOf(2, 3).max() }) expect(3, { listOf(2, 3).maxOrNull() })
expect(3000000000000, { listOf(3000000000000, 2000000000000).max() }) expect(3000000000000, { listOf(3000000000000, 2000000000000).maxOrNull() })
expect('b', { listOf('a', 'b').max() }) expect('b', { listOf('a', 'b').maxOrNull() })
expect("b", { listOf("a", "b").max() }) expect("b", { listOf("a", "b").maxOrNull() })
expect(null, { listOf<Int>().asSequence().max() }) expect(null, { listOf<Int>().asSequence().maxOrNull() })
expect(3, { listOf(2, 3).asSequence().max() }) expect(3, { listOf(2, 3).asSequence().maxOrNull() })
assertIsPositiveZero(listOf(0.0, -0.0).shuffled().max()!!) assertIsPositiveZero(listOf(0.0, -0.0).shuffled().maxOrNull()!!)
assertIsPositiveZero(listOf(0.0F, -0.0F).shuffled().max()!!.toDouble()) assertIsPositiveZero(listOf(0.0F, -0.0F).shuffled().maxOrNull()!!.toDouble())
} }
@Test fun minWith() { @Test fun minWith() {
@@ -394,14 +394,14 @@ abstract class IterableTests<T : Iterable<String>>(val createFrom: (Array<out St
} }
@Test @Test
fun max() { fun maxOrNull() {
expect("foo") { data.max() } expect("foo") { data.maxOrNull() }
expect("bar") { data.maxBy { it.last() } } expect("bar") { data.maxBy { it.last() } }
} }
@Test @Test
fun min() { fun minOrNull() {
expect("bar") { data.min() } expect("bar") { data.minOrNull() }
expect("foo") { data.minBy { it.last() } } expect("foo") { data.minBy { it.last() } }
} }
@@ -419,35 +419,35 @@ class UnsignedArraysTest {
} }
@Test @Test
fun min() { fun minOrNull() {
expect(null) { arrayOf<UByte>().min() } expect(null) { arrayOf<UByte>().minOrNull() }
expect(1u) { arrayOf<UShort>(1).min() } expect(1u) { arrayOf<UShort>(1).minOrNull() }
expect(2u) { arrayOf<UInt>(2, 3).min() } expect(2u) { arrayOf<UInt>(2, 3).minOrNull() }
expect(2uL) { arrayOf<ULong>(3, 2).min() } expect(2uL) { arrayOf<ULong>(3, 2).minOrNull() }
} }
@Test @Test
fun minInUnsignedArrays() { fun minOrNullInUnsignedArrays() {
expect(null) { ubyteArrayOf().min() } expect(null) { ubyteArrayOf().minOrNull() }
expect(1u) { ushortArrayOf(1).min() } expect(1u) { ushortArrayOf(1).minOrNull() }
expect(2u) { uintArrayOf(2, 3).min() } expect(2u) { uintArrayOf(2, 3).minOrNull() }
expect(2uL) { ulongArrayOf(3, 2).min() } expect(2uL) { ulongArrayOf(3, 2).minOrNull() }
} }
@Test @Test
fun max() { fun maxOrNull() {
expect(null) { arrayOf<UByte>().max() } expect(null) { arrayOf<UByte>().maxOrNull() }
expect(1u) { arrayOf<UShort>(1).max() } expect(1u) { arrayOf<UShort>(1).maxOrNull() }
expect(3u) { arrayOf<UInt>(2, 3).max() } expect(3u) { arrayOf<UInt>(2, 3).maxOrNull() }
expect(3uL) { arrayOf<ULong>(3, 2).max() } expect(3uL) { arrayOf<ULong>(3, 2).maxOrNull() }
} }
@Test @Test
fun maxInUnsignedArrays() { fun maxOrNullInUnsignedArrays() {
expect(null) { ubyteArrayOf().max() } expect(null) { ubyteArrayOf().maxOrNull() }
expect(1u) { ushortArrayOf(1).max() } expect(1u) { ushortArrayOf(1).maxOrNull() }
expect(3u) { uintArrayOf(2, 3).max() } expect(3u) { uintArrayOf(2, 3).maxOrNull() }
expect(3uL) { ulongArrayOf(3, 2).max() } expect(3uL) { ulongArrayOf(3, 2).maxOrNull() }
} }
@Test @Test
@@ -83,20 +83,20 @@ class NaNPropagationTest {
} }
@Test @Test
fun arrayMin() { fun arrayMinOrNull() {
propagateOf2( propagateOf2(
{ a, b -> arrayOf(a, b).min()!! }, { a, b -> arrayOf(a, b).minOrNull()!! },
{ a, b -> arrayOf(a, b).min()!! }, { a, b -> arrayOf(a, b).minOrNull()!! },
"arrayOf().min()" "arrayOf().minOrNull()"
) )
} }
@Test @Test
fun arrayMax() { fun arrayMaxOrNull() {
propagateOf2( propagateOf2(
{ a, b -> arrayOf(a, b).max()!! }, { a, b -> arrayOf(a, b).maxOrNull()!! },
{ a, b -> arrayOf(a, b).max()!! }, { a, b -> arrayOf(a, b).maxOrNull()!! },
"arrayOf().max()" "arrayOf().maxOrNull()"
) )
} }
@@ -119,20 +119,20 @@ class NaNPropagationTest {
} }
@Test @Test
fun primitiveArrayMin() { fun primitiveArrayMinOrNull() {
propagateOf2( propagateOf2(
{ a, b -> doubleArrayOf(a, b).min()!! }, { a, b -> doubleArrayOf(a, b).minOrNull()!! },
{ a, b -> floatArrayOf(a, b).min()!! }, { a, b -> floatArrayOf(a, b).minOrNull()!! },
"primitiveArrayOf().min()" "primitiveArrayOf().minOrNull()"
) )
} }
@Test @Test
fun primitiveArrayMax() { fun primitiveArrayMax() {
propagateOf2( propagateOf2(
{ a, b -> doubleArrayOf(a, b).max()!! }, { a, b -> doubleArrayOf(a, b).minOrNull()!! },
{ a, b -> floatArrayOf(a, b).max()!! }, { a, b -> floatArrayOf(a, b).minOrNull()!! },
"primitiveArrayOf().max()" "primitiveArrayOf().maxOrNull()"
) )
} }
@@ -165,20 +165,20 @@ class NaNPropagationTest {
} }
@Test @Test
fun listMin() { fun listMinOrNull() {
propagateOf2( propagateOf2(
{ a, b -> listOf(a, b).min()!! }, { a, b -> listOf(a, b).minOrNull()!! },
{ a, b -> listOf(a, b).min()!! }, { a, b -> listOf(a, b).minOrNull()!! },
"listOf().min()" "listOf().minOrNull()"
) )
} }
@Test @Test
fun listMax() { fun listMaxOrNull() {
propagateOf2( propagateOf2(
{ a, b -> listOf(a, b).max()!! }, { a, b -> listOf(a, b).maxOrNull()!! },
{ a, b -> listOf(a, b).max()!! }, { a, b -> listOf(a, b).maxOrNull()!! },
"listOf().max()" "listOf().maxOrNull()"
) )
} }
@@ -201,20 +201,20 @@ class NaNPropagationTest {
} }
@Test @Test
fun sequenceMin() { fun sequenceMinOrNull() {
propagateOf2( propagateOf2(
{ a, b -> sequenceOf(a, b).min()!! }, { a, b -> sequenceOf(a, b).minOrNull()!! },
{ a, b -> sequenceOf(a, b).min()!! }, { a, b -> sequenceOf(a, b).minOrNull()!! },
"sequenceOf().min()" "sequenceOf().minOrNull()"
) )
} }
@Test @Test
fun sequenceMax() { fun sequenceMaxOrNull() {
propagateOf2( propagateOf2(
{ a, b -> sequenceOf(a, b).max()!! }, { a, b -> sequenceOf(a, b).maxOrNull()!! },
{ a, b -> sequenceOf(a, b).max()!! }, { a, b -> sequenceOf(a, b).maxOrNull()!! },
"sequenceOf().max()" "sequenceOf().maxOrNull()"
) )
} }
@@ -266,34 +266,34 @@ class NaNTotalOrderTest {
} }
@Test @Test
fun arrayTMin() { fun arrayTMinOrNull() {
totalOrderMinOf2<Comparable<Any>>({ a, b -> arrayOf(a, b).min()!! }, "arrayOf().min()") totalOrderMinOf2<Comparable<Any>>({ a, b -> arrayOf(a, b).minOrNull()!! }, "arrayOf().minOrNull()")
} }
@Test @Test
fun arrayTMax() { fun arrayTMaxOrNull() {
totalOrderMaxOf2<Comparable<Any>>({ a, b -> arrayOf(a, b).max()!! }, "arrayOf().max()") totalOrderMaxOf2<Comparable<Any>>({ a, b -> arrayOf(a, b).maxOrNull()!! }, "arrayOf().maxOrNull()")
} }
@Test @Test
fun listTMin() { fun listTMinOrNull() {
totalOrderMinOf2<Comparable<Any>>({ a, b -> listOf(a, b).min()!! }, "listOf().min()") totalOrderMinOf2<Comparable<Any>>({ a, b -> listOf(a, b).minOrNull()!! }, "listOf().minOrNull()")
} }
@Test @Test
fun listTMax() { fun listTMaxOrNull() {
totalOrderMaxOf2<Comparable<Any>>({ a, b -> listOf(a, b).max()!! }, "listOf().max()") totalOrderMaxOf2<Comparable<Any>>({ a, b -> listOf(a, b).maxOrNull()!! }, "listOf().maxOrNull()")
} }
@Test @Test
fun sequenceTMin() { fun sequenceTMinOrNull() {
totalOrderMinOf2<Comparable<Any>>({ a, b -> sequenceOf(a, b).min()!! }, "sequenceOf().min()") totalOrderMinOf2<Comparable<Any>>({ a, b -> sequenceOf(a, b).minOrNull()!! }, "sequenceOf().minOrNull()")
} }
@Test @Test
fun sequenceTMax() { fun sequenceTMaxOrNull() {
totalOrderMaxOf2<Comparable<Any>>({ a, b -> sequenceOf(a, b).max()!! }, "sequenceOf().max()") totalOrderMaxOf2<Comparable<Any>>({ a, b -> sequenceOf(a, b).maxOrNull()!! }, "sequenceOf().maxOrNull()")
} }
} }
+2 -2
View File
@@ -1635,8 +1635,8 @@ ${" "}
assertEquals(23, deindented.lines().size) assertEquals(23, deindented.lines().size)
val indents = deindented.lines().map { "^\\s*".toRegex().find(it)!!.value.length } val indents = deindented.lines().map { "^\\s*".toRegex().find(it)!!.value.length }
assertEquals(0, indents.min()) assertEquals(0, indents.minOrNull())
assertEquals(42, indents.max()) assertEquals(42, indents.maxOrNull())
assertEquals(1, deindented.lines().count { it.isEmpty() }) assertEquals(1, deindented.lines().count { it.isEmpty() })
} }
@@ -1393,6 +1393,16 @@ public final class kotlin/collections/ArraysKt {
public static final fun maxBy ([Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun maxBy ([Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun maxBy ([SLkotlin/jvm/functions/Function1;)Ljava/lang/Short; public static final fun maxBy ([SLkotlin/jvm/functions/Function1;)Ljava/lang/Short;
public static final fun maxBy ([ZLkotlin/jvm/functions/Function1;)Ljava/lang/Boolean; public static final fun maxBy ([ZLkotlin/jvm/functions/Function1;)Ljava/lang/Boolean;
public static final fun maxOrNull ([B)Ljava/lang/Byte;
public static final fun maxOrNull ([C)Ljava/lang/Character;
public static final fun maxOrNull ([D)Ljava/lang/Double;
public static final fun maxOrNull ([F)Ljava/lang/Float;
public static final fun maxOrNull ([I)Ljava/lang/Integer;
public static final fun maxOrNull ([J)Ljava/lang/Long;
public static final fun maxOrNull ([Ljava/lang/Comparable;)Ljava/lang/Comparable;
public static final fun maxOrNull ([Ljava/lang/Double;)Ljava/lang/Double;
public static final fun maxOrNull ([Ljava/lang/Float;)Ljava/lang/Float;
public static final fun maxOrNull ([S)Ljava/lang/Short;
public static final fun maxWith ([BLjava/util/Comparator;)Ljava/lang/Byte; public static final fun maxWith ([BLjava/util/Comparator;)Ljava/lang/Byte;
public static final fun maxWith ([CLjava/util/Comparator;)Ljava/lang/Character; public static final fun maxWith ([CLjava/util/Comparator;)Ljava/lang/Character;
public static final fun maxWith ([DLjava/util/Comparator;)Ljava/lang/Double; public static final fun maxWith ([DLjava/util/Comparator;)Ljava/lang/Double;
@@ -1421,6 +1431,16 @@ public final class kotlin/collections/ArraysKt {
public static final fun minBy ([Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun minBy ([Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun minBy ([SLkotlin/jvm/functions/Function1;)Ljava/lang/Short; public static final fun minBy ([SLkotlin/jvm/functions/Function1;)Ljava/lang/Short;
public static final fun minBy ([ZLkotlin/jvm/functions/Function1;)Ljava/lang/Boolean; public static final fun minBy ([ZLkotlin/jvm/functions/Function1;)Ljava/lang/Boolean;
public static final fun minOrNull ([B)Ljava/lang/Byte;
public static final fun minOrNull ([C)Ljava/lang/Character;
public static final fun minOrNull ([D)Ljava/lang/Double;
public static final fun minOrNull ([F)Ljava/lang/Float;
public static final fun minOrNull ([I)Ljava/lang/Integer;
public static final fun minOrNull ([J)Ljava/lang/Long;
public static final fun minOrNull ([Ljava/lang/Comparable;)Ljava/lang/Comparable;
public static final fun minOrNull ([Ljava/lang/Double;)Ljava/lang/Double;
public static final fun minOrNull ([Ljava/lang/Float;)Ljava/lang/Float;
public static final fun minOrNull ([S)Ljava/lang/Short;
public static final fun minWith ([BLjava/util/Comparator;)Ljava/lang/Byte; public static final fun minWith ([BLjava/util/Comparator;)Ljava/lang/Byte;
public static final fun minWith ([CLjava/util/Comparator;)Ljava/lang/Character; public static final fun minWith ([CLjava/util/Comparator;)Ljava/lang/Character;
public static final fun minWith ([DLjava/util/Comparator;)Ljava/lang/Double; public static final fun minWith ([DLjava/util/Comparator;)Ljava/lang/Double;
@@ -2195,11 +2215,17 @@ public final class kotlin/collections/CollectionsKt {
public static final fun max (Ljava/lang/Iterable;)Ljava/lang/Double; public static final fun max (Ljava/lang/Iterable;)Ljava/lang/Double;
public static final fun max (Ljava/lang/Iterable;)Ljava/lang/Float; public static final fun max (Ljava/lang/Iterable;)Ljava/lang/Float;
public static final fun maxBy (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun maxBy (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun maxOrNull (Ljava/lang/Iterable;)Ljava/lang/Comparable;
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 maxWith (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;
public static final fun minBy (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun minBy (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun minOrNull (Ljava/lang/Iterable;)Ljava/lang/Comparable;
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 minWith (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;
@@ -2615,6 +2641,10 @@ public final class kotlin/collections/unsigned/UArraysKt {
public static final fun max-GBYM_sE ([B)Lkotlin/UByte; public static final fun max-GBYM_sE ([B)Lkotlin/UByte;
public static final fun max-QwZRm1k ([J)Lkotlin/ULong; public static final fun max-QwZRm1k ([J)Lkotlin/ULong;
public static final fun max-rL5Bavg ([S)Lkotlin/UShort; public static final fun max-rL5Bavg ([S)Lkotlin/UShort;
public static final fun maxOrNull--ajY-9A ([I)Lkotlin/UInt;
public static final fun maxOrNull-GBYM_sE ([B)Lkotlin/UByte;
public static final fun maxOrNull-QwZRm1k ([J)Lkotlin/ULong;
public static final fun maxOrNull-rL5Bavg ([S)Lkotlin/UShort;
public static final fun maxWith-XMRcp5o ([BLjava/util/Comparator;)Lkotlin/UByte; public static final fun maxWith-XMRcp5o ([BLjava/util/Comparator;)Lkotlin/UByte;
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;
@@ -2623,6 +2653,10 @@ public final class kotlin/collections/unsigned/UArraysKt {
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;
public static final fun min-rL5Bavg ([S)Lkotlin/UShort; public static final fun min-rL5Bavg ([S)Lkotlin/UShort;
public static final fun minOrNull--ajY-9A ([I)Lkotlin/UInt;
public static final fun minOrNull-GBYM_sE ([B)Lkotlin/UByte;
public static final fun minOrNull-QwZRm1k ([J)Lkotlin/ULong;
public static final fun minOrNull-rL5Bavg ([S)Lkotlin/UShort;
public static final fun minWith-XMRcp5o ([BLjava/util/Comparator;)Lkotlin/UByte; public static final fun minWith-XMRcp5o ([BLjava/util/Comparator;)Lkotlin/UByte;
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;
@@ -4838,11 +4872,17 @@ public final class kotlin/sequences/SequencesKt {
public static final fun max (Lkotlin/sequences/Sequence;)Ljava/lang/Double; public static final fun max (Lkotlin/sequences/Sequence;)Ljava/lang/Double;
public static final fun max (Lkotlin/sequences/Sequence;)Ljava/lang/Float; public static final fun max (Lkotlin/sequences/Sequence;)Ljava/lang/Float;
public static final fun maxBy (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun maxBy (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun maxOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Comparable;
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 maxWith (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;
public static final fun minBy (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun minBy (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun minOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Comparable;
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 minWith (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;
@@ -5241,9 +5281,11 @@ public final class kotlin/text/StringsKt {
public static final fun mapTo (Ljava/lang/CharSequence;Ljava/util/Collection;Lkotlin/jvm/functions/Function1;)Ljava/util/Collection; public static final fun mapTo (Ljava/lang/CharSequence;Ljava/util/Collection;Lkotlin/jvm/functions/Function1;)Ljava/util/Collection;
public static final fun max (Ljava/lang/CharSequence;)Ljava/lang/Character; public static final fun max (Ljava/lang/CharSequence;)Ljava/lang/Character;
public static final fun maxBy (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/Character; public static final fun maxBy (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 maxWith (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 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 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
@@ -306,11 +306,11 @@ object Aggregates : TemplateGroupBase() {
} }
val f_minMax = run { val f_minMax = sequence {
val genericSpecializations = PrimitiveType.floatingPointPrimitives + setOf(null) val genericSpecializations = PrimitiveType.floatingPointPrimitives + setOf(null)
listOf("min", "max").map { op -> fun def(op: String, nullable: Boolean, orNull: String = "OrNull".ifOrEmpty(nullable)) =
fn("$op()") { fn("$op$orNull()") {
include(Iterables, genericSpecializations) include(Iterables, genericSpecializations)
include(Sequences, genericSpecializations) include(Sequences, genericSpecializations)
include(ArraysOfObjects, genericSpecializations) include(ArraysOfObjects, genericSpecializations)
@@ -318,19 +318,30 @@ object Aggregates : TemplateGroupBase() {
include(ArraysOfUnsigned) include(ArraysOfUnsigned)
include(CharSequences) include(CharSequences)
} builder { } builder {
val isFloat = primitive?.isFloatingPoint() == true
val isGeneric = f in listOf(Iterables, Sequences, ArraysOfObjects)
typeParam("T : Comparable<T>") typeParam("T : Comparable<T>")
if (primitive != null) { returns("T?")
if (isFloat && isGeneric)
val isFloat = primitive?.isFloatingPoint() == true
if (!nullable) {
deprecate(Deprecation("Use ${op}OrNull instead.", "${op}OrNull()", DeprecationLevel.WARNING))
val isGeneric = f in listOf(Iterables, Sequences, ArraysOfObjects)
if (isFloat && isGeneric) {
since("1.1") since("1.1")
}
body { "return ${op}OrNull()" }
return@builder
} }
since("1.4")
doc { doc {
"Returns the ${if (op == "max") "largest" else "smallest"} ${f.element} or `null` if there are no ${f.element.pluralize()}." + "Returns the ${if (op == "max") "largest" else "smallest"} ${f.element} or `null` if there are no ${f.element.pluralize()}." +
if (isFloat) "\n\n" + "If any of ${f.element.pluralize()} is `NaN` returns `NaN`." else "" if (isFloat) "\n\n" + "If any of ${f.element.pluralize()} is `NaN` returns `NaN`." else ""
} }
returns("T?")
val acc = op val acc = op
val cmpBlock = if (isFloat) val cmpBlock = if (isFloat)
@@ -361,7 +372,10 @@ object Aggregates : TemplateGroupBase() {
""" """
} }
} }
}
for (op in listOf("min", "max"))
for (nullable in listOf(false, true))
yield(def(op, nullable))
} }
val f_minBy = fn("minBy(selector: (T) -> R)") { val f_minBy = fn("minBy(selector: (T) -> R)") {