```dataStoreManager.getShopDomain().distinctUntilC...
# coroutines
m
Copy code
dataStoreManager.getShopDomain().distinctUntilChanged().collectLatest { shop ->
            dataStoreManager.getStorefrontAccessToken().distinctUntilChanged().collectLatest { accessToken ->
                    if (shop.isNotEmpty() && accessToken.isNotEmpty()) {
                        // Build the graph client
I need to collect from two flows and do something but having nested
collectLatest
is making me think if it's the right approach? Is there a better way which does the same as above?
s
combine
on the two flows
m
combine
is behaving differently than
collectLatest
e
Copy code
combine(f, g) { x, y -> x to y }.collectLatest { (x, y) ->
👍 1
g
Maybe I'm missing something, but isn't it what combineLatest(f, g) does?
m
I think
combineLatest
has been deprecated for
combine
g
Ah, I got what is the issue, combineLatest is our own utility, haha, sorry for confusion. Implemented like this, if you curious (+ other overloads for 3-4 flows):
Copy code
fun <T1, T2, R> combineLatest(
    flow: Flow<T1>,
    flow2: Flow<T2>,
    transform: suspend (T1, T2) -> R
): Flow<R> = combine(flow, flow2) { t1, t2 -> listOf(t1, t2) }
    .mapLatest { args ->
        @Suppress("UNCHECKED_CAST")
        transform(
            args[0] as T1,
            args[1] as T2
        )
    }
m
Great, thank you very much for that! It behaves exactly as what I wanted.