Understanding Reactive’s .flatMap() Operator

Prashant Pandey
Jun 18, 2019 · 5 min read

.flatMap() is one of the most arcane of Reactive’s operators. While it is difficult to understand, once we understand exactly how it works, it becomes an extremely powerful operator in our toolkit. In this article, we’ll try to dissect it and understand what it does and why it does what it does. Note: I am using Project Reactor for demonstration but RxJava’s .flatMap() also works in the same way. All you need to know about Reactor for this post is that a Mono represents a stream containing a single event, whereas a Flux represents a stream with more than one event.