- java.lang.Object
-
- io.smallrye.mutiny.groups.MultiSelect<T>
-
-
Constructor Summary
Constructors Constructor Description MultiSelect(Multi<T> upstream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Multi<T>distinct()Selects all the distinct items from the upstream.Multi<T>distinct(java.util.Comparator<? super T> comparator)Selects all the distinct items from the upstream.Multi<T>first()Select the first item from theMulti.Multi<T>first(long n)Selects the firstnitems from theMulti.Multi<T>first(java.time.Duration duration)Selects the first items for the given duration.Multi<T>first(java.util.function.Predicate<? super T> predicate)Selects the first items while the given predicate returnstrue.Multi<T>last()Select the last item from theMulti.Multi<T>last(int n)Selects the lastnitems from theMulti.Multi<T>when(java.util.function.Function<? super T,Uni<java.lang.Boolean>> predicate)Selects the items where the given function produced aUniemittingtrue.Multi<T>where(java.util.function.Predicate<? super T> predicate)Selects the items where the given predicate returnstrue.Multi<T>where(java.util.function.Predicate<? super T> predicate, int limit)Likewhen(Function), but select at mostlimititems.
-
-
-
Method Detail
-
first
@CheckReturnValue public Multi<T> first()
Select the first item from theMulti.If the upstream
Multicontains more than one item, the others are dropped. If the upstream emits a failure before emitting an item, the producedMultiemits the same failure. If the upstream completes without emitting an item first, the producedMultiis empty.- Returns:
- the resulting
Multi
-
last
@CheckReturnValue public Multi<T> last()
Select the last item from theMulti.If the upstream
Multicontains more than one item, the others are dropped, only the last one is emitted by the producedMulti. If the upstream emits a failure, the producedMultiemits the same failure. If the upstream completes without emitting an item first, the producedMultiis empty.- Returns:
- the resulting
Multi
-
first
@CheckReturnValue public Multi<T> first(long n)
Selects the firstnitems from theMulti.If the upstream
Multicontains more than n items, the others are dropped. If the upstreamMultiemits less than n items, all the items are emitted by the producedMulti. If the upstream emits a failure before emitting n items, the producedMultiemits the same failure after having emitted the first items. If the upstream completes without emitting an item first, the producedMultiis empty.
-
last
@CheckReturnValue public Multi<T> last(int n)
Selects the lastnitems from theMulti.If the upstream
Multicontains more than n items, the others are dropped. If the upstreamMultiemits less than n items, all the items are emitted by the producedMulti. If the upstream emits a failure, the producedMultiemits the same failure after. No items will be emitted by the producedMulti. If the upstream completes without emitting an item first, the producedMultiis empty.
-
first
@CheckReturnValue public Multi<T> first(java.util.function.Predicate<? super T> predicate)
Selects the first items while the given predicate returnstrue. It calls the predicates for each items, until the predicate returnsfalse. Each item for which the predicates returnedtrueis emitted by the producedMulti. As soon as the predicate returnsfalsefor an item, it stops emitting the item and sends the completion event. The last checked item is not emitted.If the upstream
Multiis empty, the producedMultiis empty. If the upstreamMultiis emitting a failure, while the predicate has not returnedfalseyet, the failure is emitted by the producedMulti. If the predicates throws an exception while testing an item, the producedMultiemits that exception as failure. No more items will be tested or emitted. If the predicates returnstruefor each items from upstream, all the items are selected. Once the predicate returnsfalse, it cancels the subscription to the upstream, and completes the producedMulti.- Parameters:
predicate- the predicate to test the items, must not benull- Returns:
- the resulting
Multi
-
first
@CheckReturnValue public Multi<T> first(java.time.Duration duration)
Selects the first items for the given duration. It selects each items emitted after the subscription for the given duration.If the upstream
Multiis empty, the producedMultiis empty. If the upstreamMultiis emitting a failure, before the duration expires, the failure is emitted by the producedMulti. If the upstream completes before the given duration, all the items are selected.Once the duration expires, it cancels the subscription to the upstream, and completes the produced
Multi.- Parameters:
duration- the duration, must not benull, must be strictly positive.- Returns:
- the resulting
Multi
-
where
@CheckReturnValue public Multi<T> where(java.util.function.Predicate<? super T> predicate)
Selects the items where the given predicate returnstrue. It calls the predicates for each items. Each item for which the predicates returnedtrueis emitted by the producedMulti. Others are dropped.If the upstream
Multiis empty, the producedMultiis empty. If the upstreamMultiis emitting a failure, the failure is emitted by the producedMulti. If the predicates throws an exception while testing an item, the producedMultiemits that exception as failure. No more items will be tested or emitted. If the predicates returnstruefor each items from upstream, all the items are selected. The producedMulticompletes when the upstream completes.- Parameters:
predicate- the predicate to test the items, must not benull- Returns:
- the resulting
Multi - See Also:
when(Function)
-
where
@CheckReturnValue public Multi<T> where(java.util.function.Predicate<? super T> predicate, int limit)
Likewhen(Function), but select at mostlimititems.- Parameters:
predicate- the predicate to test the items, must not benulllimit- the maximum number of item to select, must be positive. 0 would produce an emptyMulti- Returns:
- the resulting
Multi - See Also:
when(Function)
-
when
@CheckReturnValue public Multi<T> when(java.util.function.Function<? super T,Uni<java.lang.Boolean>> predicate)
Selects the items where the given function produced aUniemittingtrue. This method is the asynchronous version ofwhere(Predicate). Instead of a synchronous predicate, it accepts a function producingUni. It calls the function for every item, and depending of the producedUni, it emits the item downstream or drops it. If the returnedUniproducestrue, the item is selected and emitted by the producedMulti, otherwise the item is dropped. The item is only emitted whenUniproduced for that item emitstrue.If the upstream
Multiis empty, the producedMultiis empty. If the upstreamMultiis emitting a failure, the failure is emitted by the producedMulti. If the function throws an exception while testing an item, the producedMultiemits that exception as failure. No more items will be tested or emitted. If the function produced anullUni, the producedMultiemits anNullPointerExceptionas failure. No more items will be tested or emitted. If the function produced a failing Uni, the producedMultiemits that failure. No more items will be tested or emitted. If the function produced aUniemittingnull, the producedMultiemits a failure. No more items will be tested or emitted. If the function accepts all the items from the upstream, all the items are selected. The producedMulticompletes when the upstream completes.This method preserves the item orders.
- Parameters:
predicate- the function to test the items, must not benull, must not producednull- Returns:
- the resulting
Multi
-
distinct
@CheckReturnValue public Multi<T> distinct()
Selects all the distinct items from the upstream. This methods usesObject.hashCode()to compare items.Do NOT call this method on unbounded upstream, as it would lead to an
OutOfMemoryError.If the comparison throws an exception, the produced
Multifails. The producedMulticompletes when the upstream sends the completion event.- Returns:
- the resulting
Multi. - See Also:
MultiSkip.repetitions(),distinct(Comparator)
-
distinct
@CheckReturnValue public Multi<T> distinct(java.util.Comparator<? super T> comparator)
Selects all the distinct items from the upstream. This methods uses the given comparator to compare the items.Do NOT call this method on unbounded upstream, as it would lead to an
OutOfMemoryError.If the comparison throws an exception, the produced
Multifails. The producedMulticompletes when the upstream sends the completion event.Unlike
distinct()which uses aHashSetinternally, this variant uses aTreeSetinitialized with the given comparator. If the comparator isnull, it uses aHashSetas backend.- Parameters:
comparator- the comparator used to compare items. Ifnull, it will uses the item'shashCodemethod.- Returns:
- the resulting
Multi. - See Also:
MultiSkip.repetitions()
-
-