Home > database >  Equivalent Observable.fromIterable in Kotlin Coroutine Flow?
Equivalent Observable.fromIterable in Kotlin Coroutine Flow?

Time:08-25

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)

CodePudding user response:

You can call asFlow() on an Iterable.

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

CodePudding user response:

An alternative to the @Tenfour04's answer is to use flowOf:

val list = listOf(1, 2, 3)
flowOf(*list.toTypedArray())
  • Related