Provide flatMapIndexed operation

- similar to flatMap, but transform function takes index and element

#KT-36894
This commit is contained in:
Ilya Gorbunov
2020-06-19 16:16:55 +03:00
parent db93462bcf
commit 130987fa1e
20 changed files with 1216 additions and 74 deletions
@@ -2644,6 +2644,198 @@ public inline fun <K, V, R> kotlin.collections.Map<out K, V>.flatMap(transform:
@kotlin.jvm.JvmName(name = "flatMapSequence")
public inline fun <K, V, R> kotlin.collections.Map<out K, V>.flatMap(transform: (kotlin.collections.Map.Entry<K, V>) -> kotlin.sequences.Sequence<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <T, R> kotlin.Array<out T>.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedSequence")
@kotlin.internal.InlineOnly
public inline fun <T, R> kotlin.Array<out T>.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.BooleanArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Boolean) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.ByteArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Byte) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.CharArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.DoubleArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Double) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.FloatArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Float) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.IntArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Int) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.LongArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Long) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.ShortArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Short) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.UByteArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.UByte) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.UIntArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.UInt) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.ULongArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.ULong) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.UShortArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.UShort) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <T, R> kotlin.collections.Iterable<T>.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedSequence")
@kotlin.internal.InlineOnly
public inline fun <T, R> kotlin.collections.Iterable<T>.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.Array<out T>.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedSequenceTo")
@kotlin.internal.InlineOnly
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.Array<out T>.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.BooleanArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Boolean) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.ByteArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Byte) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.CharArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.DoubleArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Double) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.FloatArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Float) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.IntArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Int) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.LongArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Long) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.ShortArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Short) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.UByteArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.UByte) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.UIntArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.UInt) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.ULongArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.ULong) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.UShortArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.UShort) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.collections.Iterable<T>.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedSequenceTo")
@kotlin.internal.InlineOnly
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.collections.Iterable<T>.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence<R>): C
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.Array<out T>.flatMapTo(destination: C, transform: (T) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@@ -151,6 +151,28 @@ public fun <T, R> kotlin.sequences.Sequence<T>.flatMap(transform: (T) -> kotlin.
public fun <T, R> kotlin.sequences.Sequence<T>.flatMap(transform: (T) -> kotlin.sequences.Sequence<R>): kotlin.sequences.Sequence<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
public fun <T, R> kotlin.sequences.Sequence<T>.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable<R>): kotlin.sequences.Sequence<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedSequence")
public fun <T, R> kotlin.sequences.Sequence<T>.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence<R>): kotlin.sequences.Sequence<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.sequences.Sequence<T>.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedSequenceTo")
@kotlin.internal.InlineOnly
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.sequences.Sequence<T>.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIterableTo")
+12
View File
@@ -263,6 +263,18 @@ public inline fun kotlin.CharSequence.firstOrNull(predicate: (kotlin.Char) -> ko
public inline fun <R> kotlin.CharSequence.flatMap(transform: (kotlin.Char) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.CharSequence.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.CharSequence.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable<R>): C
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.CharSequence.flatMapTo(destination: C, transform: (kotlin.Char) -> kotlin.collections.Iterable<R>): C
public inline fun <R> kotlin.CharSequence.fold(initial: R, operation: (acc: R, kotlin.Char) -> R): R
@@ -2614,6 +2614,198 @@ public inline fun <K, V, R> kotlin.collections.Map<out K, V>.flatMap(transform:
@kotlin.jvm.JvmName(name = "flatMapSequence")
public inline fun <K, V, R> kotlin.collections.Map<out K, V>.flatMap(transform: (kotlin.collections.Map.Entry<K, V>) -> kotlin.sequences.Sequence<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <T, R> kotlin.Array<out T>.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedSequence")
@kotlin.internal.InlineOnly
public inline fun <T, R> kotlin.Array<out T>.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.BooleanArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Boolean) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.ByteArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Byte) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.CharArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.DoubleArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Double) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.FloatArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Float) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.IntArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Int) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.LongArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Long) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.ShortArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Short) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.UByteArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.UByte) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.UIntArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.UInt) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.ULongArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.ULong) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.UShortArray.flatMapIndexed(transform: (index: kotlin.Int, kotlin.UShort) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <T, R> kotlin.collections.Iterable<T>.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedSequence")
@kotlin.internal.InlineOnly
public inline fun <T, R> kotlin.collections.Iterable<T>.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.Array<out T>.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedSequenceTo")
@kotlin.internal.InlineOnly
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.Array<out T>.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.BooleanArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Boolean) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.ByteArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Byte) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.CharArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.DoubleArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Double) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.FloatArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Float) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.IntArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Int) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.LongArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Long) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.ShortArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Short) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.UByteArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.UByte) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.UIntArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.UInt) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.ULongArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.ULong) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.UShortArray.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.UShort) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.collections.Iterable<T>.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedSequenceTo")
@kotlin.internal.InlineOnly
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.collections.Iterable<T>.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence<R>): C
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.Array<out T>.flatMapTo(destination: C, transform: (T) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@@ -151,6 +151,28 @@ public fun <T, R> kotlin.sequences.Sequence<T>.flatMap(transform: (T) -> kotlin.
public fun <T, R> kotlin.sequences.Sequence<T>.flatMap(transform: (T) -> kotlin.sequences.Sequence<R>): kotlin.sequences.Sequence<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
public fun <T, R> kotlin.sequences.Sequence<T>.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable<R>): kotlin.sequences.Sequence<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedSequence")
public fun <T, R> kotlin.sequences.Sequence<T>.flatMapIndexed(transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence<R>): kotlin.sequences.Sequence<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.sequences.Sequence<T>.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.collections.Iterable<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedSequenceTo")
@kotlin.internal.InlineOnly
public inline fun <T, R, C : kotlin.collections.MutableCollection<in R>> kotlin.sequences.Sequence<T>.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, T) -> kotlin.sequences.Sequence<R>): C
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIterableTo")
+12
View File
@@ -263,6 +263,18 @@ public inline fun kotlin.CharSequence.firstOrNull(predicate: (kotlin.Char) -> ko
public inline fun <R> kotlin.CharSequence.flatMap(transform: (kotlin.Char) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterable")
@kotlin.internal.InlineOnly
public inline fun <R> kotlin.CharSequence.flatMapIndexed(transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable<R>): kotlin.collections.List<R>
@kotlin.SinceKotlin(version = "1.4")
@kotlin.OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName(name = "flatMapIndexedIterableTo")
@kotlin.internal.InlineOnly
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.CharSequence.flatMapIndexedTo(destination: C, transform: (index: kotlin.Int, kotlin.Char) -> kotlin.collections.Iterable<R>): C
public inline fun <R, C : kotlin.collections.MutableCollection<in R>> kotlin.CharSequence.flatMapTo(destination: C, transform: (kotlin.Char) -> kotlin.collections.Iterable<R>): C
public inline fun <R> kotlin.CharSequence.fold(initial: R, operation: (acc: R, kotlin.Char) -> R): R
@@ -10035,6 +10035,336 @@ public inline fun <T, R> Array<out T>.flatMap(transform: (T) -> Sequence<R>): Li
return flatMapTo(ArrayList<R>(), 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 <T, R> Array<out T>.flatMapIndexed(transform: (index: Int, T) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <R> ByteArray.flatMapIndexed(transform: (index: Int, Byte) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <R> ShortArray.flatMapIndexed(transform: (index: Int, Short) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <R> IntArray.flatMapIndexed(transform: (index: Int, Int) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <R> LongArray.flatMapIndexed(transform: (index: Int, Long) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <R> FloatArray.flatMapIndexed(transform: (index: Int, Float) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <R> DoubleArray.flatMapIndexed(transform: (index: Int, Double) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <R> BooleanArray.flatMapIndexed(transform: (index: Int, Boolean) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <R> CharArray.flatMapIndexed(transform: (index: Int, Char) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <T, R> Array<out T>.flatMapIndexed(transform: (index: Int, T) -> Sequence<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <T, R, C : MutableCollection<in R>> Array<out T>.flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Iterable<R>): 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 <R, C : MutableCollection<in R>> ByteArray.flatMapIndexedTo(destination: C, transform: (index: Int, Byte) -> Iterable<R>): 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 <R, C : MutableCollection<in R>> ShortArray.flatMapIndexedTo(destination: C, transform: (index: Int, Short) -> Iterable<R>): 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 <R, C : MutableCollection<in R>> IntArray.flatMapIndexedTo(destination: C, transform: (index: Int, Int) -> Iterable<R>): 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 <R, C : MutableCollection<in R>> LongArray.flatMapIndexedTo(destination: C, transform: (index: Int, Long) -> Iterable<R>): 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 <R, C : MutableCollection<in R>> FloatArray.flatMapIndexedTo(destination: C, transform: (index: Int, Float) -> Iterable<R>): 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 <R, C : MutableCollection<in R>> DoubleArray.flatMapIndexedTo(destination: C, transform: (index: Int, Double) -> Iterable<R>): 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 <R, C : MutableCollection<in R>> BooleanArray.flatMapIndexedTo(destination: C, transform: (index: Int, Boolean) -> Iterable<R>): 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 <R, C : MutableCollection<in R>> CharArray.flatMapIndexedTo(destination: C, transform: (index: Int, Char) -> Iterable<R>): 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 <T, R, C : MutableCollection<in R>> Array<out T>.flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Sequence<R>): 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].
*/
@@ -1299,6 +1299,72 @@ public inline fun <T, R> Iterable<T>.flatMap(transform: (T) -> Sequence<R>): Lis
return flatMapTo(ArrayList<R>(), 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 <T, R> Iterable<T>.flatMapIndexed(transform: (index: Int, T) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <T, R> Iterable<T>.flatMapIndexed(transform: (index: Int, T) -> Sequence<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <T, R, C : MutableCollection<in R>> Iterable<T>.flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Iterable<R>): 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 <T, R, C : MutableCollection<in R>> Iterable<T>.flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Sequence<R>): 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].
*/
@@ -777,7 +777,7 @@ public fun <T> Sequence<T>.toSet(): Set<T> {
@OverloadResolutionByLambdaReturnType
@kotlin.jvm.JvmName("flatMapIterable")
public fun <T, R> Sequence<T>.flatMap(transform: (T) -> Iterable<R>): Sequence<R> {
return FlatteningSequence(this, transform, { it.iterator() })
return FlatteningSequence(this, transform, Iterable<R>::iterator)
}
/**
@@ -788,7 +788,79 @@ public fun <T, R> Sequence<T>.flatMap(transform: (T) -> Iterable<R>): Sequence<R
* @sample samples.collections.Collections.Transformations.flatMap
*/
public fun <T, R> Sequence<T>.flatMap(transform: (T) -> Sequence<R>): Sequence<R> {
return FlatteningSequence(this, transform, { it.iterator() })
return FlatteningSequence(this, transform, Sequence<R>::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 <T, R> Sequence<T>.flatMapIndexed(transform: (index: Int, T) -> Iterable<R>): Sequence<R> {
return flatMapIndexed(this, transform, Iterable<R>::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 <T, R> Sequence<T>.flatMapIndexed(transform: (index: Int, T) -> Sequence<R>): Sequence<R> {
return flatMapIndexed(this, transform, Sequence<R>::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 <T, R, C : MutableCollection<in R>> Sequence<T>.flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Iterable<R>): 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 <T, R, C : MutableCollection<in R>> Sequence<T>.flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Sequence<R>): C {
var index = 0
for (element in this) {
val list = transform(checkIndexOverflow(index++), element)
destination.addAll(list)
}
return destination
}
/**
@@ -785,6 +785,39 @@ public inline fun <R> CharSequence.flatMap(transform: (Char) -> Iterable<R>): Li
return flatMapTo(ArrayList<R>(), 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 <R> CharSequence.flatMapIndexed(transform: (index: Int, Char) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <R, C : MutableCollection<in R>> CharSequence.flatMapIndexedTo(destination: C, transform: (index: Int, Char) -> Iterable<R>): 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].
*/
@@ -4494,6 +4494,138 @@ public inline fun <R> UShortArray.flatMap(transform: (UShort) -> Iterable<R>): L
return flatMapTo(ArrayList<R>(), 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 <R> UIntArray.flatMapIndexed(transform: (index: Int, UInt) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <R> ULongArray.flatMapIndexed(transform: (index: Int, ULong) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <R> UByteArray.flatMapIndexed(transform: (index: Int, UByte) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <R> UShortArray.flatMapIndexed(transform: (index: Int, UShort) -> Iterable<R>): List<R> {
return flatMapIndexedTo(ArrayList<R>(), 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 <R, C : MutableCollection<in R>> UIntArray.flatMapIndexedTo(destination: C, transform: (index: Int, UInt) -> Iterable<R>): 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 <R, C : MutableCollection<in R>> ULongArray.flatMapIndexedTo(destination: C, transform: (index: Int, ULong) -> Iterable<R>): 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 <R, C : MutableCollection<in R>> UByteArray.flatMapIndexedTo(destination: C, transform: (index: Int, UByte) -> Iterable<R>): 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 <R, C : MutableCollection<in R>> UShortArray.flatMapIndexedTo(destination: C, transform: (index: Int, UShort) -> Iterable<R>): 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].
*/
@@ -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<String> = listOf("Abcd", "efgh", "Klmn")
val selected: List<Boolean> = 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()
@@ -318,6 +318,15 @@ constructor(
}
}
internal fun <T, C, R> flatMapIndexed(source: Sequence<T>, transform: (Int, T) -> C, iterator: (C) -> Iterator<R>): Sequence<R> =
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
*/
@@ -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<Array<Int>> = arrayOf(arrayOf(1, 2, 3), arrayOf(4, 5, 6))
val arr2: Array<out Array<Int>> = arr1
@@ -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")
@@ -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)
@@ -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<ULong>() })
}
@Test
fun flatMapIndexed() {
assertEquals(listOf(), ubyteArrayOf().flatMapIndexed { index, _ -> listOf(index) })
assertEquals(listOf<UShort>(2, 3, 3), ushortArrayOf(1, 2, 3).flatMapIndexed { index, e -> List(index) { e } })
assertEquals(listOf<UInt>(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<ULong>() })
}
@Test
fun withIndex() {
fun <T> assertIterableContentEquals(expected: Iterable<T>, actual: Iterable<T>) {
+6 -1
View File
@@ -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")
@@ -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;
@@ -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<R>")
body {
"return FlatteningSequence(this, transform, { it.iterator() })"
"return FlatteningSequence(this, transform, Iterable<R>::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<R>")
body {
"return FlatteningSequence(this, transform, { it.iterator() })"
"return FlatteningSequence(this, transform, Sequence<R>::iterator)"
}
}
}
@@ -396,70 +396,79 @@ object Mapping : TemplateGroupBase() {
}
}
val f_flatMapIndexed = fn("flatMapIndexed(transform: (index: Int, T) -> Iterable<R>)") {
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<R>)") {
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<R>")
body {
"return flatMapIndexedTo(ArrayList<R>(), transform)"
}
specialFor(Sequences) {
inline(Inline.No)
signature("flatMapIndexed(transform: (index: Int, T) -> Sequence<R>)")
returns("Sequence<R>")
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<R>")
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<R>(), transform)"
}
specialFor(Sequences) {
inline(Inline.No)
returns("Sequence<R>")
body {
"return flatMapIndexed(this, transform, $containerClass<R>::iterator)"
}
"""
}
}
}
val f_flatMapIndexedTo = fn("flatMapIndexedTo(destination: C, transform: (index: Int, T) -> Iterable<R>)") {
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<R>)")
}
typeParam("R")
typeParam("C : MutableCollection<in R>")
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<R>)") {
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<in R>")
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
"""
}
}