Package org.bsc.async

Interface AsyncGeneratorOperators<E>

    • Method Detail

      • executor

        default Executor executor()
      • map

        default <U> AsyncGenerator<U> map​(Function<E,​U> mapFunction)
        Maps the elements of this generator to a new asynchronous generator.
        Type Parameters:
        U - the type of elements in the new generator
        Parameters:
        mapFunction - the function to map elements to a new asynchronous counterpart
        Returns:
        a generator with mapped elements
      • flatMap

        default <U> AsyncGenerator<U> flatMap​(Function<E,​CompletableFuture<U>> mapFunction)
        Maps the elements of this generator to a new asynchronous generator, and flattens the resulting nested generators.
        Type Parameters:
        U - the type of elements in the new generator
        Parameters:
        mapFunction - the function to map elements to a new asynchronous counterpart
        Returns:
        a generator with mapped and flattened elements
      • filter

        default AsyncGenerator<E> filter​(Predicate<E> predicate)
        Filters the elements of this generator based on the given predicate. Only elements that satisfy the predicate will be included in the resulting generator.
        Parameters:
        predicate - the predicate to test elements against
        Returns:
        a generator with elements that satisfy the predicate
      • forEachAsync

        default CompletableFuture<Object> forEachAsync​(Consumer<E> consumer)
        Asynchronously iterates over the elements of the AsyncGenerator and applies the given consumer to each element.
        Parameters:
        consumer - the consumer function to be applied to each element
        Returns:
        a CompletableFuture representing the completion of the iteration process.
      • collectAsync

        default <R extends List<E>> CompletableFuture<R> collectAsync​(R result,
                                                                      BiConsumer<R,​E> consumer)
        Collects elements from the AsyncGenerator asynchronously into a list.
        Type Parameters:
        R - the type of the result list
        Parameters:
        result - the result list to collect elements into
        consumer - the consumer function for processing elements
        Returns:
        a CompletableFuture representing the completion of the collection process