```storage.findXXX(userId) .flatMapLatest { ...
# coroutines
m
Copy code
storage.findXXX(userId)
    .flatMapLatest {
        if(it == null){
            flowOf(
                storage.findYYY(userId)
            )
        } else{
            flowOf(it)
        }
    }
z
In this example, I don't understand why you're wrapping either return value in
flowOf
, since there's only one value in either case. Presumably your actual code has multiple values?
m
yes. both have multiple values. i want to use alternative flow while the original emits null
z
Another alternative would be to use the
transform
operator:
Copy code
.transform { 
  if (it == null) {
    emit(…)
    emit(…)
    // or
    emitAll(otherFlow)
  } else {
    emit(it)
  }
See https://kotlinlang.org/docs/reference/coroutines/flow.html#transform-operator
m
hm, i think thats wat i am after. thanks!
p
It should be transformLatest, else you'll accumulate streams