I was wondering. Is this: ```flow.flatMapLatest { ...
# coroutines
p
I was wondering. Is this:
Copy code
flow.flatMapLatest {
  flow {
    emit("a")
    emit("b")
    emitAll(otherFlow())
  }
}
the same as this?
Copy code
flow.transformLatest {
  emit("a")
  emit("b")
  emitAll(otherFlow())
}
They seem to do the same on paper (minus the extra flow object), however, is there anything that using
flatMapLatest
will do that
transformLatest
doesn’t? 🙂
j
flatMapLatest
literally calls
transformLatest
under the hood, and simply emits all items from the flow returned by the lambda. So I don't believe there is any real difference. I'd say it's mostly a matter of expressing better what the code does, and avoiding the extra flow
Also, it might be useful to use
flatMapLatest
if you need to do some extra stuff before creating the new flow for a given element of the source flow
p
Oh yeah, you are right, it does. Should have checked the source 😅