Fibonacci functional router

Now that we have seen the basics of functional mappings, let's try to render the Fibonacci series using them. We will use the same Fibonacci generator developed in the previous section. We have seen that we can write a Reactive Stream publisher into ServerResponse, as demonstrated in the following code snippet:

@Configurationclass FibonacciConfigurer {        @Bean    RouterFunction<ServerResponse> fibonacciEndpoint() {        Flux<Long> fibonacciGenerator = Flux.generate(() -> Tuples.<Long,                Long>of(0L, 1L), (state, sink) -> {            if (state.getT1() < 0)                sink.complete();            else      ;            return Tuples.of(state.getT2(), state.getT1() + state.getT2());        });        RouterFunction<ServerResponse> fibonacciRoute = RouterFunctions. ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.