Core API – Kotlin Programming Language (original) (raw)

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

Since Kotlin

1.0

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf("123", "45")
println(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

1.4

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf("123", "45")
println(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

1.0

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf("123", "45")
println(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

1.4

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf("123", "45")
println(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.

Since Kotlin

1.0

Samples

import kotlin.test.*
import java.util.*

fun main() { 
   //sampleStart 
   val map = mapOf("122" to 2, "3455" to 3)
println(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

1.4

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf("123", "45")
println(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

1.3

Samples

import kotlin.math.*
import kotlin.test.*

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