Class ReactiveUtils
- java.lang.Object
-
- pl.gsmservice.gateway.utils.reactive.ReactiveUtils
-
public final class ReactiveUtils extends java.lang.ObjectUtility class for reactive stream operations.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.concurrent.Flow.Publisher<T>concat(java.util.List<java.util.concurrent.Flow.Publisher<T>> pubs)Concatenates multiple publishers into a single publisher.static <T> java.util.concurrent.Flow.Publisher<T>flatten(java.util.concurrent.Flow.Publisher<java.util.List<T>> source)Flattens a stream ofList<T>into a stream of individualTitems.static <T,R>
java.util.concurrent.Flow.Publisher<R>flatten(java.util.concurrent.Flow.Publisher<T> source, java.util.function.Function<T,java.lang.Iterable<R>> flattener)Flattens a stream of collections into a stream of individual items.static <T,R>
java.util.concurrent.Flow.Publisher<R>map(java.util.concurrent.Flow.Publisher<T> source, java.util.function.Function<T,R> mapper)Maps elements from a Flow.Publisher using a synchronous transformation function.static <T,R>
java.util.concurrent.Flow.Publisher<R>mapAsync(java.util.concurrent.Flow.Publisher<T> source, java.util.function.Function<T,java.util.concurrent.CompletableFuture<R>> mapper)Maps elements from a Flow.Publisher using an asynchronous transformation function.static <T> java.util.concurrent.Flow.Publisher<java.util.List<T>>wrapped(java.util.concurrent.Flow.Publisher<T> source)Wraps aFlow.Publisher<T>into aFlow.Publisher<List<T>>.
-
-
-
Method Detail
-
mapAsync
public static <T,R> java.util.concurrent.Flow.Publisher<R> mapAsync(java.util.concurrent.Flow.Publisher<T> source, java.util.function.Function<T,java.util.concurrent.CompletableFuture<R>> mapper)Maps elements from a Flow.Publisher using an asynchronous transformation function. This is useful for transforming HttpResponseelements using operations that return CompletableFuture results. - Type Parameters:
T- the input element typeR- the output element type- Parameters:
source- the source publishermapper- the async transformation function (e.g., AsyncOperation::handleResponse)- Returns:
- a new publisher that emits the mapped elements
-
map
public static <T,R> java.util.concurrent.Flow.Publisher<R> map(java.util.concurrent.Flow.Publisher<T> source, java.util.function.Function<T,R> mapper)Maps elements from a Flow.Publisher using a synchronous transformation function.- Type Parameters:
T- the input element typeR- the output element type- Parameters:
source- the source publishermapper- the transformation function- Returns:
- a new publisher that emits the mapped elements
-
flatten
public static <T,R> java.util.concurrent.Flow.Publisher<R> flatten(java.util.concurrent.Flow.Publisher<T> source, java.util.function.Function<T,java.lang.Iterable<R>> flattener)Flattens a stream of collections into a stream of individual items.- Type Parameters:
T- the input collection typeR- the output element type- Parameters:
source- the source publisher emitting collectionsflattener- the function to extract items from each collection- Returns:
- a new publisher that emits individual items from the collections
-
flatten
public static <T> java.util.concurrent.Flow.Publisher<T> flatten(java.util.concurrent.Flow.Publisher<java.util.List<T>> source)
Flattens a stream ofList<T>into a stream of individualTitems.- Type Parameters:
T- the type of elements to emit downstream- Parameters:
source- the source publisher emitting lists- Returns:
- a new publisher that emits individual items from the lists
-
wrapped
public static <T> java.util.concurrent.Flow.Publisher<java.util.List<T>> wrapped(java.util.concurrent.Flow.Publisher<T> source)
Wraps aFlow.Publisher<T>into aFlow.Publisher<List<T>>.- Type Parameters:
T- the type of elements to emit downstream- Parameters:
source- the source publisher- Returns:
- a new publisher that emits lists of items from the source publisher
-
concat
public static <T> java.util.concurrent.Flow.Publisher<T> concat(java.util.List<java.util.concurrent.Flow.Publisher<T>> pubs)
Concatenates multiple publishers into a single publisher.- Type Parameters:
T- the type of elements to emit downstream- Parameters:
pubs- the publishers to concatenate- Returns:
- a new publisher that concatenates the given publishers
-
-