Convert from Flux to Mono

Valahu picture Valahu · Feb 3, 2017 · Viewed 25.1k times · Source

How can I convert from a Flux with 1 element to a Mono?

Flux.fromArray(arrayOf(1,2,1,1,1,2))
                .distinct()
                .take(1)

How do I make this a Mono(1)?

Answer

Simon Baslé picture Simon Baslé · Feb 3, 2017

Instead of take(1), you could use next().

This will transform the Flux into a valued Mono by taking the first emitted item, or an empty Mono if the Flux is empty itself.