https://kotlinlang.org logo
#getting-started
Title
# getting-started
b

Billy Newman

10/26/2023, 3:31 PM
Hello again, running into an issue trying to combine live data as flows. When updating livedata objects I am not seeing the combine trigger. Example in thread
Copy code
val flow = combine(first.asFlow(), second.asFlow()){ first, second ->
    first to second
}
...
fun updateFirst(update: String) {
   first.value = update // combine transform is not called
}
I am observing the flow object in my compose screen
m

Mikhail

10/26/2023, 3:55 PM
What is the
first
and why do you think it should emit data to flow?
b

Billy Newman

10/26/2023, 4:02 PM
Copy code
val first = MutableLiveData<String>()
Sorry first is a livedata object that is changing
Should an update of that livedata invoke the combine transform in this case, or am I doing this wrong?
m

Mitchell Syer

10/26/2023, 6:39 PM
combine first needs values from all flows before it can transform. I think the Livedata you are passing contain nothing, so they are not emitting. It is also possible that you are not collecting/consuming the flow, so it isn't subscribed to any changes.
b

Billy Newman

10/26/2023, 6:54 PM
I am collecting the flow in my screen, but I suspect its an issue with your first observation. Thank you, I will check there