Introduce minOf/maxOf, minOfWith/maxOfWith and their OrNull variants

#KT-38708 Fixed
This commit is contained in:
Ilya Gorbunov
2020-05-21 00:17:01 +03:00
parent 6a24becd1d
commit 7b68de38e1
9 changed files with 6744 additions and 2 deletions
File diff suppressed because it is too large Load Diff
@@ -1793,6 +1793,192 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.maxBy(selector: (T) -> R):
return maxElem
}
/**
* Returns the largest value among all values produced by [selector] function
* applied to each element in the collection.
*
* @throws NoSuchElementException if the collection is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* Returns the largest value among all values produced by [selector] function
* applied to each element in the collection.
*
* @throws NoSuchElementException if the collection is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* Returns the largest value among all values produced by [selector] function
* applied to each element in the collection.
*
* @throws NoSuchElementException if the collection is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R : Comparable<R>> Iterable<T>.maxOf(selector: (T) -> R): R {
val iterator = iterator()
if (!iterator.hasNext()) throw NoSuchElementException()
var maxValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (maxValue < v) {
maxValue = v
}
}
return maxValue
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R : Comparable<R>> Iterable<T>.maxOfOrNull(selector: (T) -> R): R? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var maxValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (maxValue < v) {
maxValue = v
}
}
return maxValue
}
/**
* Returns the largest value according to the provided [comparator]
* among all values produced by [selector] function applied to each element in the collection.
*
* @throws NoSuchElementException if the collection is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R> Iterable<T>.maxOfWith(comparator: Comparator<in R>, selector: (T) -> R): R {
val iterator = iterator()
if (!iterator.hasNext()) throw NoSuchElementException()
var maxValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (comparator.compare(maxValue, v) < 0) {
maxValue = v
}
}
return maxValue
}
/**
* Returns the largest value according to the provided [comparator]
* among all values produced by [selector] function applied to each element in the collection or `null` if there are no elements.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R> Iterable<T>.maxOfWithOrNull(comparator: Comparator<in R>, selector: (T) -> R): R? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var maxValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (comparator.compare(maxValue, v) < 0) {
maxValue = v
}
}
return maxValue
}
/**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*/
@@ -1881,6 +2067,192 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.minBy(selector: (T) -> R):
return minElem
}
/**
* Returns the smallest value among all values produced by [selector] function
* applied to each element in the collection.
*
* @throws NoSuchElementException if the collection is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* Returns the smallest value among all values produced by [selector] function
* applied to each element in the collection.
*
* @throws NoSuchElementException if the collection is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* Returns the smallest value among all values produced by [selector] function
* applied to each element in the collection.
*
* @throws NoSuchElementException if the collection is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R : Comparable<R>> Iterable<T>.minOf(selector: (T) -> R): R {
val iterator = iterator()
if (!iterator.hasNext()) throw NoSuchElementException()
var minValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (minValue > v) {
minValue = v
}
}
return minValue
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R : Comparable<R>> Iterable<T>.minOfOrNull(selector: (T) -> R): R? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var minValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (minValue > v) {
minValue = v
}
}
return minValue
}
/**
* Returns the smallest value according to the provided [comparator]
* among all values produced by [selector] function applied to each element in the collection.
*
* @throws NoSuchElementException if the collection is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R> Iterable<T>.minOfWith(comparator: Comparator<in R>, selector: (T) -> R): R {
val iterator = iterator()
if (!iterator.hasNext()) throw NoSuchElementException()
var minValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (comparator.compare(minValue, v) > 0) {
minValue = v
}
}
return minValue
}
/**
* Returns the smallest value according to the provided [comparator]
* among all values produced by [selector] function applied to each element in the collection or `null` if there are no elements.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R> Iterable<T>.minOfWithOrNull(comparator: Comparator<in R>, selector: (T) -> R): R? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var minValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (comparator.compare(minValue, v) > 0) {
minValue = v
}
}
return minValue
}
/**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/
@@ -189,6 +189,110 @@ public inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxBy(selector: (Map.E
return entries.maxBy(selector)
}
/**
* Returns the largest value among all values produced by [selector] function
* applied to each entry in the map.
*
* @throws NoSuchElementException if the map is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<out K, V>.maxOf(selector: (Map.Entry<K, V>) -> Double): Double {
return entries.maxOf(selector)
}
/**
* Returns the largest value among all values produced by [selector] function
* applied to each entry in the map.
*
* @throws NoSuchElementException if the map is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<out K, V>.maxOf(selector: (Map.Entry<K, V>) -> Float): Float {
return entries.maxOf(selector)
}
/**
* Returns the largest value among all values produced by [selector] function
* applied to each entry in the map.
*
* @throws NoSuchElementException if the map is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxOf(selector: (Map.Entry<K, V>) -> R): R {
return entries.maxOf(selector)
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<out K, V>.maxOfOrNull(selector: (Map.Entry<K, V>) -> Double): Double? {
return entries.maxOfOrNull(selector)
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<out K, V>.maxOfOrNull(selector: (Map.Entry<K, V>) -> Float): Float? {
return entries.maxOfOrNull(selector)
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxOfOrNull(selector: (Map.Entry<K, V>) -> R): R? {
return entries.maxOfOrNull(selector)
}
/**
* Returns the largest value according to the provided [comparator]
* among all values produced by [selector] function applied to each entry in the map.
*
* @throws NoSuchElementException if the map is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V, R> Map<out K, V>.maxOfWith(comparator: Comparator<in R>, selector: (Map.Entry<K, V>) -> R): R {
return entries.maxOfWith(comparator, selector)
}
/**
* Returns the largest value according to the provided [comparator]
* among all values produced by [selector] function applied to each entry in the map or `null` if there are no entries.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V, R> Map<out K, V>.maxOfWithOrNull(comparator: Comparator<in R>, selector: (Map.Entry<K, V>) -> R): R? {
return entries.maxOfWithOrNull(comparator, selector)
}
/**
* Returns the first entry having the largest value according to the provided [comparator] or `null` if there are no entries.
*/
@@ -206,6 +310,110 @@ public inline fun <K, V, R : Comparable<R>> Map<out K, V>.minBy(selector: (Map.E
return entries.minBy(selector)
}
/**
* Returns the smallest value among all values produced by [selector] function
* applied to each entry in the map.
*
* @throws NoSuchElementException if the map is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<out K, V>.minOf(selector: (Map.Entry<K, V>) -> Double): Double {
return entries.minOf(selector)
}
/**
* Returns the smallest value among all values produced by [selector] function
* applied to each entry in the map.
*
* @throws NoSuchElementException if the map is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<out K, V>.minOf(selector: (Map.Entry<K, V>) -> Float): Float {
return entries.minOf(selector)
}
/**
* Returns the smallest value among all values produced by [selector] function
* applied to each entry in the map.
*
* @throws NoSuchElementException if the map is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V, R : Comparable<R>> Map<out K, V>.minOf(selector: (Map.Entry<K, V>) -> R): R {
return entries.minOf(selector)
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<out K, V>.minOfOrNull(selector: (Map.Entry<K, V>) -> Double): Double? {
return entries.minOfOrNull(selector)
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<out K, V>.minOfOrNull(selector: (Map.Entry<K, V>) -> Float): Float? {
return entries.minOfOrNull(selector)
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V, R : Comparable<R>> Map<out K, V>.minOfOrNull(selector: (Map.Entry<K, V>) -> R): R? {
return entries.minOfOrNull(selector)
}
/**
* Returns the smallest value according to the provided [comparator]
* among all values produced by [selector] function applied to each entry in the map.
*
* @throws NoSuchElementException if the map is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V, R> Map<out K, V>.minOfWith(comparator: Comparator<in R>, selector: (Map.Entry<K, V>) -> R): R {
return entries.minOfWith(comparator, selector)
}
/**
* Returns the smallest value according to the provided [comparator]
* among all values produced by [selector] function applied to each entry in the map or `null` if there are no entries.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <K, V, R> Map<out K, V>.minOfWithOrNull(comparator: Comparator<in R>, selector: (Map.Entry<K, V>) -> R): R? {
return entries.minOfWithOrNull(comparator, selector)
}
/**
* Returns the first entry having the smallest value according to the provided [comparator] or `null` if there are no entries.
*/
@@ -1248,6 +1248,208 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.maxBy(selector: (T) -> R):
return maxElem
}
/**
* Returns the largest value among all values produced by [selector] function
* applied to each element in the sequence.
*
* @throws NoSuchElementException if the sequence is empty.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* Returns the largest value among all values produced by [selector] function
* applied to each element in the sequence.
*
* @throws NoSuchElementException if the sequence is empty.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* Returns the largest value among all values produced by [selector] function
* applied to each element in the sequence.
*
* @throws NoSuchElementException if the sequence is empty.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R : Comparable<R>> Sequence<T>.maxOf(selector: (T) -> R): R {
val iterator = iterator()
if (!iterator.hasNext()) throw NoSuchElementException()
var maxValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (maxValue < v) {
maxValue = v
}
}
return maxValue
}
/**
* 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.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* 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.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* 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.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R : Comparable<R>> Sequence<T>.maxOfOrNull(selector: (T) -> R): R? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var maxValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (maxValue < v) {
maxValue = v
}
}
return maxValue
}
/**
* Returns the largest value according to the provided [comparator]
* among all values produced by [selector] function applied to each element in the sequence.
*
* @throws NoSuchElementException if the sequence is empty.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R> Sequence<T>.maxOfWith(comparator: Comparator<in R>, selector: (T) -> R): R {
val iterator = iterator()
if (!iterator.hasNext()) throw NoSuchElementException()
var maxValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (comparator.compare(maxValue, v) < 0) {
maxValue = v
}
}
return maxValue
}
/**
* Returns the largest value according to the provided [comparator]
* among all values produced by [selector] function applied to each element in the sequence or `null` if there are no elements.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R> Sequence<T>.maxOfWithOrNull(comparator: Comparator<in R>, selector: (T) -> R): R? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var maxValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (comparator.compare(maxValue, v) < 0) {
maxValue = v
}
}
return maxValue
}
/**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
*
@@ -1346,6 +1548,208 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.minBy(selector: (T) -> R):
return minElem
}
/**
* Returns the smallest value among all values produced by [selector] function
* applied to each element in the sequence.
*
* @throws NoSuchElementException if the sequence is empty.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* Returns the smallest value among all values produced by [selector] function
* applied to each element in the sequence.
*
* @throws NoSuchElementException if the sequence is empty.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* Returns the smallest value among all values produced by [selector] function
* applied to each element in the sequence.
*
* @throws NoSuchElementException if the sequence is empty.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R : Comparable<R>> Sequence<T>.minOf(selector: (T) -> R): R {
val iterator = iterator()
if (!iterator.hasNext()) throw NoSuchElementException()
var minValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (minValue > v) {
minValue = v
}
}
return minValue
}
/**
* 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.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* 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.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* 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.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R : Comparable<R>> Sequence<T>.minOfOrNull(selector: (T) -> R): R? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var minValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (minValue > v) {
minValue = v
}
}
return minValue
}
/**
* Returns the smallest value according to the provided [comparator]
* among all values produced by [selector] function applied to each element in the sequence.
*
* @throws NoSuchElementException if the sequence is empty.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R> Sequence<T>.minOfWith(comparator: Comparator<in R>, selector: (T) -> R): R {
val iterator = iterator()
if (!iterator.hasNext()) throw NoSuchElementException()
var minValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (comparator.compare(minValue, v) > 0) {
minValue = v
}
}
return minValue
}
/**
* Returns the smallest value according to the provided [comparator]
* among all values produced by [selector] function applied to each element in the sequence or `null` if there are no elements.
*
* The operation is _terminal_.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R> Sequence<T>.minOfWithOrNull(comparator: Comparator<in R>, selector: (T) -> R): R? {
val iterator = iterator()
if (!iterator.hasNext()) return null
var minValue = selector(iterator.next())
while (iterator.hasNext()) {
val v = selector(iterator.next())
if (comparator.compare(minValue, v) > 0) {
minValue = v
}
}
return minValue
}
/**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*
@@ -1123,6 +1123,202 @@ public inline fun <R : Comparable<R>> CharSequence.maxBy(selector: (Char) -> R):
return maxElem
}
/**
* Returns the largest value among all values produced by [selector] function
* applied to each character in the char sequence.
*
* @throws NoSuchElementException if the char sequence is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* Returns the largest value among all values produced by [selector] function
* applied to each character in the char sequence.
*
* @throws NoSuchElementException if the char sequence is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* Returns the largest value among all values produced by [selector] function
* applied to each character in the char sequence.
*
* @throws NoSuchElementException if the char sequence is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return maxValue
}
/**
* Returns the largest value according to the provided [comparator]
* among all values produced by [selector] function applied to each character in the char sequence.
*
* @throws NoSuchElementException if the char sequence is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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) {
maxValue = v
}
}
return maxValue
}
/**
* Returns the largest value according to the provided [comparator]
* among all values produced by [selector] function applied to each character in the char sequence or `null` if there are no characters.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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) {
maxValue = v
}
}
return maxValue
}
/**
* Returns the first character having the largest value according to the provided [comparator] or `null` if there are no characters.
*/
@@ -1171,6 +1367,202 @@ public inline fun <R : Comparable<R>> CharSequence.minBy(selector: (Char) -> R):
return minElem
}
/**
* Returns the smallest value among all values produced by [selector] function
* applied to each character in the char sequence.
*
* @throws NoSuchElementException if the char sequence is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* Returns the smallest value among all values produced by [selector] function
* applied to each character in the char sequence.
*
* @throws NoSuchElementException if the char sequence is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* Returns the smallest value among all values produced by [selector] function
* applied to each character in the char sequence.
*
* @throws NoSuchElementException if the char sequence is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* 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.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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
}
}
return minValue
}
/**
* Returns the smallest value according to the provided [comparator]
* among all values produced by [selector] function applied to each character in the char sequence.
*
* @throws NoSuchElementException if the char sequence is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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) {
minValue = v
}
}
return minValue
}
/**
* Returns the smallest value according to the provided [comparator]
* among all values produced by [selector] function applied to each character in the char sequence or `null` if there are no characters.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
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) {
minValue = v
}
}
return minValue
}
/**
* Returns the first character having the smallest value according to the provided [comparator] or `null` if there are no characters.
*/
File diff suppressed because it is too large Load Diff