Class ReactorFlux
java.lang.Object
dmx.fun.reactor.ReactorFlux
Idiomatic conversions between Project Reactor's
Flux and dmx-fun's
Option, Result, Try, and NonEmptyList.
Where ReactorFun handles a single value (Mono), this facade
handles streams (Flux):
sequence/collectResult/collectValidatedfold a stream of outcomes into a singleMono<Result<List<…>, …>>— the reactive equivalent ofResult.sequence(Iterable)— choosing fail-fast or error-accumulating semantics.flattenOptiondrops absent elements from aFlux<Option<T>>.toFluxemits a dmx-fun container or collection as aFlux.
Backpressure and cancellation are preserved by the underlying Reactor operators.
-
Method Summary
Modifier and TypeMethodDescriptioncollectResult(reactor.core.publisher.Flux<T> source) Collects every element of aFlux<T>intoOk(list)(empty stream →Ok([])), turning a Reactor error signal intoErr(cause).collectResult(reactor.core.publisher.Flux<T> source, Function<? super Throwable, E> errorMapper) Collects every element of aFlux<T>intoOk(list), mapping a Reactor error signal througherrorMapperto the typed error channel.static <T,E> reactor.core.publisher.Mono <Validated<NonEmptyList<E>, List<T>>> collectValidated(reactor.core.publisher.Flux<Result<T, E>> results) Folds aFlux<Result<T, E>>into aMono<Validated<NonEmptyList<E>, List<T>>>, accumulating: everyErris gathered into the invalid channel (no short-circuit), and an all-Okstream (including empty) isValid.static <T> reactor.core.publisher.Flux<T> flattenOption(reactor.core.publisher.Flux<Option<T>> source) Drops the absent elements of aFlux<Option<T>>, keeping the values of theSomeelements in source order.Folds aFlux<Result<T, E>>into a singleMono<Result<List<T>, E>>, fail-fast: the firstErrshort-circuits and cancels the upstream, and an empty stream yieldsOk([]).static <T> reactor.core.publisher.Flux<T> toFlux(NonEmptyList<T> list) Emits each element of aNonEmptyListas aFlux(1..N elements).static <T> reactor.core.publisher.Flux<T> static <T, E extends Throwable>
reactor.core.publisher.Flux<T> static <T,E> reactor.core.publisher.Flux <T> static <T> reactor.core.publisher.Flux<T>
-
Method Details
-
sequence
public static <T,E> reactor.core.publisher.Mono<Result<List<T>,E>> sequence(reactor.core.publisher.Flux<Result<T, E>> results) Folds aFlux<Result<T, E>>into a singleMono<Result<List<T>, E>>, fail-fast: the firstErrshort-circuits and cancels the upstream, and an empty stream yieldsOk([]). A Reactor error signal from the source is not absorbed — it propagates as a Reactor error.- Type Parameters:
T- the value typeE- the error type- Parameters:
results- the stream of results- Returns:
- a
Monoemitting the sequencedResult
-
collectResult
public static <T> reactor.core.publisher.Mono<Result<List<T>, Throwable>> collectResult(reactor.core.publisher.Flux<T> source) Collects every element of aFlux<T>intoOk(list)(empty stream →Ok([])), turning a Reactor error signal intoErr(cause).- Type Parameters:
T- the value type- Parameters:
source- the source stream- Returns:
- a
Monoemitting the collectedResult
-
collectResult
-
collectValidated
public static <T,E> reactor.core.publisher.Mono<Validated<NonEmptyList<E>, List<T>>> collectValidated(reactor.core.publisher.Flux<Result<T, E>> results) Folds aFlux<Result<T, E>>into aMono<Validated<NonEmptyList<E>, List<T>>>, accumulating: everyErris gathered into the invalid channel (no short-circuit), and an all-Okstream (including empty) isValid.- Type Parameters:
T- the value typeE- the error type- Parameters:
results- the stream of results- Returns:
- a
Monoemitting the accumulatedValidated
-
flattenOption
public static <T> reactor.core.publisher.Flux<T> flattenOption(reactor.core.publisher.Flux<Option<T>> source) Drops the absent elements of aFlux<Option<T>>, keeping the values of theSomeelements in source order.- Type Parameters:
T- the value type- Parameters:
source- the stream of options- Returns:
- a
Fluxof the present values
-
toFlux
Emits each element of aNonEmptyListas aFlux(1..N elements).- Type Parameters:
T- the element type- Parameters:
list- the non-empty list- Returns:
- a
Fluxover the list
-
toFlux
-
toFlux
-
toFlux
-
toFlux
public static <T,E> reactor.core.publisher.Flux<T> toFlux(Result<T, E> result, Function<? super E, ? extends Throwable> errorMapper) Emits aResultas aFlux:Okemits one element,Errerrors with the error mapped to aThrowablebyerrorMapper.- Type Parameters:
T- the value typeE- the error type- Parameters:
result- the resulterrorMapper- maps the typed error to aThrowableerror signal- Returns:
- a
Fluxof one element or an error
-