Both flatMap and mapMulti turn one stream element into zero or more output elements. The difference is how you express that expansion: flatMap asks for a new stream per element, while mapMulti hands you a consumer and lets you push results into it. That distinction affects allocation, readability, and even how your pipeline behaves when it short-circuits.
This article compares the two operations by mental model and cost, then gives a decision guide keyed to common element shapes and a before/after migration. The short version: mapMulti is not a blanket replacement for flatMap , and the performance difference is often smaller than the code change suggests.
Table of Contents
What flatMap and mapMulti Actually Promise
Two Mental Models: Pull Versus Push
Allocation, Speed, and Readability
A Decision Guide by Element Shape
Migrating a Pipeline from flatMap to mapMulti
Gotchas: Type Witnesses, Short-Circuiting, and Versions
When Readability Should Win
Conclusion
What flatMap and mapMulti Actually…