Class ReactiveUtils


  • public final class ReactiveUtils
    extends java.lang.Object
    Utility 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 of List<T> into a stream of individual T items.
      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 a Flow.Publisher<T> into a Flow.Publisher<List<T>>.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 HttpResponse elements using operations that return CompletableFuture results.
        Type Parameters:
        T - the input element type
        R - the output element type
        Parameters:
        source - the source publisher
        mapper - 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 type
        R - the output element type
        Parameters:
        source - the source publisher
        mapper - 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 type
        R - the output element type
        Parameters:
        source - the source publisher emitting collections
        flattener - 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 of List<T> into a stream of individual T items.
        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 a Flow.Publisher<T> into a Flow.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