Relax upper bound of T for minBy and maxBy to be nullable.
Swap type parameters of minBy and maxBy. #KT-10099 Fixed
This commit is contained in:
@@ -8359,7 +8359,7 @@ public fun ShortArray.max(): Short? {
|
|||||||
/**
|
/**
|
||||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||||
*/
|
*/
|
||||||
public inline fun <R : Comparable<R>, T : Any> Array<out T>.maxBy(selector: (T) -> R): T? {
|
public inline fun <T, R : Comparable<R>> Array<out T>.maxBy(selector: (T) -> R): T? {
|
||||||
if (isEmpty()) return null
|
if (isEmpty()) return null
|
||||||
var maxElem = this[0]
|
var maxElem = this[0]
|
||||||
var maxValue = selector(maxElem)
|
var maxValue = selector(maxElem)
|
||||||
@@ -8625,7 +8625,7 @@ public fun ShortArray.min(): Short? {
|
|||||||
/**
|
/**
|
||||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||||
*/
|
*/
|
||||||
public inline fun <R : Comparable<R>, T : Any> Array<out T>.minBy(selector: (T) -> R): T? {
|
public inline fun <T, R : Comparable<R>> Array<out T>.minBy(selector: (T) -> R): T? {
|
||||||
if (isEmpty()) return null
|
if (isEmpty()) return null
|
||||||
var minElem = this[0]
|
var minElem = this[0]
|
||||||
var minValue = selector(minElem)
|
var minValue = selector(minElem)
|
||||||
|
|||||||
@@ -1397,7 +1397,7 @@ public fun <T : Comparable<T>> Iterable<T>.max(): T? {
|
|||||||
/**
|
/**
|
||||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||||
*/
|
*/
|
||||||
public inline fun <R : Comparable<R>, T : Any> Iterable<T>.maxBy(selector: (T) -> R): T? {
|
public inline fun <T, R : Comparable<R>> Iterable<T>.maxBy(selector: (T) -> R): T? {
|
||||||
val iterator = iterator()
|
val iterator = iterator()
|
||||||
if (!iterator.hasNext()) return null
|
if (!iterator.hasNext()) return null
|
||||||
var maxElem = iterator.next()
|
var maxElem = iterator.next()
|
||||||
@@ -1430,7 +1430,7 @@ public fun <T : Comparable<T>> Iterable<T>.min(): T? {
|
|||||||
/**
|
/**
|
||||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||||
*/
|
*/
|
||||||
public inline fun <R : Comparable<R>, T : Any> Iterable<T>.minBy(selector: (T) -> R): T? {
|
public inline fun <T, R : Comparable<R>> Iterable<T>.minBy(selector: (T) -> R): T? {
|
||||||
val iterator = iterator()
|
val iterator = iterator()
|
||||||
if (!iterator.hasNext()) return null
|
if (!iterator.hasNext()) return null
|
||||||
var minElem = iterator.next()
|
var minElem = iterator.next()
|
||||||
|
|||||||
@@ -799,7 +799,7 @@ public fun <T : Comparable<T>> Sequence<T>.max(): T? {
|
|||||||
/**
|
/**
|
||||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||||
*/
|
*/
|
||||||
public inline fun <R : Comparable<R>, T : Any> Sequence<T>.maxBy(selector: (T) -> R): T? {
|
public inline fun <T, R : Comparable<R>> Sequence<T>.maxBy(selector: (T) -> R): T? {
|
||||||
val iterator = iterator()
|
val iterator = iterator()
|
||||||
if (!iterator.hasNext()) return null
|
if (!iterator.hasNext()) return null
|
||||||
var maxElem = iterator.next()
|
var maxElem = iterator.next()
|
||||||
@@ -832,7 +832,7 @@ public fun <T : Comparable<T>> Sequence<T>.min(): T? {
|
|||||||
/**
|
/**
|
||||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||||
*/
|
*/
|
||||||
public inline fun <R : Comparable<R>, T : Any> Sequence<T>.minBy(selector: (T) -> R): T? {
|
public inline fun <T, R : Comparable<R>> Sequence<T>.minBy(selector: (T) -> R): T? {
|
||||||
val iterator = iterator()
|
val iterator = iterator()
|
||||||
if (!iterator.hasNext()) return null
|
if (!iterator.hasNext()) return null
|
||||||
var minElem = iterator.next()
|
var minElem = iterator.next()
|
||||||
|
|||||||
@@ -181,8 +181,8 @@ fun aggregates(): List<GenericFunction> {
|
|||||||
inline(true)
|
inline(true)
|
||||||
|
|
||||||
doc { f -> "Returns the first ${f.element} yielding the smallest value of the given function or `null` if there are no ${f.element.pluralize()}." }
|
doc { f -> "Returns the first ${f.element} yielding the smallest value of the given function or `null` if there are no ${f.element.pluralize()}." }
|
||||||
|
typeParam("T")
|
||||||
typeParam("R : Comparable<R>")
|
typeParam("R : Comparable<R>")
|
||||||
typeParam("T : Any")
|
|
||||||
returns("T?")
|
returns("T?")
|
||||||
body {
|
body {
|
||||||
"""
|
"""
|
||||||
@@ -287,8 +287,8 @@ fun aggregates(): List<GenericFunction> {
|
|||||||
inline(true)
|
inline(true)
|
||||||
|
|
||||||
doc { f -> "Returns the first ${f.element} yielding the largest value of the given function or `null` if there are no ${f.element.pluralize()}." }
|
doc { f -> "Returns the first ${f.element} yielding the largest value of the given function or `null` if there are no ${f.element.pluralize()}." }
|
||||||
|
typeParam("T")
|
||||||
typeParam("R : Comparable<R>")
|
typeParam("R : Comparable<R>")
|
||||||
typeParam("T : Any")
|
|
||||||
returns("T?")
|
returns("T?")
|
||||||
body {
|
body {
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user