Document and test NaN propagation of maxOf/minOf
Also simplify minOf/maxOf implementations #KT-38708
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1797,6 +1797,8 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.maxBy(selector: (T) -> R):
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each element in the collection.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the collection is empty.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@@ -1807,13 +1809,9 @@ public inline fun <T> Iterable<T>.maxOf(selector: (T) -> Double): Double {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) throw NoSuchElementException()
|
||||
var maxValue = selector(iterator.next())
|
||||
if (maxValue.isNaN()) return maxValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
maxValue = maxOf(maxValue, v)
|
||||
}
|
||||
return maxValue
|
||||
}
|
||||
@@ -1822,6 +1820,8 @@ public inline fun <T> Iterable<T>.maxOf(selector: (T) -> Double): Double {
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each element in the collection.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the collection is empty.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@@ -1832,13 +1832,9 @@ public inline fun <T> Iterable<T>.maxOf(selector: (T) -> Float): Float {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) throw NoSuchElementException()
|
||||
var maxValue = selector(iterator.next())
|
||||
if (maxValue.isNaN()) return maxValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
maxValue = maxOf(maxValue, v)
|
||||
}
|
||||
return maxValue
|
||||
}
|
||||
@@ -1859,7 +1855,6 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.maxOf(selector: (T) -> R):
|
||||
var maxValue = selector(iterator.next())
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
@@ -1870,6 +1865,8 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.maxOf(selector: (T) -> R):
|
||||
/**
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each element in the collection or `null` if there are no elements.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
|
||||
@@ -1879,13 +1876,9 @@ public inline fun <T> Iterable<T>.maxOfOrNull(selector: (T) -> Double): Double?
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
var maxValue = selector(iterator.next())
|
||||
if (maxValue.isNaN()) return maxValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
maxValue = maxOf(maxValue, v)
|
||||
}
|
||||
return maxValue
|
||||
}
|
||||
@@ -1893,6 +1886,8 @@ public inline fun <T> Iterable<T>.maxOfOrNull(selector: (T) -> Double): Double?
|
||||
/**
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each element in the collection or `null` if there are no elements.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
|
||||
@@ -1902,13 +1897,9 @@ public inline fun <T> Iterable<T>.maxOfOrNull(selector: (T) -> Float): Float? {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
var maxValue = selector(iterator.next())
|
||||
if (maxValue.isNaN()) return maxValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
maxValue = maxOf(maxValue, v)
|
||||
}
|
||||
return maxValue
|
||||
}
|
||||
@@ -1927,7 +1918,6 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.maxOfOrNull(selector: (T) -
|
||||
var maxValue = selector(iterator.next())
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
@@ -2071,6 +2061,8 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.minBy(selector: (T) -> R):
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each element in the collection.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the collection is empty.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@@ -2081,13 +2073,9 @@ public inline fun <T> Iterable<T>.minOf(selector: (T) -> Double): Double {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) throw NoSuchElementException()
|
||||
var minValue = selector(iterator.next())
|
||||
if (minValue.isNaN()) return minValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
minValue = minOf(minValue, v)
|
||||
}
|
||||
return minValue
|
||||
}
|
||||
@@ -2096,6 +2084,8 @@ public inline fun <T> Iterable<T>.minOf(selector: (T) -> Double): Double {
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each element in the collection.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the collection is empty.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@@ -2106,13 +2096,9 @@ public inline fun <T> Iterable<T>.minOf(selector: (T) -> Float): Float {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) throw NoSuchElementException()
|
||||
var minValue = selector(iterator.next())
|
||||
if (minValue.isNaN()) return minValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
minValue = minOf(minValue, v)
|
||||
}
|
||||
return minValue
|
||||
}
|
||||
@@ -2133,7 +2119,6 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.minOf(selector: (T) -> R):
|
||||
var minValue = selector(iterator.next())
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
@@ -2144,6 +2129,8 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.minOf(selector: (T) -> R):
|
||||
/**
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each element in the collection or `null` if there are no elements.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
|
||||
@@ -2153,13 +2140,9 @@ public inline fun <T> Iterable<T>.minOfOrNull(selector: (T) -> Double): Double?
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
var minValue = selector(iterator.next())
|
||||
if (minValue.isNaN()) return minValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
minValue = minOf(minValue, v)
|
||||
}
|
||||
return minValue
|
||||
}
|
||||
@@ -2167,6 +2150,8 @@ public inline fun <T> Iterable<T>.minOfOrNull(selector: (T) -> Double): Double?
|
||||
/**
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each element in the collection or `null` if there are no elements.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
|
||||
@@ -2176,13 +2161,9 @@ public inline fun <T> Iterable<T>.minOfOrNull(selector: (T) -> Float): Float? {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
var minValue = selector(iterator.next())
|
||||
if (minValue.isNaN()) return minValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
minValue = minOf(minValue, v)
|
||||
}
|
||||
return minValue
|
||||
}
|
||||
@@ -2201,7 +2182,6 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.minOfOrNull(selector: (T) -
|
||||
var minValue = selector(iterator.next())
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
|
||||
@@ -193,6 +193,8 @@ public inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxBy(selector: (Map.E
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each entry in the map.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the map is empty.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@@ -207,6 +209,8 @@ public inline fun <K, V> Map<out K, V>.maxOf(selector: (Map.Entry<K, V>) -> Doub
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each entry in the map.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the map is empty.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@@ -234,6 +238,8 @@ public inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxOf(selector: (Map.E
|
||||
/**
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each entry in the map or `null` if there are no entries.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
|
||||
@@ -246,6 +252,8 @@ public inline fun <K, V> Map<out K, V>.maxOfOrNull(selector: (Map.Entry<K, V>) -
|
||||
/**
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each entry in the map or `null` if there are no entries.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
|
||||
@@ -314,6 +322,8 @@ public inline fun <K, V, R : Comparable<R>> Map<out K, V>.minBy(selector: (Map.E
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each entry in the map.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the map is empty.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@@ -328,6 +338,8 @@ public inline fun <K, V> Map<out K, V>.minOf(selector: (Map.Entry<K, V>) -> Doub
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each entry in the map.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the map is empty.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@@ -355,6 +367,8 @@ public inline fun <K, V, R : Comparable<R>> Map<out K, V>.minOf(selector: (Map.E
|
||||
/**
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each entry in the map or `null` if there are no entries.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
|
||||
@@ -367,6 +381,8 @@ public inline fun <K, V> Map<out K, V>.minOfOrNull(selector: (Map.Entry<K, V>) -
|
||||
/**
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each entry in the map or `null` if there are no entries.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
|
||||
|
||||
@@ -1252,6 +1252,8 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.maxBy(selector: (T) -> R):
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each element in the sequence.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the sequence is empty.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
@@ -1264,13 +1266,9 @@ public inline fun <T> Sequence<T>.maxOf(selector: (T) -> Double): Double {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) throw NoSuchElementException()
|
||||
var maxValue = selector(iterator.next())
|
||||
if (maxValue.isNaN()) return maxValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
maxValue = maxOf(maxValue, v)
|
||||
}
|
||||
return maxValue
|
||||
}
|
||||
@@ -1279,6 +1277,8 @@ public inline fun <T> Sequence<T>.maxOf(selector: (T) -> Double): Double {
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each element in the sequence.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the sequence is empty.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
@@ -1291,13 +1291,9 @@ public inline fun <T> Sequence<T>.maxOf(selector: (T) -> Float): Float {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) throw NoSuchElementException()
|
||||
var maxValue = selector(iterator.next())
|
||||
if (maxValue.isNaN()) return maxValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
maxValue = maxOf(maxValue, v)
|
||||
}
|
||||
return maxValue
|
||||
}
|
||||
@@ -1320,7 +1316,6 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.maxOf(selector: (T) -> R):
|
||||
var maxValue = selector(iterator.next())
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
@@ -1331,6 +1326,8 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.maxOf(selector: (T) -> R):
|
||||
/**
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each element in the sequence or `null` if there are no elements.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@@ -1342,13 +1339,9 @@ public inline fun <T> Sequence<T>.maxOfOrNull(selector: (T) -> Double): Double?
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
var maxValue = selector(iterator.next())
|
||||
if (maxValue.isNaN()) return maxValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
maxValue = maxOf(maxValue, v)
|
||||
}
|
||||
return maxValue
|
||||
}
|
||||
@@ -1356,6 +1349,8 @@ public inline fun <T> Sequence<T>.maxOfOrNull(selector: (T) -> Double): Double?
|
||||
/**
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each element in the sequence or `null` if there are no elements.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@@ -1367,13 +1362,9 @@ public inline fun <T> Sequence<T>.maxOfOrNull(selector: (T) -> Float): Float? {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
var maxValue = selector(iterator.next())
|
||||
if (maxValue.isNaN()) return maxValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
maxValue = maxOf(maxValue, v)
|
||||
}
|
||||
return maxValue
|
||||
}
|
||||
@@ -1394,7 +1385,6 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.maxOfOrNull(selector: (T) -
|
||||
var maxValue = selector(iterator.next())
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
@@ -1552,6 +1542,8 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.minBy(selector: (T) -> R):
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each element in the sequence.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the sequence is empty.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
@@ -1564,13 +1556,9 @@ public inline fun <T> Sequence<T>.minOf(selector: (T) -> Double): Double {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) throw NoSuchElementException()
|
||||
var minValue = selector(iterator.next())
|
||||
if (minValue.isNaN()) return minValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
minValue = minOf(minValue, v)
|
||||
}
|
||||
return minValue
|
||||
}
|
||||
@@ -1579,6 +1567,8 @@ public inline fun <T> Sequence<T>.minOf(selector: (T) -> Double): Double {
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each element in the sequence.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the sequence is empty.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
@@ -1591,13 +1581,9 @@ public inline fun <T> Sequence<T>.minOf(selector: (T) -> Float): Float {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) throw NoSuchElementException()
|
||||
var minValue = selector(iterator.next())
|
||||
if (minValue.isNaN()) return minValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
minValue = minOf(minValue, v)
|
||||
}
|
||||
return minValue
|
||||
}
|
||||
@@ -1620,7 +1606,6 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.minOf(selector: (T) -> R):
|
||||
var minValue = selector(iterator.next())
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
@@ -1631,6 +1616,8 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.minOf(selector: (T) -> R):
|
||||
/**
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each element in the sequence or `null` if there are no elements.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@@ -1642,13 +1629,9 @@ public inline fun <T> Sequence<T>.minOfOrNull(selector: (T) -> Double): Double?
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
var minValue = selector(iterator.next())
|
||||
if (minValue.isNaN()) return minValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
minValue = minOf(minValue, v)
|
||||
}
|
||||
return minValue
|
||||
}
|
||||
@@ -1656,6 +1639,8 @@ public inline fun <T> Sequence<T>.minOfOrNull(selector: (T) -> Double): Double?
|
||||
/**
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each element in the sequence or `null` if there are no elements.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*/
|
||||
@@ -1667,13 +1652,9 @@ public inline fun <T> Sequence<T>.minOfOrNull(selector: (T) -> Float): Float? {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
var minValue = selector(iterator.next())
|
||||
if (minValue.isNaN()) return minValue
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
if (v.isNaN()) return v
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
minValue = minOf(minValue, v)
|
||||
}
|
||||
return minValue
|
||||
}
|
||||
@@ -1694,7 +1675,6 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.minOfOrNull(selector: (T) -
|
||||
var minValue = selector(iterator.next())
|
||||
while (iterator.hasNext()) {
|
||||
val v = selector(iterator.next())
|
||||
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
|
||||
@@ -1127,6 +1127,8 @@ public inline fun <R : Comparable<R>> CharSequence.maxBy(selector: (Char) -> R):
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each character in the char sequence.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the char sequence is empty.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@@ -1136,15 +1138,9 @@ public inline fun <R : Comparable<R>> CharSequence.maxBy(selector: (Char) -> R):
|
||||
public inline fun CharSequence.maxOf(selector: (Char) -> Double): Double {
|
||||
if (isEmpty()) throw NoSuchElementException()
|
||||
var maxValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return maxValue
|
||||
if (maxValue.isNaN()) return maxValue
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
if (v.isNaN()) return v
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
maxValue = maxOf(maxValue, v)
|
||||
}
|
||||
return maxValue
|
||||
}
|
||||
@@ -1153,6 +1149,8 @@ public inline fun CharSequence.maxOf(selector: (Char) -> Double): Double {
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each character in the char sequence.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the char sequence is empty.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@@ -1162,15 +1160,9 @@ public inline fun CharSequence.maxOf(selector: (Char) -> Double): Double {
|
||||
public inline fun CharSequence.maxOf(selector: (Char) -> Float): Float {
|
||||
if (isEmpty()) throw NoSuchElementException()
|
||||
var maxValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return maxValue
|
||||
if (maxValue.isNaN()) return maxValue
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
if (v.isNaN()) return v
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
maxValue = maxOf(maxValue, v)
|
||||
}
|
||||
return maxValue
|
||||
}
|
||||
@@ -1188,12 +1180,8 @@ public inline fun CharSequence.maxOf(selector: (Char) -> Float): Float {
|
||||
public inline fun <R : Comparable<R>> CharSequence.maxOf(selector: (Char) -> R): R {
|
||||
if (isEmpty()) throw NoSuchElementException()
|
||||
var maxValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return maxValue
|
||||
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
@@ -1204,6 +1192,8 @@ public inline fun <R : Comparable<R>> CharSequence.maxOf(selector: (Char) -> R):
|
||||
/**
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each character in the char sequence or `null` if there are no characters.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
|
||||
@@ -1212,15 +1202,9 @@ public inline fun <R : Comparable<R>> CharSequence.maxOf(selector: (Char) -> R):
|
||||
public inline fun CharSequence.maxOfOrNull(selector: (Char) -> Double): Double? {
|
||||
if (isEmpty()) return null
|
||||
var maxValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return maxValue
|
||||
if (maxValue.isNaN()) return maxValue
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
if (v.isNaN()) return v
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
maxValue = maxOf(maxValue, v)
|
||||
}
|
||||
return maxValue
|
||||
}
|
||||
@@ -1228,6 +1212,8 @@ public inline fun CharSequence.maxOfOrNull(selector: (Char) -> Double): Double?
|
||||
/**
|
||||
* Returns the largest value among all values produced by [selector] function
|
||||
* applied to each character in the char sequence or `null` if there are no characters.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
|
||||
@@ -1236,15 +1222,9 @@ public inline fun CharSequence.maxOfOrNull(selector: (Char) -> Double): Double?
|
||||
public inline fun CharSequence.maxOfOrNull(selector: (Char) -> Float): Float? {
|
||||
if (isEmpty()) return null
|
||||
var maxValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return maxValue
|
||||
if (maxValue.isNaN()) return maxValue
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
if (v.isNaN()) return v
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
maxValue = maxOf(maxValue, v)
|
||||
}
|
||||
return maxValue
|
||||
}
|
||||
@@ -1260,12 +1240,8 @@ public inline fun CharSequence.maxOfOrNull(selector: (Char) -> Float): Float? {
|
||||
public inline fun <R : Comparable<R>> CharSequence.maxOfOrNull(selector: (Char) -> R): R? {
|
||||
if (isEmpty()) return null
|
||||
var maxValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return maxValue
|
||||
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
|
||||
if (maxValue < v) {
|
||||
maxValue = v
|
||||
}
|
||||
@@ -1286,8 +1262,6 @@ public inline fun <R : Comparable<R>> CharSequence.maxOfOrNull(selector: (Char)
|
||||
public inline fun <R> CharSequence.maxOfWith(comparator: Comparator<in R>, selector: (Char) -> R): R {
|
||||
if (isEmpty()) throw NoSuchElementException()
|
||||
var maxValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return maxValue
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
if (comparator.compare(maxValue, v) < 0) {
|
||||
@@ -1308,8 +1282,6 @@ public inline fun <R> CharSequence.maxOfWith(comparator: Comparator<in R>, selec
|
||||
public inline fun <R> CharSequence.maxOfWithOrNull(comparator: Comparator<in R>, selector: (Char) -> R): R? {
|
||||
if (isEmpty()) return null
|
||||
var maxValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return maxValue
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
if (comparator.compare(maxValue, v) < 0) {
|
||||
@@ -1371,6 +1343,8 @@ public inline fun <R : Comparable<R>> CharSequence.minBy(selector: (Char) -> R):
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each character in the char sequence.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the char sequence is empty.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@@ -1380,15 +1354,9 @@ public inline fun <R : Comparable<R>> CharSequence.minBy(selector: (Char) -> R):
|
||||
public inline fun CharSequence.minOf(selector: (Char) -> Double): Double {
|
||||
if (isEmpty()) throw NoSuchElementException()
|
||||
var minValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return minValue
|
||||
if (minValue.isNaN()) return minValue
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
if (v.isNaN()) return v
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
minValue = minOf(minValue, v)
|
||||
}
|
||||
return minValue
|
||||
}
|
||||
@@ -1397,6 +1365,8 @@ public inline fun CharSequence.minOf(selector: (Char) -> Double): Double {
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each character in the char sequence.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*
|
||||
* @throws NoSuchElementException if the char sequence is empty.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@@ -1406,15 +1376,9 @@ public inline fun CharSequence.minOf(selector: (Char) -> Double): Double {
|
||||
public inline fun CharSequence.minOf(selector: (Char) -> Float): Float {
|
||||
if (isEmpty()) throw NoSuchElementException()
|
||||
var minValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return minValue
|
||||
if (minValue.isNaN()) return minValue
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
if (v.isNaN()) return v
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
minValue = minOf(minValue, v)
|
||||
}
|
||||
return minValue
|
||||
}
|
||||
@@ -1432,12 +1396,8 @@ public inline fun CharSequence.minOf(selector: (Char) -> Float): Float {
|
||||
public inline fun <R : Comparable<R>> CharSequence.minOf(selector: (Char) -> R): R {
|
||||
if (isEmpty()) throw NoSuchElementException()
|
||||
var minValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return minValue
|
||||
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
@@ -1448,6 +1408,8 @@ public inline fun <R : Comparable<R>> CharSequence.minOf(selector: (Char) -> R):
|
||||
/**
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each character in the char sequence or `null` if there are no characters.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
|
||||
@@ -1456,15 +1418,9 @@ public inline fun <R : Comparable<R>> CharSequence.minOf(selector: (Char) -> R):
|
||||
public inline fun CharSequence.minOfOrNull(selector: (Char) -> Double): Double? {
|
||||
if (isEmpty()) return null
|
||||
var minValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return minValue
|
||||
if (minValue.isNaN()) return minValue
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
if (v.isNaN()) return v
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
minValue = minOf(minValue, v)
|
||||
}
|
||||
return minValue
|
||||
}
|
||||
@@ -1472,6 +1428,8 @@ public inline fun CharSequence.minOfOrNull(selector: (Char) -> Double): Double?
|
||||
/**
|
||||
* Returns the smallest value among all values produced by [selector] function
|
||||
* applied to each character in the char sequence or `null` if there are no characters.
|
||||
*
|
||||
* If any of values produced by [selector] function is `NaN`, the returned result is `NaN`.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
|
||||
@@ -1480,15 +1438,9 @@ public inline fun CharSequence.minOfOrNull(selector: (Char) -> Double): Double?
|
||||
public inline fun CharSequence.minOfOrNull(selector: (Char) -> Float): Float? {
|
||||
if (isEmpty()) return null
|
||||
var minValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return minValue
|
||||
if (minValue.isNaN()) return minValue
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
if (v.isNaN()) return v
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
minValue = minOf(minValue, v)
|
||||
}
|
||||
return minValue
|
||||
}
|
||||
@@ -1504,12 +1456,8 @@ public inline fun CharSequence.minOfOrNull(selector: (Char) -> Float): Float? {
|
||||
public inline fun <R : Comparable<R>> CharSequence.minOfOrNull(selector: (Char) -> R): R? {
|
||||
if (isEmpty()) return null
|
||||
var minValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return minValue
|
||||
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
|
||||
if (minValue > v) {
|
||||
minValue = v
|
||||
}
|
||||
@@ -1530,8 +1478,6 @@ public inline fun <R : Comparable<R>> CharSequence.minOfOrNull(selector: (Char)
|
||||
public inline fun <R> CharSequence.minOfWith(comparator: Comparator<in R>, selector: (Char) -> R): R {
|
||||
if (isEmpty()) throw NoSuchElementException()
|
||||
var minValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return minValue
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
if (comparator.compare(minValue, v) > 0) {
|
||||
@@ -1552,8 +1498,6 @@ public inline fun <R> CharSequence.minOfWith(comparator: Comparator<in R>, selec
|
||||
public inline fun <R> CharSequence.minOfWithOrNull(comparator: Comparator<in R>, selector: (Char) -> R): R? {
|
||||
if (isEmpty()) return null
|
||||
var minValue = selector(this[0])
|
||||
val lastIndex = this.lastIndex
|
||||
if (lastIndex == 0) return minValue
|
||||
for (i in 1..lastIndex) {
|
||||
val v = selector(this[i])
|
||||
if (comparator.compare(minValue, v) > 0) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user