https://kotlinlang.org logo
Title
y

Yauhen Pelkin

11/21/2019, 9:26 AM
Is there any way to combine flow items in to list without termination?
p

Paul Woitaschek

11/21/2019, 9:55 AM
What's your usecase?
y

Yauhen Pelkin

11/21/2019, 10:09 AM
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.
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

Paul Woitaschek

11/21/2019, 10:37 AM
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

Yauhen Pelkin

11/21/2019, 10:52 AM
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

Paul Woitaschek

11/21/2019, 10:53 AM
Then just do it using regular imperative code?