Trying a hands-on project

Now that we have discussed Reactor interfaces in detail, let's try to generate a factorial series using Reactor. Given a number, we want to generate a factorial of all numbers less than or equal to the provided number. In number theory, a factorial is described as follows:

"The factorial of a positive number 'n' is  defined  as n! = n(n-1)(n-2)...2.1 For example, 5 ! = 5 × 4 × 3 × 2 × 1 = 120."

Now, let's try to build a factorial stream function that takes a number and attempts to generate a factorial for every number, from 0 to N:

public class FactorialService {    Flux<Double> generateFactorial(long number) {        Flux<Double> factorialStream = Flux.generate(                () -> Tuples.<Long, Double>of(0L, 1.0d), (state, sink) -> { ...

Get Hands-On Reactive Programming with Reactor now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.