From a04f70fb36ee831bb0bda89780c28d01f1108045 Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Tue, 23 Jun 2020 07:20:14 +0300 Subject: [PATCH] Fix min/maxByOrNull function samples --- .../stdlib/common/src/generated/_Arrays.kt | 36 +++++++++---------- .../common/src/generated/_Collections.kt | 4 +-- .../stdlib/common/src/generated/_Maps.kt | 4 +-- .../stdlib/common/src/generated/_Sequences.kt | 4 +-- .../stdlib/common/src/generated/_Strings.kt | 4 +-- .../stdlib/common/src/generated/_UArrays.kt | 16 ++++----- .../test/samples/collections/collections.kt | 12 +++---- .../src/templates/Aggregates.kt | 2 +- 8 files changed, 41 insertions(+), 41 deletions(-) diff --git a/libraries/stdlib/common/src/generated/_Arrays.kt b/libraries/stdlib/common/src/generated/_Arrays.kt index 733db19cf49..8e690e1acbe 100644 --- a/libraries/stdlib/common/src/generated/_Arrays.kt +++ b/libraries/stdlib/common/src/generated/_Arrays.kt @@ -13495,7 +13495,7 @@ public inline fun > 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 > Array.maxByOrNull(selector: (T) -> R): T? { @@ -13518,7 +13518,7 @@ public inline fun > Array.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 > ByteArray.maxByOrNull(selector: (Byte) -> R): Byte? { @@ -13541,7 +13541,7 @@ public inline fun > 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 > ShortArray.maxByOrNull(selector: (Short) -> R): Short? { @@ -13564,7 +13564,7 @@ public inline fun > 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 > IntArray.maxByOrNull(selector: (Int) -> R): Int? { @@ -13587,7 +13587,7 @@ public inline fun > 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 > LongArray.maxByOrNull(selector: (Long) -> R): Long? { @@ -13610,7 +13610,7 @@ public inline fun > 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 > FloatArray.maxByOrNull(selector: (Float) -> R): Float? { @@ -13633,7 +13633,7 @@ public inline fun > 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 > DoubleArray.maxByOrNull(selector: (Double) -> R): Double? { @@ -13656,7 +13656,7 @@ public inline fun > 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 > BooleanArray.maxByOrNull(selector: (Boolean) -> R): Boolean? { @@ -13679,7 +13679,7 @@ public inline fun > 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 > CharArray.maxByOrNull(selector: (Char) -> R): Char? { @@ -15630,7 +15630,7 @@ public inline fun > 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 > Array.minByOrNull(selector: (T) -> R): T? { @@ -15653,7 +15653,7 @@ public inline fun > Array.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 > ByteArray.minByOrNull(selector: (Byte) -> R): Byte? { @@ -15676,7 +15676,7 @@ public inline fun > 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 > ShortArray.minByOrNull(selector: (Short) -> R): Short? { @@ -15699,7 +15699,7 @@ public inline fun > 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 > IntArray.minByOrNull(selector: (Int) -> R): Int? { @@ -15722,7 +15722,7 @@ public inline fun > 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 > LongArray.minByOrNull(selector: (Long) -> R): Long? { @@ -15745,7 +15745,7 @@ public inline fun > 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 > FloatArray.minByOrNull(selector: (Float) -> R): Float? { @@ -15768,7 +15768,7 @@ public inline fun > 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 > DoubleArray.minByOrNull(selector: (Double) -> R): Double? { @@ -15791,7 +15791,7 @@ public inline fun > 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 > BooleanArray.minByOrNull(selector: (Boolean) -> R): Boolean? { @@ -15814,7 +15814,7 @@ public inline fun > 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 > CharArray.minByOrNull(selector: (Char) -> R): Char? { diff --git a/libraries/stdlib/common/src/generated/_Collections.kt b/libraries/stdlib/common/src/generated/_Collections.kt index 8c55855b04c..0c2930ea06c 100644 --- a/libraries/stdlib/common/src/generated/_Collections.kt +++ b/libraries/stdlib/common/src/generated/_Collections.kt @@ -1810,7 +1810,7 @@ public inline fun > Iterable.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 > Iterable.maxByOrNull(selector: (T) -> R): T? { @@ -2100,7 +2100,7 @@ public inline fun > Iterable.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 > Iterable.minByOrNull(selector: (T) -> R): T? { diff --git a/libraries/stdlib/common/src/generated/_Maps.kt b/libraries/stdlib/common/src/generated/_Maps.kt index 99c09fc72cc..4b2a3c910e7 100644 --- a/libraries/stdlib/common/src/generated/_Maps.kt +++ b/libraries/stdlib/common/src/generated/_Maps.kt @@ -188,7 +188,7 @@ public inline fun > Map.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 > Map.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 diff --git a/libraries/stdlib/common/src/generated/_Sequences.kt b/libraries/stdlib/common/src/generated/_Sequences.kt index c3d361e538a..743cb1f5399 100644 --- a/libraries/stdlib/common/src/generated/_Sequences.kt +++ b/libraries/stdlib/common/src/generated/_Sequences.kt @@ -1265,7 +1265,7 @@ public inline fun > Sequence.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 > Sequence.maxByOrNull(selector: (T) -> R): T? { @@ -1581,7 +1581,7 @@ public inline fun > Sequence.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 > Sequence.minByOrNull(selector: (T) -> R): T? { diff --git a/libraries/stdlib/common/src/generated/_Strings.kt b/libraries/stdlib/common/src/generated/_Strings.kt index 3d53488a5f7..f42dbf4efb8 100644 --- a/libraries/stdlib/common/src/generated/_Strings.kt +++ b/libraries/stdlib/common/src/generated/_Strings.kt @@ -1134,7 +1134,7 @@ public inline fun > 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 > CharSequence.maxByOrNull(selector: (Char) -> R): Char? { @@ -1368,7 +1368,7 @@ public inline fun > 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 > CharSequence.minByOrNull(selector: (Char) -> R): Char? { diff --git a/libraries/stdlib/common/src/generated/_UArrays.kt b/libraries/stdlib/common/src/generated/_UArrays.kt index 296846aff5d..2b26bcb185d 100644 --- a/libraries/stdlib/common/src/generated/_UArrays.kt +++ b/libraries/stdlib/common/src/generated/_UArrays.kt @@ -5897,7 +5897,7 @@ public inline fun > 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 > 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 > 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 > 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 > 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 > 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 > 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 > 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 diff --git a/libraries/stdlib/samples/test/samples/collections/collections.kt b/libraries/stdlib/samples/test/samples/collections/collections.kt index eada016804c..96fd924ddb2 100644 --- a/libraries/stdlib/samples/test/samples/collections/collections.kt +++ b/libraries/stdlib/samples/test/samples/collections/collections.kt @@ -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>() - 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() - val emptyMin = emptyList.minBy { it.length } + val emptyMin = emptyList.minByOrNull { it.length } assertPrints(emptyMin, "null") } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt index 6c5a12be1f0..431933d4c60 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt @@ -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 {