FlatMap

This is similar to map, but the transform function returns a collection instead of one item, and then the resulting collections are flattened to a single one:

val numbers = listOf(1, 2, 3, 4, 5)
val multiplesOf10 = numbers.flatMap { n -> listOf(n, n * 10) }

Now the resulting list looks like this [1, 10, 2, 20, 3, 30, 4, 40, 5, 50]

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.215.117