diff --git a/libraries/stdlib/common/src/generated/_Arrays.kt b/libraries/stdlib/common/src/generated/_Arrays.kt index d3b7e9c5bd0..16a879f12d9 100644 --- a/libraries/stdlib/common/src/generated/_Arrays.kt +++ b/libraries/stdlib/common/src/generated/_Arrays.kt @@ -826,6 +826,8 @@ public inline fun CharArray.elementAtOrNull(index: Int): Char? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun Array.find(predicate: (T) -> Boolean): T? { @@ -834,6 +836,8 @@ public inline fun Array.find(predicate: (T) -> Boolean): T? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun ByteArray.find(predicate: (Byte) -> Boolean): Byte? { @@ -842,6 +846,8 @@ public inline fun ByteArray.find(predicate: (Byte) -> Boolean): Byte? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun ShortArray.find(predicate: (Short) -> Boolean): Short? { @@ -850,6 +856,8 @@ public inline fun ShortArray.find(predicate: (Short) -> Boolean): Short? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun IntArray.find(predicate: (Int) -> Boolean): Int? { @@ -858,6 +866,8 @@ public inline fun IntArray.find(predicate: (Int) -> Boolean): Int? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun LongArray.find(predicate: (Long) -> Boolean): Long? { @@ -866,6 +876,8 @@ public inline fun LongArray.find(predicate: (Long) -> Boolean): Long? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun FloatArray.find(predicate: (Float) -> Boolean): Float? { @@ -874,6 +886,8 @@ public inline fun FloatArray.find(predicate: (Float) -> Boolean): Float? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun DoubleArray.find(predicate: (Double) -> Boolean): Double? { @@ -882,6 +896,8 @@ public inline fun DoubleArray.find(predicate: (Double) -> Boolean): Double? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun BooleanArray.find(predicate: (Boolean) -> Boolean): Boolean? { @@ -890,6 +906,8 @@ public inline fun BooleanArray.find(predicate: (Boolean) -> Boolean): Boolean? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun CharArray.find(predicate: (Char) -> Boolean): Char? { @@ -898,6 +916,8 @@ public inline fun CharArray.find(predicate: (Char) -> Boolean): Char? { /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun Array.findLast(predicate: (T) -> Boolean): T? { @@ -906,6 +926,8 @@ public inline fun Array.findLast(predicate: (T) -> Boolean): T? { /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun ByteArray.findLast(predicate: (Byte) -> Boolean): Byte? { @@ -914,6 +936,8 @@ public inline fun ByteArray.findLast(predicate: (Byte) -> Boolean): Byte? { /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun ShortArray.findLast(predicate: (Short) -> Boolean): Short? { @@ -922,6 +946,8 @@ public inline fun ShortArray.findLast(predicate: (Short) -> Boolean): Short? { /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun IntArray.findLast(predicate: (Int) -> Boolean): Int? { @@ -930,6 +956,8 @@ public inline fun IntArray.findLast(predicate: (Int) -> Boolean): Int? { /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun LongArray.findLast(predicate: (Long) -> Boolean): Long? { @@ -938,6 +966,8 @@ public inline fun LongArray.findLast(predicate: (Long) -> Boolean): Long? { /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun FloatArray.findLast(predicate: (Float) -> Boolean): Float? { @@ -946,6 +976,8 @@ public inline fun FloatArray.findLast(predicate: (Float) -> Boolean): Float? { /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun DoubleArray.findLast(predicate: (Double) -> Boolean): Double? { @@ -954,6 +986,8 @@ public inline fun DoubleArray.findLast(predicate: (Double) -> Boolean): Double? /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun BooleanArray.findLast(predicate: (Boolean) -> Boolean): Boolean? { @@ -962,6 +996,8 @@ public inline fun BooleanArray.findLast(predicate: (Boolean) -> Boolean): Boolea /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun CharArray.findLast(predicate: (Char) -> Boolean): Char? { @@ -1348,6 +1384,8 @@ public inline fun CharArray.getOrElse(index: Int, defaultValue: (Int) -> Char): /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array. + * + * @sample samples.collections.Collections.Elements.getOrNull */ public fun Array.getOrNull(index: Int): T? { return if (index >= 0 && index <= lastIndex) get(index) else null @@ -1355,6 +1393,8 @@ public fun Array.getOrNull(index: Int): T? { /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array. + * + * @sample samples.collections.Collections.Elements.getOrNull */ public fun ByteArray.getOrNull(index: Int): Byte? { return if (index >= 0 && index <= lastIndex) get(index) else null @@ -1362,6 +1402,8 @@ public fun ByteArray.getOrNull(index: Int): Byte? { /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array. + * + * @sample samples.collections.Collections.Elements.getOrNull */ public fun ShortArray.getOrNull(index: Int): Short? { return if (index >= 0 && index <= lastIndex) get(index) else null @@ -1369,6 +1411,8 @@ public fun ShortArray.getOrNull(index: Int): Short? { /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array. + * + * @sample samples.collections.Collections.Elements.getOrNull */ public fun IntArray.getOrNull(index: Int): Int? { return if (index >= 0 && index <= lastIndex) get(index) else null @@ -1376,6 +1420,8 @@ public fun IntArray.getOrNull(index: Int): Int? { /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array. + * + * @sample samples.collections.Collections.Elements.getOrNull */ public fun LongArray.getOrNull(index: Int): Long? { return if (index >= 0 && index <= lastIndex) get(index) else null @@ -1383,6 +1429,8 @@ public fun LongArray.getOrNull(index: Int): Long? { /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array. + * + * @sample samples.collections.Collections.Elements.getOrNull */ public fun FloatArray.getOrNull(index: Int): Float? { return if (index >= 0 && index <= lastIndex) get(index) else null @@ -1390,6 +1438,8 @@ public fun FloatArray.getOrNull(index: Int): Float? { /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array. + * + * @sample samples.collections.Collections.Elements.getOrNull */ public fun DoubleArray.getOrNull(index: Int): Double? { return if (index >= 0 && index <= lastIndex) get(index) else null @@ -1397,6 +1447,8 @@ public fun DoubleArray.getOrNull(index: Int): Double? { /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array. + * + * @sample samples.collections.Collections.Elements.getOrNull */ public fun BooleanArray.getOrNull(index: Int): Boolean? { return if (index >= 0 && index <= lastIndex) get(index) else null @@ -1404,6 +1456,8 @@ public fun BooleanArray.getOrNull(index: Int): Boolean? { /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array. + * + * @sample samples.collections.Collections.Elements.getOrNull */ public fun CharArray.getOrNull(index: Int): Char? { return if (index >= 0 && index <= lastIndex) get(index) else null @@ -11465,6 +11519,8 @@ public inline fun > CharArray.mapIndexedTo(destin /** * Returns a list containing only the non-null results of applying the given [transform] function * to each element in the original array. + * + * @sample samples.collections.Collections.Transformations.mapNotNull */ public inline fun Array.mapNotNull(transform: (T) -> R?): List { return mapNotNullTo(ArrayList(), transform) diff --git a/libraries/stdlib/common/src/generated/_Collections.kt b/libraries/stdlib/common/src/generated/_Collections.kt index 35a0b98bb65..1816156f3a8 100644 --- a/libraries/stdlib/common/src/generated/_Collections.kt +++ b/libraries/stdlib/common/src/generated/_Collections.kt @@ -159,6 +159,8 @@ public inline fun List.elementAtOrNull(index: Int): T? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun Iterable.find(predicate: (T) -> Boolean): T? { @@ -167,6 +169,8 @@ public inline fun Iterable.find(predicate: (T) -> Boolean): T? { /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun Iterable.findLast(predicate: (T) -> Boolean): T? { @@ -175,6 +179,8 @@ public inline fun Iterable.findLast(predicate: (T) -> Boolean): T? { /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun List.findLast(predicate: (T) -> Boolean): T? { @@ -261,6 +267,8 @@ public inline fun List.getOrElse(index: Int, defaultValue: (Int) -> T): T /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this list. + * + * @sample samples.collections.Collections.Elements.getOrNull */ public fun List.getOrNull(index: Int): T? { return if (index >= 0 && index <= lastIndex) get(index) else null @@ -1536,6 +1544,8 @@ public inline fun > Iterable.mapIndexedTo(d /** * Returns a list containing only the non-null results of applying the given [transform] function * to each element in the original collection. + * + * @sample samples.collections.Collections.Transformations.mapNotNull */ public inline fun Iterable.mapNotNull(transform: (T) -> R?): List { return mapNotNullTo(ArrayList(), transform) diff --git a/libraries/stdlib/common/src/generated/_Maps.kt b/libraries/stdlib/common/src/generated/_Maps.kt index 1c797570b44..ea5229ae72f 100644 --- a/libraries/stdlib/common/src/generated/_Maps.kt +++ b/libraries/stdlib/common/src/generated/_Maps.kt @@ -98,6 +98,8 @@ public inline fun Map.map(transform: (Map.Entry) -> R) /** * Returns a list containing only the non-null results of applying the given [transform] function * to each entry in the original map. + * + * @sample samples.collections.Maps.Transformations.mapNotNull */ public inline fun Map.mapNotNull(transform: (Map.Entry) -> R?): List { return mapNotNullTo(ArrayList(), transform) diff --git a/libraries/stdlib/common/src/generated/_Sequences.kt b/libraries/stdlib/common/src/generated/_Sequences.kt index fff94d8a5a5..b1ccb2d1536 100644 --- a/libraries/stdlib/common/src/generated/_Sequences.kt +++ b/libraries/stdlib/common/src/generated/_Sequences.kt @@ -79,6 +79,8 @@ public fun Sequence.elementAtOrNull(index: Int): T? { * Returns the first element matching the given [predicate], or `null` if no such element was found. * * The operation is _terminal_. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun Sequence.find(predicate: (T) -> Boolean): T? { @@ -89,6 +91,8 @@ public inline fun Sequence.find(predicate: (T) -> Boolean): T? { * Returns the last element matching the given [predicate], or `null` if no such element was found. * * The operation is _terminal_. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun Sequence.findLast(predicate: (T) -> Boolean): T? { @@ -1060,6 +1064,8 @@ public inline fun > Sequence.mapIndexedTo(d * to each element in the original sequence. * * The operation is _intermediate_ and _stateless_. + * + * @sample samples.collections.Collections.Transformations.mapNotNull */ public fun Sequence.mapNotNull(transform: (T) -> R?): Sequence { return TransformingSequence(this, transform).filterNotNull() diff --git a/libraries/stdlib/common/src/generated/_Strings.kt b/libraries/stdlib/common/src/generated/_Strings.kt index 8409923bf3d..af555f2b813 100644 --- a/libraries/stdlib/common/src/generated/_Strings.kt +++ b/libraries/stdlib/common/src/generated/_Strings.kt @@ -44,6 +44,8 @@ public inline fun CharSequence.elementAtOrNull(index: Int): Char? { /** * Returns the first character matching the given [predicate], or `null` if no such character was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun CharSequence.find(predicate: (Char) -> Boolean): Char? { @@ -52,6 +54,8 @@ public inline fun CharSequence.find(predicate: (Char) -> Boolean): Char? { /** * Returns the last character matching the given [predicate], or `null` if no such character was found. + * + * @sample samples.collections.Collections.Elements.find */ @kotlin.internal.InlineOnly public inline fun CharSequence.findLast(predicate: (Char) -> Boolean): Char? { @@ -102,6 +106,8 @@ public inline fun CharSequence.getOrElse(index: Int, defaultValue: (Int) -> Char /** * Returns a character at the given [index] or `null` if the [index] is out of bounds of this char sequence. + * + * @sample samples.collections.Collections.Elements.getOrNull */ public fun CharSequence.getOrNull(index: Int): Char? { return if (index >= 0 && index <= lastIndex) get(index) else null @@ -970,6 +976,8 @@ public inline fun > CharSequence.mapIndexedTo(des /** * Returns a list containing only the non-null results of applying the given [transform] function * to each character in the original char sequence. + * + * @sample samples.collections.Collections.Transformations.mapNotNull */ public inline fun CharSequence.mapNotNull(transform: (Char) -> R?): List { return mapNotNullTo(ArrayList(), transform) diff --git a/libraries/stdlib/common/src/generated/_UArrays.kt b/libraries/stdlib/common/src/generated/_UArrays.kt index 0809417f6bb..271977e22e7 100644 --- a/libraries/stdlib/common/src/generated/_UArrays.kt +++ b/libraries/stdlib/common/src/generated/_UArrays.kt @@ -412,6 +412,8 @@ public inline fun UShortArray.elementAtOrNull(index: Int): UShort? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -422,6 +424,8 @@ public inline fun UIntArray.find(predicate: (UInt) -> Boolean): UInt? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -432,6 +436,8 @@ public inline fun ULongArray.find(predicate: (ULong) -> Boolean): ULong? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -442,6 +448,8 @@ public inline fun UByteArray.find(predicate: (UByte) -> Boolean): UByte? { /** * Returns the first element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -452,6 +460,8 @@ public inline fun UShortArray.find(predicate: (UShort) -> Boolean): UShort? { /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -462,6 +472,8 @@ public inline fun UIntArray.findLast(predicate: (UInt) -> Boolean): UInt? { /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -472,6 +484,8 @@ public inline fun ULongArray.findLast(predicate: (ULong) -> Boolean): ULong? { /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -482,6 +496,8 @@ public inline fun UByteArray.findLast(predicate: (UByte) -> Boolean): UByte? { /** * Returns the last element matching the given [predicate], or `null` if no such element was found. + * + * @sample samples.collections.Collections.Elements.find */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -704,6 +720,8 @@ public inline fun UShortArray.getOrElse(index: Int, defaultValue: (Int) -> UShor /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array. + * + * @sample samples.collections.Collections.Elements.getOrNull */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -713,6 +731,8 @@ public fun UIntArray.getOrNull(index: Int): UInt? { /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array. + * + * @sample samples.collections.Collections.Elements.getOrNull */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -722,6 +742,8 @@ public fun ULongArray.getOrNull(index: Int): ULong? { /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array. + * + * @sample samples.collections.Collections.Elements.getOrNull */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -731,6 +753,8 @@ public fun UByteArray.getOrNull(index: Int): UByte? { /** * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array. + * + * @sample samples.collections.Collections.Elements.getOrNull */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes diff --git a/libraries/stdlib/samples/test/samples/collections/collections.kt b/libraries/stdlib/samples/test/samples/collections/collections.kt index 61dc2039e09..0c7d7fc7be3 100644 --- a/libraries/stdlib/samples/test/samples/collections/collections.kt +++ b/libraries/stdlib/samples/test/samples/collections/collections.kt @@ -532,6 +532,15 @@ class Collections { assertPrints(numbers.map { it * it }, "[1, 4, 9]") } + @Sample + fun mapNotNull() { + val strings: List = listOf("12a", "45", "", "3") + val ints: List = strings.mapNotNull { it.toIntOrNull() } + + assertPrints(ints, "[45, 3]") + assertPrints(ints.sum(), "48") + } + @Sample fun flatMap() { val list = listOf("123", "45") @@ -770,6 +779,27 @@ class Collections { val emptyList = emptyList() assertPrints(emptyList.elementAtOrElse(0) { "no int" }, "no int") } + + @Sample + fun find() { + val numbers = listOf(1, 2, 3, 4, 5, 6, 7) + val firstOdd = numbers.find { it % 2 != 0 } + val lastEven = numbers.findLast { it % 2 == 0 } + + assertPrints(firstOdd, "1") + assertPrints(lastEven, "6") + } + + @Sample + fun getOrNull() { + val list = listOf(1, 2, 3) + assertPrints(list.getOrNull(0), "1") + assertPrints(list.getOrNull(2), "3") + assertPrints(list.getOrNull(3), "null") + + val emptyList = emptyList() + assertPrints(emptyList.getOrNull(0), "null") + } } class Sorting { diff --git a/libraries/stdlib/samples/test/samples/collections/maps.kt b/libraries/stdlib/samples/test/samples/collections/maps.kt index b0e4f3675c9..8165bc3a756 100644 --- a/libraries/stdlib/samples/test/samples/collections/maps.kt +++ b/libraries/stdlib/samples/test/samples/collections/maps.kt @@ -325,6 +325,14 @@ class Maps { assertPrints(map2, "{beverage=2.7$, meal=12.4$}") } + @Sample + fun mapNotNull() { + val map = mapOf("Alice" to 20, "Tom" to 13, "Bob" to 18) + val adults = map.mapNotNull { (name, age) -> name.takeIf { age >= 18 } } + + assertPrints(adults, "[Alice, Bob]") + } + @Sample fun mapToSortedMap() { val map = mapOf(Pair("c", 3), Pair("b", 2), Pair("d", 1)) diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt index e645c30dacd..79050071b25 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt @@ -429,6 +429,7 @@ object Elements : TemplateGroupBase() { include(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) } builder { doc { "Returns ${f.element.prefixWithArticle()} at the given [index] or `null` if the [index] is out of bounds of this ${f.collection}." } + sample("samples.collections.Collections.Elements.getOrNull") returns("T?") body { """ @@ -561,6 +562,7 @@ object Elements : TemplateGroupBase() { } builder { inline(Inline.Only) doc { "Returns the first ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." } + sample("samples.collections.Collections.Elements.find") returns("T?") body { "return firstOrNull(predicate)"} } @@ -755,6 +757,7 @@ object Elements : TemplateGroupBase() { } builder { inline(Inline.Only) doc { "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." } + sample("samples.collections.Collections.Elements.find") returns("T?") body { "return lastOrNull(predicate)"} } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt index 079c9c525fb..97c2dbd9d47 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt @@ -141,6 +141,13 @@ object Mapping : TemplateGroupBase() { to each ${f.element} in the original ${f.collection}. """ } + + fun sampleClass(f: Family): String = when (f) { + Maps -> "samples.collections.Maps.Transformations" + else -> "samples.collections.Collections.Transformations" + } + sample("${sampleClass(f)}.mapNotNull") + body { "return mapNotNullTo(ArrayList(), transform)" }