Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert from Flux to Mono

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)?

like image 216
Valahu Avatar asked Feb 03 '17 10:02

Valahu


People also ask

How do you convert flux to Mono?

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.

What is the difference between flux and Mono?

A Flux object represents a reactive sequence of 0.. N items, while a Mono object represents a single-value-or-empty (0..1) result. This distinction carries a bit of semantic information into the type, indicating the rough cardinality of the asynchronous processing.

How do you flatten flux flux?

Flatten Stream<Flux> using Flux#fromStream() + Flux#flatMap()

What is flatMapMany?

The flatMapMany is a generic operator on Mono that returns a Publisher. Let's apply flatMapManyto our solution: private <T> Flux<T> monoTofluxUsingFlatMapMany(Mono<List<T>> monoList) { return monoList .flatMapMany(Flux::fromIterable) .log(); }


1 Answers

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.

like image 58
Simon Baslé Avatar answered Sep 28 '22 07:09

Simon Baslé