Interface PeekingOperators<T>

  • Type Parameters:
    T - The type of the elements that the stream emits.
    All Known Subinterfaces:
    ProcessorBuilder<T,​R>, PublisherBuilder<T>

    public interface PeekingOperators<T>
    Operations for peeking at elements and signals in the stream, without impacting the stream itself.

    The documentation for each operator uses marble diagrams to visualize how the operator functions. Each element flowing in and out of the stream is represented as a coloured marble that has a value, with the operator applying some transformation or some side effect, termination and error signals potentially being passed, and for operators that subscribe to the stream, an output value being redeemed at the end.

    Below is an example diagram labelling all the parts of the stream.

    Example marble diagram

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      PeekingOperators<T> onComplete​(java.lang.Runnable action)
      Returns a stream containing all the elements from this stream, additionally performing the provided action when this stream completes.
      PeekingOperators<T> onError​(java.util.function.Consumer<java.lang.Throwable> errorHandler)
      Returns a stream containing all the elements from this stream, additionally performing the provided action if this stream conveys an error.
      PeekingOperators<T> onTerminate​(java.lang.Runnable action)
      Returns a stream containing all the elements from this stream, additionally performing the provided action when this stream completes or failed.
      PeekingOperators<T> peek​(java.util.function.Consumer<? super T> consumer)
      Returns a stream containing all the elements from this stream, additionally performing the provided action on each element.
    • Method Detail

      • peek

        PeekingOperators<T> peek​(java.util.function.Consumer<? super T> consumer)
        Returns a stream containing all the elements from this stream, additionally performing the provided action on each element.

        peek marbles diagram

        Parameters:
        consumer - The function called for every element.
        Returns:
        A new stream builder that consumes elements of type T and emits the same elements. In between, the given function is called for each element.
      • onError

        PeekingOperators<T> onError​(java.util.function.Consumer<java.lang.Throwable> errorHandler)
        Returns a stream containing all the elements from this stream, additionally performing the provided action if this stream conveys an error. The given consumer is called with the failure.

        onError marble diagram

        Parameters:
        errorHandler - The function called with the failure.
        Returns:
        A new stream builder that consumes elements of type T and emits the same elements. If the stream conveys a failure, the given error handler is called.
      • onTerminate

        PeekingOperators<T> onTerminate​(java.lang.Runnable action)
        Returns a stream containing all the elements from this stream, additionally performing the provided action when this stream completes or failed. The given action does not know if the stream failed or completed. If you need to distinguish use onError(Consumer) and onComplete(Runnable). In addition, the action is called if the stream is cancelled downstream.

        onTerminate marble diagram

        Parameters:
        action - The function called when the stream completes or failed.
        Returns:
        A new stream builder that consumes elements of type T and emits the same elements. The given action is called when the stream completes or fails.
      • onComplete

        PeekingOperators<T> onComplete​(java.lang.Runnable action)
        Returns a stream containing all the elements from this stream, additionally performing the provided action when this stream completes.

        onComplete marble diagram

        Parameters:
        action - The function called when the stream completes.
        Returns:
        A new stream builder that consumes elements of type T and emits the same elements. The given action is called when the stream completes.