flatMap

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

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

The operation is intermediate and stateless.

Since Kotlin

1.4

Samples

import kotlin.test.*

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

fun <T, R> Sequence<T>.flatMap(transform: (T) -> Sequence<R>): Sequence<R>(source)

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

The operation is intermediate and stateless.

Since Kotlin

1.0

Samples

import kotlin.test.*

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