flatMap

inline fun <T, R> Array<out T>.flatMap(transform: (T) -> Iterable<R>): List<R>
inline fun <R> ByteArray.flatMap(transform: (Byte) -> Iterable<R>): List<R>
inline fun <R> ShortArray.flatMap(transform: (Short) -> Iterable<R>): List<R>
inline fun <R> IntArray.flatMap(transform: (Int) -> Iterable<R>): List<R>
inline fun <R> LongArray.flatMap(transform: (Long) -> Iterable<R>): List<R>
inline fun <R> FloatArray.flatMap(transform: (Float) -> Iterable<R>): List<R>
inline fun <R> DoubleArray.flatMap(transform: (Double) -> Iterable<R>): List<R>
inline fun <R> BooleanArray.flatMap(transform: (Boolean) -> Iterable<R>): List<R>
inline fun <R> CharArray.flatMap(transform: (Char) -> Iterable<R>): List<R>

Returns a single list of all elements yielded from results of transform function being invoked on each element of original array.

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val list = listOf("123", "45")
assertPrints(list.flatMap { it.toList() }, "[1, 2, 3, 4, 5]") 
   //sampleEnd
}

@JvmName(name = "flatMapSequence")
inline fun <T, R> Array<out T>.flatMap(transform: (T) -> Sequence<R>): List<R>

Returns a single list of all elements yielded from results of transform function being invoked on each element of original array.

Since Kotlin

1.4

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val list = listOf("123", "45")
assertPrints(list.flatMap { it.toList() }, "[1, 2, 3, 4, 5]") 
   //sampleEnd
}

inline fun <T, R> Iterable<T>.flatMap(transform: (T) -> Iterable<R>): List<R>

Returns a single list of all elements yielded from results of transform function being invoked on each element of original collection.

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val list = listOf("123", "45")
assertPrints(list.flatMap { it.toList() }, "[1, 2, 3, 4, 5]") 
   //sampleEnd
}

@JvmName(name = "flatMapSequence")
inline fun <T, R> Iterable<T>.flatMap(transform: (T) -> Sequence<R>): List<R>

Returns a single list of all elements yielded from results of transform function being invoked on each element of original collection.

Since Kotlin

1.4

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val list = listOf("123", "45")
assertPrints(list.flatMap { it.toList() }, "[1, 2, 3, 4, 5]") 
   //sampleEnd
}

inline fun <K, V, R> Map<out K, V>.flatMap(transform: (Map.Entry<K, V>) -> Iterable<R>): List<R>

Returns a single list of all elements yielded from results of transform function being invoked on each entry of original map.

Samples

import samples.*
import kotlin.test.*
import java.util.*
fun main() { 
   //sampleStart 
   val map = mapOf("122" to 2, "3455" to 3)
assertPrints(map.flatMap { (key, value) -> key.take(value).toList() }, "[1, 2, 3, 4, 5]") 
   //sampleEnd
}

@JvmName(name = "flatMapSequence")
inline fun <K, V, R> Map<out K, V>.flatMap(transform: (Map.Entry<K, V>) -> Sequence<R>): List<R>

Returns a single list of all elements yielded from results of transform function being invoked on each entry of original map.

Since Kotlin

1.4

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val list = listOf("123", "45")
assertPrints(list.flatMap { it.toList() }, "[1, 2, 3, 4, 5]") 
   //sampleEnd
}

inline fun <R> UIntArray.flatMap(transform: (UInt) -> Iterable<R>): List<R>
inline fun <R> ULongArray.flatMap(transform: (ULong) -> Iterable<R>): List<R>
inline fun <R> UByteArray.flatMap(transform: (UByte) -> Iterable<R>): List<R>
inline fun <R> UShortArray.flatMap(transform: (UShort) -> Iterable<R>): List<R>

Returns a single list of all elements yielded from results of transform function being invoked on each element of original array.

Since Kotlin

1.3

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val list = listOf("123", "45")
assertPrints(list.flatMap { it.toList() }, "[1, 2, 3, 4, 5]") 
   //sampleEnd
}