miqbaldc
08/14/2020, 12:47 PM@Test
fun testFlow1() {
(1..5)
.asFlow()
.onEach { println(it) } // prints: 1, 2, 3, 4, 5
}
@Test
fun testFlow2() {
data class Abc(val id: Int)
val list: Flow<List<Abc>> = flow { emit(listOf(Abc(0), Abc(1), Abc(2))) }
list
.onEach { println(it) } // prints: list of object instead of each single abc object
}
Does currently possible to iterate each index for testFlow2
without using it like this:
list
.onEach {
it.forEach { abc -> println(abc.id) }
}
My goals:
list
.onEach { abc ->
println(abc.id) // prints: [0, 1, 2]
}
List<T>
from Flow<List<T>>