Into the jungle of reactive operators

Benedikt Jerat
Dec 20, 2019 · 8 min read
Image for post
Image for post
Photo by Martyna Bober on Unsplash

What The Operator?!

Image for post
Image for post
Photo by Ohm Kittipong on Unsplash
  • by supplying a generator function,
  • by capturing other types, like Futures, Runnables, or Callables,
  • or by consuming Arrays, Streams, or Iterables.
  • by pairing each value,
  • or each time a new value arrives at either side.
  • applying some predicate function to at least one or all values,
  • or aggregating every element into one.
Image for post
Image for post
https://projectreactor.io/docs/core/release/reference/#flux

All your operator are belong to us

Image for post
Image for post

Directly creating a sequence: just

Image for post
Image for post
https://github.com/reactor/reactor-core/blob/master/reactor-core/src/main/java/reactor/core/publisher/doc-files/marbles/just.svg
Mono from simple value (strict evaluation)

Lazily creating a sequence: fromSupplier, defer

Image for post
Image for post
https://github.com/reactor/reactor-core/blob/master/reactor-core/src/main/java/reactor/core/publisher/doc-files/marbles/fromSupplier.svg
Image for post
Image for post
https://github.com/reactor/reactor-core/blob/master/reactor-core/src/main/java/reactor/core/publisher/doc-files/marbles/deferForMono.svg
Mono from simple value (deferred evaluation)

Transforming a sequence: map

Image for post
Image for post
https://rxmarbles.com/#map
Directly transforming values by using the map operator

Transforming a sequence: flatMap

Image for post
Image for post
https://github.com/reactor/reactor-core/blob/master/reactor-core/src/main/java/reactor/core/publisher/doc-files/marbles/flatMapForFlux.svg
Transforming and flattening publishers by using the flatMap operator

Combining two sequences: merge

Image for post
Image for post
https://rxmarbles.com/#merge
Image for post
Image for post
https://www.enterpriseintegrationpatterns.com/patterns/messaging/BroadcastAggregate.html

Filtering sequences: filter

Image for post
Image for post
https://rxmarbles.com/#filter
Filtering out values by applying a predicate function

Using multiple data streams

So far, the examples mainly consisted of individual operators. Therefore, I would like to continue with a slightly larger example.

         /----------> details ------------------> overall
/ /
/ /---> metacritic ---\ /
/ / \ /
name --------|--------> ign ---------> rating
\ /
\----> gamespot ----/
Single result by combining publishers from different sources



Digital Frontiers — Das Blog

Dies ist das Blog der Digital Frontiers GmbH & Co.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store