arrow-fx-coroutines / arrow.fx.coroutines.stream / Stream / flatMap

flatMap

fun <B> flatMap(f: (O) -> Stream<B>): Stream<B>

Creates a stream whose elements are generated by applying f to each output of the source stream and concatenated all of the results.

import arrow.fx.coroutines.stream.*

//sampleStart
suspend fun main(): Unit =
  Stream(1, 2, 3)
    .flatMap { i -> Stream(i, i, i) }
    .toList()
    .let(::println) // [1, 1, 1, 2, 2, 2, 3, 3, 3]
//sampleEnd

Do you like Arrow?

Arrow Org
<