Skip to content
Sharp

Project Reactor · interview question

In a Project Reactor pipeline, why would you use flatMap() instead of map() to handle a stream of product IDs that need to be fetched from a remote service?

Multiple choiceMediumchapter-19-curatedpremiumproject-reactorfunctional-pipelines-flatmap
Choose one answer
Answer and explanation

Correct answer

C. FlatMap() allows asynchronous fetching of data, enabling concurrent I/O operations.

Why

flatMap() is used to handle asynchronous operations because it can take each input element and return a publisher, enabling non-blocking I/O operations. Unlike map(), which transforms data synchronously, flatMap() allows for concurrent fetching and processing of data, making it suitable for remote service calls.

Test yourself on Project Reactor

A free test with instant, explained results. No account needed.

Start free test
All Project Reactor questions →