Introduce new overloads of max and min to fix NaN propagation behavior on JVM.

This commit is contained in:
Ilya Gorbunov
2016-12-28 04:08:05 +03:00
parent 74331f8eaa
commit 0bf2ba8701
11 changed files with 557 additions and 61 deletions
@@ -5751,6 +5751,18 @@ public header inline fun BooleanArray.forEachIndexed(action: (Int, Boolean) -> U
*/
public header inline fun CharArray.forEachIndexed(action: (Int, Char) -> Unit): Unit
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.1")
public header fun Array<out Double>.max(): Double?
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.1")
public header fun Array<out Float>.max(): Float?
/**
* Returns the largest element or `null` if there are no elements.
*/
@@ -5881,6 +5893,18 @@ public header fun BooleanArray.maxWith(comparator: Comparator<in Boolean>): Bool
*/
public header fun CharArray.maxWith(comparator: Comparator<in Char>): Char?
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.1")
public header fun Array<out Double>.min(): Double?
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.1")
public header fun Array<out Float>.min(): Float?
/**
* Returns the smallest element or `null` if there are no elements.
*/
@@ -765,6 +765,18 @@ public header inline fun <T> Iterable<T>.forEach(action: (T) -> Unit): Unit
*/
public header inline fun <T> Iterable<T>.forEachIndexed(action: (Int, T) -> Unit): Unit
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.1")
public header fun Iterable<Double>.max(): Double?
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.1")
public header fun Iterable<Float>.max(): Float?
/**
* Returns the largest element or `null` if there are no elements.
*/
@@ -780,6 +792,18 @@ public header inline fun <T, R : Comparable<R>> Iterable<T>.maxBy(selector: (T)
*/
public header fun <T> Iterable<T>.maxWith(comparator: Comparator<in T>): T?
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.1")
public header fun Iterable<Double>.min(): Double?
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.1")
public header fun Iterable<Float>.min(): Float?
/**
* Returns the smallest element or `null` if there are no elements.
*/
@@ -492,6 +492,18 @@ public header inline fun <T> Sequence<T>.forEach(action: (T) -> Unit): Unit
*/
public header inline fun <T> Sequence<T>.forEachIndexed(action: (Int, T) -> Unit): Unit
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.1")
public header fun Sequence<Double>.max(): Double?
/**
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin("1.1")
public header fun Sequence<Float>.max(): Float?
/**
* Returns the largest element or `null` if there are no elements.
*/
@@ -507,6 +519,18 @@ public header inline fun <T, R : Comparable<R>> Sequence<T>.maxBy(selector: (T)
*/
public header fun <T> Sequence<T>.maxWith(comparator: Comparator<in T>): T?
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.1")
public header fun Sequence<Double>.min(): Double?
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin("1.1")
public header fun Sequence<Float>.min(): Float?
/**
* Returns the smallest element or `null` if there are no elements.
*/