Search code examples
kotlinrx-javarx-java2kotlin-coroutineskotlin-flow

Equivalent Observable.fromIterable in Kotlin Coroutine Flow?


I would like to ask how to achieve the below code in Kotlin Flows. If you help, I will be appreciated it.

val list = listOf<Int>()
Observable.fromIterable(list)

Solution

  • You can call asFlow() on an Iterable.

    val list = listOf(1, 2, 3)
    val flow = list.asFlow()