Class MultiOnItem<T>
- java.lang.Object
-
- io.smallrye.mutiny.groups.MultiOnItem<T>
-
public class MultiOnItem<T> extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description MultiOnItem(Multi<T> upstream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Multi<T>
call(java.util.function.Function<? super T,Uni<?>> action)
Produces a newMulti
invoking the given @{code action} when anitem
event is received.Multi<T>
call(java.util.function.Supplier<Uni<?>> action)
Produces a newMulti
invoking the given @{code action} when anitem
event is received, but ignoring it in the callback.<O> Multi<O>
castTo(java.lang.Class<O> target)
Produces anMulti
emitting the item events based on the upstream events but casted to the target class.<O> Multi<O>
disjoint()
Multi<T>
failWith(java.util.function.Function<? super T,? extends java.lang.Throwable> mapper)
Multi<T>
failWith(java.util.function.Supplier<? extends java.lang.Throwable> supplier)
Multi<java.lang.Void>
ignore()
Ignores the passed items.Uni<java.lang.Void>
ignoreAsUni()
Ignores the passed items.Multi<T>
invoke(java.lang.Runnable callback)
Produces a newMulti
invoking the given callback when anitem
event is fired by the upstream.Multi<T>
invoke(java.util.function.Consumer<? super T> callback)
Produces a newMulti
invoking the given callback when anitem
event is fired by the upstream.Multi<T>
scan(java.util.function.BinaryOperator<T> accumulator)
<S> Multi<S>
scan(java.util.function.Supplier<S> initialStateProducer, java.util.function.BiFunction<S,? super T,S> accumulator)
<R> Multi<R>
transform(java.util.function.Function<? super T,? extends R> mapper)
<O> Multi<O>
transformToIterable(java.util.function.Function<? super T,? extends java.lang.Iterable<O>> mapper)
On each item received from the upstream, call the given mapper.<O> MultiFlatten<T,O>
transformToMulti(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends O>> mapper)
On each item received from upstream, invoke the given mapper.<O> Multi<O>
transformToMultiAndConcatenate(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends O>> mapper)
For each items emitted by the upstream, the givenmapper
is invoked.<O> Multi<O>
transformToMultiAndMerge(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends O>> mapper)
For each items emitted by the upstream, the givenmapper
is invoked.<O> MultiFlatten<T,O>
transformToUni(java.util.function.Function<? super T,Uni<? extends O>> mapper)
On each item received from upstream, invoke the given mapper.<O> Multi<O>
transformToUniAndConcatenate(java.util.function.Function<? super T,Uni<? extends O>> mapper)
For each items emitted by the upstream, the givenmapper
is invoked.<O> Multi<O>
transformToUniAndMerge(java.util.function.Function<? super T,Uni<? extends O>> mapper)
For each items emitted by the upstream, the givenmapper
is invoked.
-
-
-
Method Detail
-
transform
public <R> Multi<R> transform(java.util.function.Function<? super T,? extends R> mapper)
Produces a newMulti
invoking the given function for each item emitted by the upstreamMulti
.The function receives the received item as parameter, and can transform it. The returned object is sent downstream as
item
event.- Type Parameters:
R
- the type of item produced by the mapper function- Parameters:
mapper
- the mapper function, must not benull
- Returns:
- the new
Multi
-
invoke
public Multi<T> invoke(java.util.function.Consumer<? super T> callback)
Produces a newMulti
invoking the given callback when anitem
event is fired by the upstream. Note that the received item cannot benull
.If the callback throws an exception, this exception is propagated to the downstream as failure. No more items will be consumed.
- Parameters:
callback
- the callback, must not benull
- Returns:
- the new
Multi
-
invoke
public Multi<T> invoke(java.lang.Runnable callback)
Produces a newMulti
invoking the given callback when anitem
event is fired by the upstream.If the callback throws an exception, this exception is propagated to the downstream as failure. No more items will be consumed.
- Parameters:
callback
- the callback, must not benull
- Returns:
- the new
Multi
-
call
public Multi<T> call(java.util.function.Function<? super T,Uni<?>> action)
Produces a newMulti
invoking the given @{code action} when anitem
event is received. Note that the received item cannot benull
.Unlike
invoke(Consumer)
, the passed function returns aUni
. When the producedUni
sends its result, the result is discarded, and the originalitem
is forwarded downstream. If the producedUni
fails, the failure is propagated downstream.If the asynchronous action throws an exception, this exception is propagated downstream.
This method preserves the order of the items, meaning that the downstream received the items in the same order as the upstream has emitted them.
-
call
public Multi<T> call(java.util.function.Supplier<Uni<?>> action)
Produces a newMulti
invoking the given @{code action} when anitem
event is received, but ignoring it in the callback.Unlike
invoke(Consumer)
, the passed function returns aUni
. When the producedUni
sends its result, the result is discarded, and the originalitem
is forwarded downstream. If the producedUni
fails, the failure is propagated downstream.If the asynchronous action throws an exception, this exception is propagated downstream.
This method preserves the order of the items, meaning that the downstream received the items in the same order as the upstream has emitted them.
-
disjoint
public <O> Multi<O> disjoint()
Takes the items from the upstreamMulti
that are eitherPublisher<O>
,O[]
,Iterable<O>
orMulti<O>
and disjoint the items to obtain aMulti<O>
.For example,
Multi<[A, B, C], [D, E, F]
is transformed intoMulti<A, B, C, D, E, F>
.If the items from upstream are not instances of
Iterable
,Publisher
or array, anIllegalArgumentException
is propagated downstream.- Type Parameters:
O
- the type items contained in the upstream's items.- Returns:
- the resulting multi
-
transformToMulti
public <O> MultiFlatten<T,O> transformToMulti(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends O>> mapper)
On each item received from upstream, invoke the given mapper. This mapper return aPublisher
or aMulti
. The return object lets you configure the flattening process, i.e. how the items produced by the returnedPublishers or Multis
are propagated to the downstream.- Type Parameters:
O
- the type of item emitted by theMulti
produced by the mapper.- Parameters:
mapper
- the mapper, must not benull
, must not producenull
- Returns:
- the object to configure the flatten behavior.
-
transformToMultiAndConcatenate
public <O> Multi<O> transformToMultiAndConcatenate(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends O>> mapper)
For each items emitted by the upstream, the givenmapper
is invoked. Thismapper
returns aPublisher
. The events emitted by the returnedPublisher
are propagated downstream using aconcatenation
, meaning that it does not interleaved the items produced by the differentPublishers
.For example, let's imagine an upstream multi {a, b, c} and a mapper emitting the 3 items with some delays between them. For example a -> {a1, a2, a3}, b -> {b1, b2, b3} and c -> {c1, c2, c3}. Using this method on the multi {a, b c} with that mapper may produce the following multi {a1, a2, a3, b1, b2, b3, c1, c2, c3}. So produced multis are concatenated.
This operation is often called concatMap.
If the mapper throws an exception, the failure is propagated downstream. No more items will be emitted. If one of the produced
Publisher
propagates a failure, the failure is propagated downstream and no more items will be emitted.- Type Parameters:
O
- the type of item emitted by theMulti
produced by the mapper.- Parameters:
mapper
- the mapper, must not benull
, must not producenull
- Returns:
- the resulting multi
-
transformToMultiAndMerge
public <O> Multi<O> transformToMultiAndMerge(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends O>> mapper)
For each items emitted by the upstream, the givenmapper
is invoked. Thismapper
returns aPublisher
. The events emitted by the returnedPublisher
are propagated using amerge
, meaning that it may interleave events produced by the differentPublishers
.For example, let's imagine an upstream multi {a, b, c} and a mapper emitting the 3 items with some delays between them. For example a -> {a1, a2, a3}, b -> {b1, b2, b3} and c -> {c1, c2, c3}. Using this method on the multi {a, b c} with that mapper may produce the following multi {a1, b1, a2, c1, b2, c2, a3, b3, c3}. So the items from the produced multis are interleaved and are emitted as soon as they are emitted (respecting the downstream request).
This operation is often called flatMap.
If the mapper throws an exception, the failure is propagated downstream. No more items will be emitted. If one of the produced
Publisher
propagates a failure, the failure is propagated downstream and no more items will be emitted.- Type Parameters:
O
- the type of item emitted by theMulti
produced by the mapper.- Parameters:
mapper
- the mapper, must not benull
, must not producenull
- Returns:
- the resulting multi
-
transformToIterable
public <O> Multi<O> transformToIterable(java.util.function.Function<? super T,? extends java.lang.Iterable<O>> mapper)
On each item received from the upstream, call the given mapper. The mapper returns anIterable
. The items from the returnedIterable
are propagated downstream (one by one). AsIterable
is a synchronous construct, this method concatenates the items produced by the different returns iterables.- Type Parameters:
O
- the type of item contained by theIterable
produced by the mapper.- Parameters:
mapper
- the mapper, must not benull
, must not producenull
- Returns:
- the object to configure the flatten behavior.
-
transformToUni
public <O> MultiFlatten<T,O> transformToUni(java.util.function.Function<? super T,Uni<? extends O>> mapper)
On each item received from upstream, invoke the given mapper. This mapper returnUni<T>
. The return object lets you configure the flattening process, i.e. how the items produced by the returnedUnis
are propagated to the downstream.- Type Parameters:
O
- the type of item emitted by theMulti
produced by the mapper.- Parameters:
mapper
- the mapper, must not benull
, must not producenull
- Returns:
- the object to configure the flatten behavior.
-
transformToUniAndConcatenate
public <O> Multi<O> transformToUniAndConcatenate(java.util.function.Function<? super T,Uni<? extends O>> mapper)
For each items emitted by the upstream, the givenmapper
is invoked. Thismapper
returns aUni
. The events emitted by the returnedUni
are emitted downstream. Items emitted by the returnedUnis
are emitted downstream using aconcatenation
, meaning that the returnedMulti
contains the items in the same order as the upstream.For example, let's imagine an upstream multi {a, b, c} and a mapper emitting 1 items. This emission may be delayed for various reasons. For example a -> a1 without delay, b -> b1 after some delay and c -> c1 without delay. Using this method on the multi {a, b c} with that mapper would produce the following multi {a1, b1, c1}. Indeed, even if c1 could be emitted before b1, this method preserves the order. So the items from the produced unis are concatenated.
This operation is often called concatMapSingle.
If the mapper throws an exception, the failure is propagated downstream. No more items will be emitted. If one of the produced
Uni
propagates a failure, the failure is propagated downstream and no more items will be emitted.- Type Parameters:
O
- the type of item emitted by theMulti
produced by the mapper.- Parameters:
mapper
- the mapper, must not benull
, must not producenull
- Returns:
- the resulting multi
-
transformToUniAndMerge
public <O> Multi<O> transformToUniAndMerge(java.util.function.Function<? super T,Uni<? extends O>> mapper)
For each items emitted by the upstream, the givenmapper
is invoked. Thismapper
returns aUni
. The events emitted by the returnedUni
are emitted downstream. Items emitted by the returnedUnis
are emitted downstream using amerge
, meaning that it may interleave events produced by the differentUni
.For example, let's imagine an upstream multi {a, b, c} and a mapper emitting 1 items. This emission may be delayed for various reasons. For example a -> a1 without delay, b -> b1 after some delay and c -> c1 without delay. Using this method on the multi {a, b c} with that mapper would produce the following multi {a1, c1, b1}. Indeed, the b1 item is emitted after c1. So the items from the produced unis are interleaved and are emitted as soon as they are emitted (respecting the downstream request).
This operation is often called flatMapSingle.
If the mapper throws an exception, the failure is propagated downstream. No more items will be emitted. If one of the produced
Uni
propagates a failure, the failure is propagated downstream and no more items will be emitted.- Type Parameters:
O
- the type of item emitted by theMulti
produced by the mapper.- Parameters:
mapper
- the mapper, must not benull
, must not producenull
- Returns:
- the resulting multi
-
ignore
public Multi<java.lang.Void> ignore()
Ignores the passed items. The resultingMulti
will only be notified when the stream completes or fails.- Returns:
- the new multi
-
ignoreAsUni
public Uni<java.lang.Void> ignoreAsUni()
Ignores the passed items. The resultingUni
will only be completed withnull
when the stream completes or with a failure if the upstream emits a failure..- Returns:
- the new multi
-
castTo
public <O> Multi<O> castTo(java.lang.Class<O> target)
Produces anMulti
emitting the item events based on the upstream events but casted to the target class.- Type Parameters:
O
- the type of item emitted by the produced uni- Parameters:
target
- the target class- Returns:
- the new Uni
-
scan
public <S> Multi<S> scan(java.util.function.Supplier<S> initialStateProducer, java.util.function.BiFunction<S,? super T,S> accumulator)
Produces aMulti
that fires items coming from the reduction of the item emitted by this currentMulti
by the passedaccumulator
reduction function. The produced multi emits the intermediate results.Unlike
scan(BinaryOperator)
, this operator uses the value produced by theinitialStateProducer
as first value.- Type Parameters:
S
- the type of item emitted by the producedMulti
. It's the type returned by theaccumulator
operation.- Parameters:
initialStateProducer
- the producer called to provides the initial value passed to the accumulator operation.accumulator
- the reductionBiFunction
, the resultingMulti
emits the results of this method. The method is called for every item emitted by this Multi.- Returns:
- the produced
Multi
-
scan
public Multi<T> scan(java.util.function.BinaryOperator<T> accumulator)
Produces aMulti
that fires results coming from the reduction of the item emitted by this currentMulti
by the passedaccumulator
reduction function. The produced multi emits the intermediate results.Unlike
scan(Supplier, BiFunction)
, this operator doesn't take an initial value but takes the first item emitted by thisMulti
as initial value.
-
failWith
public Multi<T> failWith(java.util.function.Function<? super T,? extends java.lang.Throwable> mapper)
Produces a newMulti
invoking the given function when the currentMulti
fires an item (only once). The function transforms the received item into a failure that will be fired by the producedMulti
. For asynchronous composition, seetransformToUni(Function)
}.The upstream subscription is cancelled after the emission of the first item, as a failure is propagated downstream.
- Parameters:
mapper
- the mapper function, must not benull
, must not returnnull
- Returns:
- the new
Multi
-
failWith
public Multi<T> failWith(java.util.function.Supplier<? extends java.lang.Throwable> supplier)
Produces a newMulti
invoking the given supplier when the currentUni
fires an item. The supplier produce the received item into a failure that will be fired by the producedMulti
.The upstream subscription is cancelled after the emission of the first item, as a failure is propagated downstream.
- Parameters:
supplier
- the supplier to produce the failure, must not benull
, must not producenull
- Returns:
- the new
Multi
-
-