T
- The type of the elements that the stream emits.public interface ConsumingOperators<T>
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 having 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.
Modifier and Type | Method and Description |
---|---|
ProducesResult<Void> |
cancel()
Cancels the stream as soon as it is run.
|
<R,A> ProducesResult<R> |
collect(Collector<? super T,A,R> collector)
Collect the elements emitted by this stream using the given
Collector . |
<R> ProducesResult<R> |
collect(Supplier<R> supplier,
BiConsumer<R,? super T> accumulator)
Collect the elements emitted by this stream using a
Collector built from the given
supplier and accumulator . |
ProducesResult<Optional<T>> |
findFirst()
Find the first element emitted by the
Publisher , and return it in a
CompletionStage . |
ProducesResult<Void> |
forEach(Consumer<? super T> action)
Performs an action for each element on this stream.
|
ProducesResult<Void> |
ignore()
Ignores each element of this stream.
|
ProducesResult<Optional<T>> |
reduce(BinaryOperator<T> accumulator)
Perform a reduction on the elements of this stream, using the provided accumulation function.
|
ProducesResult<T> |
reduce(T identity,
BinaryOperator<T> accumulator)
Perform a reduction on the elements of this stream, using the provided identity value and the accumulation
function.
|
ProducesResult<List<T>> |
toList()
Collect the elements emitted by this stream into a
List . |
ProducesResult<Void> forEach(Consumer<? super T> action)
The returned CompletionStage
will be redeemed when the stream completes, either successfully if the stream
completes normally, or with an error if the stream completes with an error or if the action throws an exception.
action
- The action.ProducesResult<Void> ignore()
The returned CompletionStage
will be redeemed when the stream completes, either successfully if the
stream completes normally, or with an error if the stream completes with an error or if the action throws an
exception.
ProducesResult<Void> cancel()
The returned CompletionStage
will be immediately redeemed as soon as the stream is run.
ProducesResult<T> reduce(T identity, BinaryOperator<T> accumulator)
The result of the reduction is returned in the CompletionStage
.
identity
- The identity value.accumulator
- The accumulator function.ProducesResult<Optional<T>> reduce(BinaryOperator<T> accumulator)
The result of the reduction is returned as an Optional<T>
in the CompletionStage
. If there are no elements in this stream,
empty will be returned.
accumulator
- The accumulator function.ProducesResult<Optional<T>> findFirst()
Publisher
, and return it in a
CompletionStage
.
If the stream is completed before a single element is emitted, then Optional.empty()
will be emitted.
<R,A> ProducesResult<R> collect(Collector<? super T,A,R> collector)
Collector
.
Since Reactive Streams are intrinsically sequential, only the accumulator of the collector will be used, the combiner will not be used.
R
- The result of the collector.A
- The accumulator type.collector
- The collector to collect the elements.<R> ProducesResult<R> collect(Supplier<R> supplier, BiConsumer<R,? super T> accumulator)
Collector
built from the given
supplier
and accumulator
.
Since Reactive Streams are intrinsically sequential, the combiner will not be used. This is why this method does not accept a combiner method.
R
- The result of the collector.supplier
- a function that creates a new result container. It creates objects of type <A>
.accumulator
- an associative, non-interfering, stateless function for incorporating an additional element into a
resultProducesResult<List<T>> toList()
List
.
Copyright © 2019 Eclipse Foundation. All rights reserved.