Ivan Pavlov
03/10/2021, 2:45 PMval 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
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?myanmarking
03/11/2021, 10:20 AM