flat Map
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
}
Returns a single list of all elements yielded from results of transform function being invoked on each element of original array.
Since Kotlin
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
}
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
}
Returns a single list of all elements yielded from results of transform function being invoked on each element of original collection.
Since Kotlin
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
}
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
}
Returns a single list of all elements yielded from results of transform function being invoked on each entry of original map.
Since Kotlin
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
}
Returns a single list of all elements yielded from results of transform function being invoked on each element of original array.
Since Kotlin
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
}