Fix min/maxByOrNull function samples
This commit is contained in:
@@ -13495,7 +13495,7 @@ public inline fun <R : Comparable<R>> CharArray.maxBy(selector: (Char) -> R): Ch
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <T, R : Comparable<R>> Array<out T>.maxByOrNull(selector: (T) -> R): T? {
|
||||
@@ -13518,7 +13518,7 @@ public inline fun <T, R : Comparable<R>> Array<out T>.maxByOrNull(selector: (T)
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> ByteArray.maxByOrNull(selector: (Byte) -> R): Byte? {
|
||||
@@ -13541,7 +13541,7 @@ public inline fun <R : Comparable<R>> ByteArray.maxByOrNull(selector: (Byte) ->
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> ShortArray.maxByOrNull(selector: (Short) -> R): Short? {
|
||||
@@ -13564,7 +13564,7 @@ public inline fun <R : Comparable<R>> ShortArray.maxByOrNull(selector: (Short) -
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> IntArray.maxByOrNull(selector: (Int) -> R): Int? {
|
||||
@@ -13587,7 +13587,7 @@ public inline fun <R : Comparable<R>> IntArray.maxByOrNull(selector: (Int) -> R)
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> LongArray.maxByOrNull(selector: (Long) -> R): Long? {
|
||||
@@ -13610,7 +13610,7 @@ public inline fun <R : Comparable<R>> LongArray.maxByOrNull(selector: (Long) ->
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> FloatArray.maxByOrNull(selector: (Float) -> R): Float? {
|
||||
@@ -13633,7 +13633,7 @@ public inline fun <R : Comparable<R>> FloatArray.maxByOrNull(selector: (Float) -
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> DoubleArray.maxByOrNull(selector: (Double) -> R): Double? {
|
||||
@@ -13656,7 +13656,7 @@ public inline fun <R : Comparable<R>> DoubleArray.maxByOrNull(selector: (Double)
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> BooleanArray.maxByOrNull(selector: (Boolean) -> R): Boolean? {
|
||||
@@ -13679,7 +13679,7 @@ public inline fun <R : Comparable<R>> BooleanArray.maxByOrNull(selector: (Boolea
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> CharArray.maxByOrNull(selector: (Char) -> R): Char? {
|
||||
@@ -15630,7 +15630,7 @@ public inline fun <R : Comparable<R>> CharArray.minBy(selector: (Char) -> R): Ch
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <T, R : Comparable<R>> Array<out T>.minByOrNull(selector: (T) -> R): T? {
|
||||
@@ -15653,7 +15653,7 @@ public inline fun <T, R : Comparable<R>> Array<out T>.minByOrNull(selector: (T)
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> ByteArray.minByOrNull(selector: (Byte) -> R): Byte? {
|
||||
@@ -15676,7 +15676,7 @@ public inline fun <R : Comparable<R>> ByteArray.minByOrNull(selector: (Byte) ->
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> ShortArray.minByOrNull(selector: (Short) -> R): Short? {
|
||||
@@ -15699,7 +15699,7 @@ public inline fun <R : Comparable<R>> ShortArray.minByOrNull(selector: (Short) -
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> IntArray.minByOrNull(selector: (Int) -> R): Int? {
|
||||
@@ -15722,7 +15722,7 @@ public inline fun <R : Comparable<R>> IntArray.minByOrNull(selector: (Int) -> R)
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> LongArray.minByOrNull(selector: (Long) -> R): Long? {
|
||||
@@ -15745,7 +15745,7 @@ public inline fun <R : Comparable<R>> LongArray.minByOrNull(selector: (Long) ->
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> FloatArray.minByOrNull(selector: (Float) -> R): Float? {
|
||||
@@ -15768,7 +15768,7 @@ public inline fun <R : Comparable<R>> FloatArray.minByOrNull(selector: (Float) -
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> DoubleArray.minByOrNull(selector: (Double) -> R): Double? {
|
||||
@@ -15791,7 +15791,7 @@ public inline fun <R : Comparable<R>> DoubleArray.minByOrNull(selector: (Double)
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> BooleanArray.minByOrNull(selector: (Boolean) -> R): Boolean? {
|
||||
@@ -15814,7 +15814,7 @@ public inline fun <R : Comparable<R>> BooleanArray.minByOrNull(selector: (Boolea
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> CharArray.minByOrNull(selector: (Char) -> R): Char? {
|
||||
|
||||
@@ -1810,7 +1810,7 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.maxBy(selector: (T) -> R):
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <T, R : Comparable<R>> Iterable<T>.maxByOrNull(selector: (T) -> R): T? {
|
||||
@@ -2100,7 +2100,7 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.minBy(selector: (T) -> R):
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <T, R : Comparable<R>> Iterable<T>.minByOrNull(selector: (T) -> R): T? {
|
||||
|
||||
@@ -188,7 +188,7 @@ public inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxBy(selector: (Map.E
|
||||
/**
|
||||
* Returns the first entry yielding the largest value of the given function or `null` if there are no entries.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@kotlin.internal.InlineOnly
|
||||
@@ -331,7 +331,7 @@ public inline fun <K, V, R : Comparable<R>> Map<out K, V>.minBy(selector: (Map.E
|
||||
/**
|
||||
* Returns the first entry yielding the smallest value of the given function or `null` if there are no entries.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@kotlin.internal.InlineOnly
|
||||
|
||||
@@ -1265,7 +1265,7 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.maxBy(selector: (T) -> R):
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <T, R : Comparable<R>> Sequence<T>.maxByOrNull(selector: (T) -> R): T? {
|
||||
@@ -1581,7 +1581,7 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.minBy(selector: (T) -> R):
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <T, R : Comparable<R>> Sequence<T>.minByOrNull(selector: (T) -> R): T? {
|
||||
|
||||
@@ -1134,7 +1134,7 @@ public inline fun <R : Comparable<R>> CharSequence.maxBy(selector: (Char) -> R):
|
||||
/**
|
||||
* Returns the first character yielding the largest value of the given function or `null` if there are no characters.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> CharSequence.maxByOrNull(selector: (Char) -> R): Char? {
|
||||
@@ -1368,7 +1368,7 @@ public inline fun <R : Comparable<R>> CharSequence.minBy(selector: (Char) -> R):
|
||||
/**
|
||||
* Returns the first character yielding the smallest value of the given function or `null` if there are no characters.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public inline fun <R : Comparable<R>> CharSequence.minByOrNull(selector: (Char) -> R): Char? {
|
||||
|
||||
@@ -5897,7 +5897,7 @@ public inline fun <R : Comparable<R>> UShortArray.maxBy(selector: (UShort) -> R)
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
@@ -5922,7 +5922,7 @@ public inline fun <R : Comparable<R>> UIntArray.maxByOrNull(selector: (UInt) ->
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
@@ -5947,7 +5947,7 @@ public inline fun <R : Comparable<R>> ULongArray.maxByOrNull(selector: (ULong) -
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
@@ -5972,7 +5972,7 @@ public inline fun <R : Comparable<R>> UByteArray.maxByOrNull(selector: (UByte) -
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.maxBy
|
||||
* @sample samples.collections.Collections.Aggregates.maxByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
@@ -6909,7 +6909,7 @@ public inline fun <R : Comparable<R>> UShortArray.minBy(selector: (UShort) -> R)
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
@@ -6934,7 +6934,7 @@ public inline fun <R : Comparable<R>> UIntArray.minByOrNull(selector: (UInt) ->
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
@@ -6959,7 +6959,7 @@ public inline fun <R : Comparable<R>> ULongArray.minByOrNull(selector: (ULong) -
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
@@ -6984,7 +6984,7 @@ public inline fun <R : Comparable<R>> UByteArray.minByOrNull(selector: (UByte) -
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*
|
||||
* @sample samples.collections.Collections.Aggregates.minBy
|
||||
* @sample samples.collections.Collections.Aggregates.minByOrNull
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
@@ -652,24 +652,24 @@ class Collections {
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun maxBy() {
|
||||
fun maxByOrNull() {
|
||||
val nameToAge = listOf("Alice" to 42, "Bob" to 28, "Carol" to 51)
|
||||
val oldestPerson = nameToAge.maxBy { it.second }
|
||||
val oldestPerson = nameToAge.maxByOrNull { it.second }
|
||||
assertPrints(oldestPerson, "(Carol, 51)")
|
||||
|
||||
val emptyList = emptyList<Pair<String, Int>>()
|
||||
val emptyMax = emptyList.maxBy { it.second }
|
||||
val emptyMax = emptyList.maxByOrNull { it.second }
|
||||
assertPrints(emptyMax, "null")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun minBy() {
|
||||
fun minByOrNull() {
|
||||
val list = listOf("abcd", "abc", "ab", "abcde")
|
||||
val shortestString = list.minBy { it.length }
|
||||
val shortestString = list.minByOrNull { it.length }
|
||||
assertPrints(shortestString, "ab")
|
||||
|
||||
val emptyList = emptyList<String>()
|
||||
val emptyMin = emptyList.minBy { it.length }
|
||||
val emptyMin = emptyList.minByOrNull { it.length }
|
||||
assertPrints(emptyMin, "null")
|
||||
}
|
||||
|
||||
|
||||
@@ -399,7 +399,7 @@ object Aggregates : TemplateGroupBase() {
|
||||
since("1.4")
|
||||
|
||||
doc { "Returns the first ${f.element} yielding the ${if (op == "maxBy") "largest" else "smallest"} value of the given function or `null` if there are no ${f.element.pluralize()}." }
|
||||
sample("samples.collections.Collections.Aggregates.$op")
|
||||
sample("samples.collections.Collections.Aggregates.$op$orNull")
|
||||
|
||||
val (elem, value, cmp) = if (op == "minBy") Triple("minElem", "minValue", ">") else Triple("maxElem", "maxValue", "<")
|
||||
body {
|
||||
|
||||
Reference in New Issue
Block a user