diff --git a/libraries/stdlib/api/js-v1/kotlin.collections.kt b/libraries/stdlib/api/js-v1/kotlin.collections.kt index c59bdc05971..366e809d8d5 100644 --- a/libraries/stdlib/api/js-v1/kotlin.collections.kt +++ b/libraries/stdlib/api/js-v1/kotlin.collections.kt @@ -2644,6 +2644,198 @@ public inline fun kotlin.collections.Map.flatMap(transform: @kotlin.jvm.JvmName(name = "flatMapSequence") public inline fun kotlin.collections.Map.flatMap(transform: (kotlin.collections.Map.Entry) -> kotlin.sequences.Sequence): kotlin.collections.List +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.Array.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedSequence") +@kotlin.internal.InlineOnly +public inline fun kotlin.Array.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.BooleanArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Boolean) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.ByteArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Byte) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.CharArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.DoubleArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Double) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.FloatArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Float) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.IntArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Int) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.LongArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Long) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.ShortArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Short) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun kotlin.UByteArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.UByte) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun kotlin.UIntArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.UInt) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun kotlin.ULongArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.ULong) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun kotlin.UShortArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.UShort) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.collections.Iterable.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedSequence") +@kotlin.internal.InlineOnly +public inline fun kotlin.collections.Iterable.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.Array.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedSequenceTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.Array.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.BooleanArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Boolean) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.ByteArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Byte) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.CharArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.DoubleArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Double) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.FloatArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Float) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.IntArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Int) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.LongArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Long) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.ShortArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Short) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun > kotlin.UByteArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.UByte) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun > kotlin.UIntArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.UInt) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun > kotlin.ULongArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.ULong) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun > kotlin.UShortArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.UShort) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.collections.Iterable.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedSequenceTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.collections.Iterable.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence): C + public inline fun > kotlin.Array.flatMapTo(destination: C, transform: (T) -> kotlin.collections.Iterable): C @kotlin.SinceKotlin(version = "1.4") diff --git a/libraries/stdlib/api/js-v1/kotlin.sequences.kt b/libraries/stdlib/api/js-v1/kotlin.sequences.kt index 827131b35c9..2cc5f47a818 100644 --- a/libraries/stdlib/api/js-v1/kotlin.sequences.kt +++ b/libraries/stdlib/api/js-v1/kotlin.sequences.kt @@ -151,6 +151,28 @@ public fun kotlin.sequences.Sequence.flatMap(transform: (T) -> kotlin. public fun kotlin.sequences.Sequence.flatMap(transform: (T) -> kotlin.sequences.Sequence): kotlin.sequences.Sequence +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +public fun kotlin.sequences.Sequence.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable): kotlin.sequences.Sequence + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedSequence") +public fun kotlin.sequences.Sequence.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence): kotlin.sequences.Sequence + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.sequences.Sequence.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedSequenceTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.sequences.Sequence.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence): C + @kotlin.SinceKotlin(version = "1.4") @kotlin.OverloadResolutionByLambdaReturnType @kotlin.jvm.JvmName(name = "flatMapIterableTo") diff --git a/libraries/stdlib/api/js-v1/kotlin.text.kt b/libraries/stdlib/api/js-v1/kotlin.text.kt index d3064fd909b..607a2a72950 100644 --- a/libraries/stdlib/api/js-v1/kotlin.text.kt +++ b/libraries/stdlib/api/js-v1/kotlin.text.kt @@ -263,6 +263,18 @@ public inline fun kotlin.CharSequence.firstOrNull(predicate: (kotlin.Char) -> ko public inline fun kotlin.CharSequence.flatMap(transform: (kotlin.Char) -> kotlin.collections.Iterable): kotlin.collections.List +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.CharSequence.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.CharSequence.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable): C + public inline fun > kotlin.CharSequence.flatMapTo(destination: C, transform: (kotlin.Char) -> kotlin.collections.Iterable): C public inline fun kotlin.CharSequence.fold(initial: R, operation: (acc: R, kotlin.Char) -> R): R diff --git a/libraries/stdlib/api/js/kotlin.collections.kt b/libraries/stdlib/api/js/kotlin.collections.kt index 2e12f1a4891..6886180bc02 100644 --- a/libraries/stdlib/api/js/kotlin.collections.kt +++ b/libraries/stdlib/api/js/kotlin.collections.kt @@ -2614,6 +2614,198 @@ public inline fun kotlin.collections.Map.flatMap(transform: @kotlin.jvm.JvmName(name = "flatMapSequence") public inline fun kotlin.collections.Map.flatMap(transform: (kotlin.collections.Map.Entry) -> kotlin.sequences.Sequence): kotlin.collections.List +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.Array.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedSequence") +@kotlin.internal.InlineOnly +public inline fun kotlin.Array.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.BooleanArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Boolean) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.ByteArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Byte) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.CharArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.DoubleArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Double) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.FloatArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Float) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.IntArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Int) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.LongArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Long) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.ShortArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Short) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun kotlin.UByteArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.UByte) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun kotlin.UIntArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.UInt) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun kotlin.ULongArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.ULong) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun kotlin.UShortArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.UShort) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.collections.Iterable.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedSequence") +@kotlin.internal.InlineOnly +public inline fun kotlin.collections.Iterable.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.Array.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedSequenceTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.Array.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.BooleanArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Boolean) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.ByteArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Byte) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.CharArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.DoubleArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Double) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.FloatArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Float) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.IntArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Int) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.LongArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Long) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.ShortArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Short) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun > kotlin.UByteArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.UByte) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun > kotlin.UIntArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.UInt) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun > kotlin.ULongArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.ULong) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun > kotlin.UShortArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.UShort) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.collections.Iterable.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedSequenceTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.collections.Iterable.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence): C + public inline fun > kotlin.Array.flatMapTo(destination: C, transform: (T) -> kotlin.collections.Iterable): C @kotlin.SinceKotlin(version = "1.4") diff --git a/libraries/stdlib/api/js/kotlin.sequences.kt b/libraries/stdlib/api/js/kotlin.sequences.kt index 827131b35c9..2cc5f47a818 100644 --- a/libraries/stdlib/api/js/kotlin.sequences.kt +++ b/libraries/stdlib/api/js/kotlin.sequences.kt @@ -151,6 +151,28 @@ public fun kotlin.sequences.Sequence.flatMap(transform: (T) -> kotlin. public fun kotlin.sequences.Sequence.flatMap(transform: (T) -> kotlin.sequences.Sequence): kotlin.sequences.Sequence +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +public fun kotlin.sequences.Sequence.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable): kotlin.sequences.Sequence + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedSequence") +public fun kotlin.sequences.Sequence.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence): kotlin.sequences.Sequence + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.sequences.Sequence.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable): C + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedSequenceTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.sequences.Sequence.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence): C + @kotlin.SinceKotlin(version = "1.4") @kotlin.OverloadResolutionByLambdaReturnType @kotlin.jvm.JvmName(name = "flatMapIterableTo") diff --git a/libraries/stdlib/api/js/kotlin.text.kt b/libraries/stdlib/api/js/kotlin.text.kt index d3064fd909b..607a2a72950 100644 --- a/libraries/stdlib/api/js/kotlin.text.kt +++ b/libraries/stdlib/api/js/kotlin.text.kt @@ -263,6 +263,18 @@ public inline fun kotlin.CharSequence.firstOrNull(predicate: (kotlin.Char) -> ko public inline fun kotlin.CharSequence.flatMap(transform: (kotlin.Char) -> kotlin.collections.Iterable): kotlin.collections.List +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun kotlin.CharSequence.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable): kotlin.collections.List + +@kotlin.SinceKotlin(version = "1.4") +@kotlin.OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > kotlin.CharSequence.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable): C + public inline fun > kotlin.CharSequence.flatMapTo(destination: C, transform: (kotlin.Char) -> kotlin.collections.Iterable): C public inline fun kotlin.CharSequence.fold(initial: R, operation: (acc: R, kotlin.Char) -> R): R diff --git a/libraries/stdlib/common/src/generated/_Arrays.kt b/libraries/stdlib/common/src/generated/_Arrays.kt index c31ebe82215..733db19cf49 100644 --- a/libraries/stdlib/common/src/generated/_Arrays.kt +++ b/libraries/stdlib/common/src/generated/_Arrays.kt @@ -10035,6 +10035,336 @@ public inline fun Array.flatMap(transform: (T) -> Sequence): Li return flatMapTo(ArrayList(), transform) } +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun Array.flatMapIndexed(transform: (index: Int, T) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun ByteArray.flatMapIndexed(transform: (index: Int, Byte) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun ShortArray.flatMapIndexed(transform: (index: Int, Short) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun IntArray.flatMapIndexed(transform: (index: Int, Int) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun LongArray.flatMapIndexed(transform: (index: Int, Long) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun FloatArray.flatMapIndexed(transform: (index: Int, Float) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun DoubleArray.flatMapIndexed(transform: (index: Int, Double) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun BooleanArray.flatMapIndexed(transform: (index: Int, Boolean) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun CharArray.flatMapIndexed(transform: (index: Int, Char) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedSequence") +@kotlin.internal.InlineOnly +public inline fun Array.flatMapIndexed(transform: (index: Int, T) -> Sequence): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > Array.flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > ByteArray.flatMapIndexedTo(destination: C, transform: (index: Int, Byte) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > ShortArray.flatMapIndexedTo(destination: C, transform: (index: Int, Short) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > IntArray.flatMapIndexedTo(destination: C, transform: (index: Int, Int) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > LongArray.flatMapIndexedTo(destination: C, transform: (index: Int, Long) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > FloatArray.flatMapIndexedTo(destination: C, transform: (index: Int, Float) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > DoubleArray.flatMapIndexedTo(destination: C, transform: (index: Int, Double) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > BooleanArray.flatMapIndexedTo(destination: C, transform: (index: Int, Boolean) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > CharArray.flatMapIndexedTo(destination: C, transform: (index: Int, Char) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedSequenceTo") +@kotlin.internal.InlineOnly +public inline fun > Array.flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Sequence): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + /** * Appends all elements yielded from results of [transform] function being invoked on each element of original array, to the given [destination]. */ diff --git a/libraries/stdlib/common/src/generated/_Collections.kt b/libraries/stdlib/common/src/generated/_Collections.kt index a271f5e69da..8c55855b04c 100644 --- a/libraries/stdlib/common/src/generated/_Collections.kt +++ b/libraries/stdlib/common/src/generated/_Collections.kt @@ -1299,6 +1299,72 @@ public inline fun Iterable.flatMap(transform: (T) -> Sequence): Lis return flatMapTo(ArrayList(), transform) } +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original collection. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun Iterable.flatMapIndexed(transform: (index: Int, T) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original collection. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedSequence") +@kotlin.internal.InlineOnly +public inline fun Iterable.flatMapIndexed(transform: (index: Int, T) -> Sequence): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original collection, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > Iterable.flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(checkIndexOverflow(index++), element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original collection, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedSequenceTo") +@kotlin.internal.InlineOnly +public inline fun > Iterable.flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Sequence): C { + var index = 0 + for (element in this) { + val list = transform(checkIndexOverflow(index++), element) + destination.addAll(list) + } + return destination +} + /** * Appends all elements yielded from results of [transform] function being invoked on each element of original collection, to the given [destination]. */ diff --git a/libraries/stdlib/common/src/generated/_Sequences.kt b/libraries/stdlib/common/src/generated/_Sequences.kt index 35fd9c0817f..c3d361e538a 100644 --- a/libraries/stdlib/common/src/generated/_Sequences.kt +++ b/libraries/stdlib/common/src/generated/_Sequences.kt @@ -777,7 +777,7 @@ public fun Sequence.toSet(): Set { @OverloadResolutionByLambdaReturnType @kotlin.jvm.JvmName("flatMapIterable") public fun Sequence.flatMap(transform: (T) -> Iterable): Sequence { - return FlatteningSequence(this, transform, { it.iterator() }) + return FlatteningSequence(this, transform, Iterable::iterator) } /** @@ -788,7 +788,79 @@ public fun Sequence.flatMap(transform: (T) -> Iterable): Sequence Sequence.flatMap(transform: (T) -> Sequence): Sequence { - return FlatteningSequence(this, transform, { it.iterator() }) + return FlatteningSequence(this, transform, Sequence::iterator) +} + +/** + * Returns a single sequence of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original sequence. + * + * The operation is _intermediate_ and _stateless_. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterable") +public fun Sequence.flatMapIndexed(transform: (index: Int, T) -> Iterable): Sequence { + return flatMapIndexed(this, transform, Iterable::iterator) +} + +/** + * Returns a single sequence of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original sequence. + * + * The operation is _intermediate_ and _stateless_. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedSequence") +public fun Sequence.flatMapIndexed(transform: (index: Int, T) -> Sequence): Sequence { + return flatMapIndexed(this, transform, Sequence::iterator) +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original sequence, to the given [destination]. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > Sequence.flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(checkIndexOverflow(index++), element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original sequence, to the given [destination]. + * + * The operation is _terminal_. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedSequenceTo") +@kotlin.internal.InlineOnly +public inline fun > Sequence.flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Sequence): C { + var index = 0 + for (element in this) { + val list = transform(checkIndexOverflow(index++), element) + destination.addAll(list) + } + return destination } /** diff --git a/libraries/stdlib/common/src/generated/_Strings.kt b/libraries/stdlib/common/src/generated/_Strings.kt index cb69bbc3441..3d53488a5f7 100644 --- a/libraries/stdlib/common/src/generated/_Strings.kt +++ b/libraries/stdlib/common/src/generated/_Strings.kt @@ -785,6 +785,39 @@ public inline fun CharSequence.flatMap(transform: (Char) -> Iterable): Li return flatMapTo(ArrayList(), transform) } +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each character + * and its index in the original char sequence. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterable") +@kotlin.internal.InlineOnly +public inline fun CharSequence.flatMapIndexed(transform: (index: Int, Char) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each character + * and its index in the original char sequence, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@kotlin.jvm.JvmName("flatMapIndexedIterableTo") +@kotlin.internal.InlineOnly +public inline fun > CharSequence.flatMapIndexedTo(destination: C, transform: (index: Int, Char) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + /** * Appends all elements yielded from results of [transform] function being invoked on each character of original char sequence, to the given [destination]. */ diff --git a/libraries/stdlib/common/src/generated/_UArrays.kt b/libraries/stdlib/common/src/generated/_UArrays.kt index fad236d2970..296846aff5d 100644 --- a/libraries/stdlib/common/src/generated/_UArrays.kt +++ b/libraries/stdlib/common/src/generated/_UArrays.kt @@ -4494,6 +4494,138 @@ public inline fun UShortArray.flatMap(transform: (UShort) -> Iterable): L return flatMapTo(ArrayList(), transform) } +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun UIntArray.flatMapIndexed(transform: (index: Int, UInt) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun ULongArray.flatMapIndexed(transform: (index: Int, ULong) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun UByteArray.flatMapIndexed(transform: (index: Int, UByte) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Returns a single list of all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array. + * + * @sample samples.collections.Collections.Transformations.flatMapIndexed + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun UShortArray.flatMapIndexed(transform: (index: Int, UShort) -> Iterable): List { + return flatMapIndexedTo(ArrayList(), transform) +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun > UIntArray.flatMapIndexedTo(destination: C, transform: (index: Int, UInt) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun > ULongArray.flatMapIndexedTo(destination: C, transform: (index: Int, ULong) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun > UByteArray.flatMapIndexedTo(destination: C, transform: (index: Int, UByte) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + +/** + * Appends all elements yielded from results of [transform] function being invoked on each element + * and its index in the original array, to the given [destination]. + */ +@SinceKotlin("1.4") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +@ExperimentalUnsignedTypes +@kotlin.internal.InlineOnly +public inline fun > UShortArray.flatMapIndexedTo(destination: C, transform: (index: Int, UShort) -> Iterable): C { + var index = 0 + for (element in this) { + val list = transform(index++, element) + destination.addAll(list) + } + return destination +} + /** * Appends all elements yielded from results of [transform] function being invoked on each element of original array, to the given [destination]. */ diff --git a/libraries/stdlib/samples/test/samples/collections/collections.kt b/libraries/stdlib/samples/test/samples/collections/collections.kt index 84745776464..eada016804c 100644 --- a/libraries/stdlib/samples/test/samples/collections/collections.kt +++ b/libraries/stdlib/samples/test/samples/collections/collections.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package samples.collections @@ -549,6 +538,14 @@ class Collections { assertPrints(list.flatMap { it.toList() }, "[1, 2, 3, 4, 5]") } + @Sample + fun flatMapIndexed() { + val data: List = listOf("Abcd", "efgh", "Klmn") + val selected: List = data.map { it.any { c -> c.isUpperCase() } } + val result = data.flatMapIndexed { index, s -> if (selected[index]) s.toList() else emptyList() } + assertPrints(result, "[A, b, c, d, K, l, m, n]") + } + @Sample fun take() { val chars = ('a'..'z').toList() diff --git a/libraries/stdlib/src/kotlin/collections/Sequences.kt b/libraries/stdlib/src/kotlin/collections/Sequences.kt index 3bbef77d77c..11fd0d86c15 100644 --- a/libraries/stdlib/src/kotlin/collections/Sequences.kt +++ b/libraries/stdlib/src/kotlin/collections/Sequences.kt @@ -318,6 +318,15 @@ constructor( } } +internal fun flatMapIndexed(source: Sequence, transform: (Int, T) -> C, iterator: (C) -> Iterator): Sequence = + sequence { + var index = 0 + for (element in source) { + val result = transform(checkIndexOverflow(index++), element) + yieldAll(iterator(result)) + } + } + /** * A sequence that supports drop(n) and take(n) operations */ diff --git a/libraries/stdlib/test/collections/ArraysTest.kt b/libraries/stdlib/test/collections/ArraysTest.kt index 8e5ce863333..b65223050d3 100644 --- a/libraries/stdlib/test/collections/ArraysTest.kt +++ b/libraries/stdlib/test/collections/ArraysTest.kt @@ -1786,6 +1786,15 @@ class ArraysTest { assertEquals(expected, result2) } + @Test fun flatMapIndexed() { + val data = arrayOf(arrayOf(1, 2, 3), arrayOf(4, 5, 6)) + val result1 = data.flatMapIndexed { index, arr -> arr.asList().subList(0, index + 1) } + val result2 = data.flatMapIndexed { index, arr -> arr.asSequence().take(index + 1) } + val expected = listOf(1, 4, 5) + assertEquals(expected, result1) + assertEquals(expected, result2) + } + @Test fun flattenArray() { val arr1: Array> = arrayOf(arrayOf(1, 2, 3), arrayOf(4, 5, 6)) val arr2: Array> = arr1 diff --git a/libraries/stdlib/test/collections/CollectionTest.kt b/libraries/stdlib/test/collections/CollectionTest.kt index 3467bcf2700..d23e1a714fe 100644 --- a/libraries/stdlib/test/collections/CollectionTest.kt +++ b/libraries/stdlib/test/collections/CollectionTest.kt @@ -60,6 +60,16 @@ class CollectionTest { assertEquals(expected, result2) } + @Test fun flatMapIndexed() { + val source = listOf(null, "foo", "bar") + val result1 = source.flatMapIndexed { index, it -> it.orEmpty().take(index + 1).asSequence() } + val result2 = source.flatMapIndexed { index, it -> it.orEmpty().take(index + 1).asIterable() } + + val expected = "fobar".toList() + assertEquals(expected, result1) + assertEquals(expected, result2) + } + /* @Test fun mapNotNull() { val data = listOf(null, "foo", null, "bar") diff --git a/libraries/stdlib/test/collections/SequenceTest.kt b/libraries/stdlib/test/collections/SequenceTest.kt index 5d159bf2ec1..c1d77e34ed5 100644 --- a/libraries/stdlib/test/collections/SequenceTest.kt +++ b/libraries/stdlib/test/collections/SequenceTest.kt @@ -592,6 +592,14 @@ public class SequenceTest { assertEquals(expected, result2.toList()) } + @Test fun flatMapIndexed() { + val result1 = sequenceOf(1, 2).flatMapIndexed { index, v -> (0..v + index).asSequence() } + val result2 = sequenceOf(1, 2).flatMapIndexed { index, v -> 0..v + index } + val expected = listOf(0, 1, 0, 1, 2, 3) + assertEquals(expected, result1.toList()) + assertEquals(expected, result2.toList()) + } + @Test fun flatten() { val expected = listOf(0, 1, 0, 1, 2) diff --git a/libraries/stdlib/test/collections/UnsignedArraysTest.kt b/libraries/stdlib/test/collections/UnsignedArraysTest.kt index e8d82168310..76aa4fe4b91 100644 --- a/libraries/stdlib/test/collections/UnsignedArraysTest.kt +++ b/libraries/stdlib/test/collections/UnsignedArraysTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -981,6 +981,14 @@ class UnsignedArraysTest { assertEquals(listOf(), ulongArrayOf(1, 2, 3).flatMap { listOf() }) } + @Test + fun flatMapIndexed() { + assertEquals(listOf(), ubyteArrayOf().flatMapIndexed { index, _ -> listOf(index) }) + assertEquals(listOf(2, 3, 3), ushortArrayOf(1, 2, 3).flatMapIndexed { index, e -> List(index) { e } }) + assertEquals(listOf(2, 2, 3, 3, 3, 3), uintArrayOf(1, 2, 3).flatMapIndexed { index, e -> List(index * 2) { e } }) + assertEquals(listOf(), ulongArrayOf(1, 2, 3).flatMapIndexed { _, _ -> listOf() }) + } + @Test fun withIndex() { fun assertIterableContentEquals(expected: Iterable, actual: Iterable) { diff --git a/libraries/stdlib/test/text/StringTest.kt b/libraries/stdlib/test/text/StringTest.kt index 3be87e7db33..b89c84e29eb 100644 --- a/libraries/stdlib/test/text/StringTest.kt +++ b/libraries/stdlib/test/text/StringTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -1242,6 +1242,11 @@ class StringTest { assertEquals("a ab abc abcd ".toList(), result) } + @Test fun flatMapIndexed() = withOneCharSequenceArg("bdfi") { data -> + val result = data.flatMapIndexed { index, c -> ('a'..c).drop(index) + ' ' } + assertEquals("ab bcd cdef defghi ".toList(), result) + } + @Test fun fold() = withOneCharSequenceArg { arg1 -> // calculate number of digits in the string val data = arg1("a1b2c3def") diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt index d838cb67107..a7e0267adc5 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt @@ -4880,6 +4880,8 @@ public final class kotlin/sequences/SequencesKt { public static final fun firstOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Object; public static final fun firstOrNull (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun flatMap (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence; + public static final fun flatMapIndexedIterable (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence; + public static final fun flatMapIndexedSequence (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence; public static final fun flatMapIterable (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence; public static final fun flatMapIterableTo (Lkotlin/sequences/Sequence;Ljava/util/Collection;Lkotlin/jvm/functions/Function1;)Ljava/util/Collection; public static final fun flatMapTo (Lkotlin/sequences/Sequence;Ljava/util/Collection;Lkotlin/jvm/functions/Function1;)Ljava/util/Collection; diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt index 3e3f5698ee6..079c9c525fb 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt @@ -311,7 +311,7 @@ object Mapping : TemplateGroupBase() { doc { "Returns a single sequence of all elements from results of [transform] function being invoked on each element of original sequence." } returns("Sequence") body { - "return FlatteningSequence(this, transform, { it.iterator() })" + "return FlatteningSequence(this, transform, Iterable::iterator)" } } } @@ -338,7 +338,7 @@ object Mapping : TemplateGroupBase() { doc { "Returns a single sequence of all elements from results of [transform] function being invoked on each element of original sequence." } returns("Sequence") body { - "return FlatteningSequence(this, transform, { it.iterator() })" + "return FlatteningSequence(this, transform, Sequence::iterator)" } } } @@ -396,70 +396,79 @@ object Mapping : TemplateGroupBase() { } } - val f_flatMapIndexed = fn("flatMapIndexed(transform: (index: Int, T) -> Iterable)") { - includeDefault() - include(Maps, CharSequences, ArraysOfUnsigned) - } builder { - inlineOnly() + val f_flatMapIndexed = listOf(Iterables, Sequences).map { containerFamily -> + val containerClass = containerFamily.name.dropLast(1) + fn("flatMapIndexed(transform: (index: Int, T) -> $containerClass)") { + when (containerFamily) { + Iterables -> include(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences) + Sequences -> include(Sequences, Iterables, ArraysOfObjects) + } + } builder { + inlineOnly() - doc { - """ - Returns a single ${f.mapResult} of all elements yielded from results of [transform] function being invoked on each ${f.element} - and its index in the original ${f.collection}. - """ - } - sample("samples.collections.Collections.Transformations.flatMap") - typeParam("R") - returns("List") - body { - "return flatMapIndexedTo(ArrayList(), transform)" - } - specialFor(Sequences) { - inline(Inline.No) - signature("flatMapIndexed(transform: (index: Int, T) -> Sequence)") - returns("Sequence") + since("1.4") + doc { + """ + Returns a single ${f.mapResult} of all elements yielded from results of [transform] function being invoked on each ${f.element} + and its index in the original ${f.collection}. + """ + } + annotation("@OptIn(kotlin.experimental.ExperimentalTypeInference::class)") + annotation("@OverloadResolutionByLambdaReturnType") + if (family != ArraysOfUnsigned) + annotation("""@kotlin.jvm.JvmName("flatMapIndexed$containerClass")""") + sample("samples.collections.Collections.Transformations.flatMapIndexed") + typeParam("R") + returns("List") body { - """ - return sequence { - var index = 0 - for (element in this@flatMapIndexed) { - val result = transform(checkIndexOverflow(index++), element) - for (r in result) yield(r) - } + "return flatMapIndexedTo(ArrayList(), transform)" + } + specialFor(Sequences) { + inline(Inline.No) + returns("Sequence") + body { + "return flatMapIndexed(this, transform, $containerClass::iterator)" } - """ } } } - val f_flatMapIndexedTo = fn("flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Iterable)") { - includeDefault() - include(Maps, CharSequences, ArraysOfUnsigned) - } builder { - inlineOnly() - doc { - """ - Appends all elements yielded from results of [transform] function being invoked on each ${f.element} - and its index in the original ${f.collection}, to the given [destination]. - """ - } - specialFor(Sequences) { - signature("flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Sequence)") - } - typeParam("R") - typeParam("C : MutableCollection") - returns("C") - body { - fun checkOverflow(value: String) = if (f == Sequences || f == Iterables) "checkIndexOverflow($value)" else value - """ - var index = 0 - for (element in this) { - val list = transform(${checkOverflow("index++")}, element) - destination.addAll(list) + val f_flatMapIndexedTo = listOf(Iterables, Sequences).map { containerFamily -> + val containerClass = containerFamily.name.dropLast(1) + fn("flatMapIndexedTo(destination: C, transform: (index: Int, T) -> $containerClass)") { + when (containerFamily) { + Iterables -> include(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences) + Sequences -> include(Sequences, Iterables, ArraysOfObjects) + } + } builder { + inlineOnly() + + since("1.4") + doc { + """ + Appends all elements yielded from results of [transform] function being invoked on each ${f.element} + and its index in the original ${f.collection}, to the given [destination]. + """ + } + annotation("@OptIn(kotlin.experimental.ExperimentalTypeInference::class)") + annotation("@OverloadResolutionByLambdaReturnType") + if (family != ArraysOfUnsigned) + annotation("""@kotlin.jvm.JvmName("flatMapIndexed${containerClass}To")""") + typeParam("R") + typeParam("C : MutableCollection") + returns("C") + body { + fun checkOverflow(value: String) = if (f == Sequences || f == Iterables) "checkIndexOverflow($value)" else value + """ + var index = 0 + for (element in this) { + val list = transform(${checkOverflow("index++")}, element) + destination.addAll(list) + } + return destination + """ } - return destination - """ } }