I have like `2 flows` and I want to observe their ...
# android
v
I have like 
2 flows
 and I want to observe their changes with 
flatMapLatest
, if either of them emit new value, I want to trigger some action, but how can I observe on 
2 flows
 , should I combine them ? how can I do it
o
Yes,
combine
. https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/combine.html For 2 flows you can use either of the following forms: Top level function
Copy code
combine(f1, f2) { v1, v2 -> TODO() }
Flow.combine extension
Copy code
f1.combine(f2) { v1, v2 -> TODO() }
v
when I was using 
flatMapLatest
  and inside lambda, I was receiving flow and 
flatMapLatest
  was returning that flow, but when I use 
combine
, this will emit 
Flow<Flow<>>
 , so is there a way to achieve like flatMapLatest
Copy code
val someStateFlow = flow1.combine(flow2) { a, b ->
    recievingFlowFromRepository()
}.stateIn(...)
I have code like this ,so this returns
Flow<Flow<>>
because combine returns by making a flow inside a lambda
o
Yes
Copy code
paramFlow1.combine(paramFlow2) { a, b ->
    Pair(a, b)
}.flatMapLatest { (a, b) -> // destructured Pair
    loadWithParameters(a, b) // this returns a Flow
}.stateIn(...)
🙏 1
☝️ 1
v
thanks for the quick tip