Convert From Flux To Mono
Answer :
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.
Here is a list:
Flux#single
will work if there is one element fromFlux
. Eg:flux.take(1).single();
Flux#next
will get you the first element. Eg:flux.next();
Flux#last
for last element. Eg:flux.last();
Flux#singleOrEmpty
is similar toOptional
. Eg:flux.take(0).singleOrEmpty();
Flux#collect
, it depends on use case.flux.collect(Collectors.reducing((i1, i2) -> i1))
.map(op -> op.get());Flux#elementAt
for i'th index. Eg:flux.elementAt(1);
Flux#publishNext
for first found element.flux.publishNext();
Flux#reduce
for reduction op. Eg:flux.reduce((i1,i2) -> i1);
Comments
Post a Comment