Is there any way to combine flow items in to list ...
# coroutines
y
Is there any way to combine flow items in to list without termination?
p
What's your usecase?
y
I have flow of items, some out of them i need to “split” in 2-3 items of similar type. Other items should remain as is. Then I need to collect all of them into list and transform into map.
Copy code
currentMonthFlow
        .flatMapMerge {calendarDataForMonth(it)}
        .flatMapMerge { it.asFlow() }
        .map { CalendarItem(it) }
        .flatMapMerge {
            if (it.needSplit()) {
                //slitting it
                listOf(it1, it2, i3).asFlow()
            } else {
                listOf(it).asFlow()
            }
        }
        .toList().associateBy ( { it.date }, { it })
After toList() it is no longer flow. At the end i want to transform it into LiveData
asLivedata()
p
I find the code kinda complicated
Can't you do
currentMonthFlow.map {  ...associateBy }
without all these flows? This looks like it could be way simpler
y
It is my current silution, but i need to split some items in to 2-3 items of same type and put into map also
p
Then just do it using regular imperative code?