Hi. I have something like ```val sf1 = MutableStat...
# coroutines
i
Hi. I have something like
Copy code
val sf1 = MutableStateFlow(listOf(1))
val sf2 = MutableStateFlow(listOf(-1))

sf1.value = listOf(1, 2)
sf2.value = listOf(-1, -2)
sf1.value = listOf(1, 2, 3)
I combine them like
Copy code
sf1.combine(sf2) { a, b -> a + b }
    .stateIn(scope, SharingStarted.Eagerly, initialValue = listOf())
    .onEach { println(it) }
    .launchIn(scope)
Then I don't have [1, -1] list in combined flow. I changed initialValue to sf1.value + sf2.value and now it works but I think that I could miss something which simplifies this. Is there a better way?
m
by the time you use combine, the first value for sf1 get’s lost because only the last value is ‘cached’. It is my understanding