https://kotlinlang.org logo
#flow
Title
# flow
m

miqbaldc

08/14/2020, 12:47 PM
Copy code
@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:
Copy code
list
   .onEach { 
      it.forEach { abc -> println(abc.id) }
   }
My goals:
Copy code
list
   .onEach { abc -> 
       println(abc.id) // prints: [0, 1, 2]
   }
Is there any workaround to transform it to
List<T>
from
Flow<List<T>>
[SOLVED] - Using this approach https://stackoverflow.com/a/59561461/3763032