https://kotlinlang.org logo
#coroutines
Title
# coroutines
k

Kulwinder Singh

10/23/2019, 12:43 PM
Hi, is it good to use multiple
combine
in flows like below
Copy code
Firestore.getFlow1().combine(Firestore.getFlow2()) { f1, f2 -> Result(f1,f2)}
                .combine(Firestore.getFlow3()) { f3, result -> result.f3 = f3 }
                .collect { _liveData.value = it}
Here
Firesstore.get*
all are wrappers that converts firestores snapshow listeners to flow, so here i have to listen three flows and want to combine them . is it good to do like this or there is any other way also ?
l

louiscad

10/23/2019, 1:02 PM
You can use top-level combine and instantiate a
Triple
of the values from the three flows.
k

Kulwinder Singh

10/23/2019, 1:17 PM
sorry i did not get it
@louiscad any example?
p

pg

10/23/2019, 2:50 PM
I'm not specialist, but maybe examples in https://kotlinlang.org/docs/reference/coroutines/flow.html#combine will helpful
👍 1
l

louiscad

10/23/2019, 3:29 PM
@Kulwinder Singh
combine(flow1, flow2, flow3) { value1, value2, value3 -> Triple(value1, value2, value3) }
3 Views