flatMapTo
Appends all elements yielded from results of transform function being invoked on each element of original array, to the given destination.
@IgnorableReturnValueinline fun <T, R, C : MutableCollection<in R>> Array<out T>.flatMapTo(destination: C, transform: (T) -> Iterable<R>): C(source)
val numbersByGroup = arrayOf(
listOf(1, 2, 3),
listOf(4, 5),
listOf(6)
)
val flattened = mutableListOf<Int>()
numbersByGroup.flatMapTo(flattened) { it }
println(flattened) // Output: [1, 2, 3, 4, 5, 6]