Class Maybe<T>
- java.lang.Object
-
- io.reactivex.rxjava3.core.Maybe<T>
-
- Type Parameters:
T
- the value type
- All Implemented Interfaces:
MaybeSource<T>
- Direct Known Subclasses:
AbstractMaybeWithUpstream
,CompletableOnErrorReturn
,FlowableElementAtMaybe
,FlowableElementAtMaybePublisher
,FlowableLastMaybe
,FlowableReduceMaybe
,FlowableSingleMaybe
,MaybeAmb
,MaybeCache
,MaybeCreate
,MaybeDefer
,MaybeDelayWithCompletable
,MaybeDoOnTerminate
,MaybeEmpty
,MaybeError
,MaybeErrorCallable
,MaybeFilterSingle
,MaybeFlatMapSingle
,MaybeFromAction
,MaybeFromCallable
,MaybeFromCompletable
,MaybeFromCompletionStage
,MaybeFromFuture
,MaybeFromRunnable
,MaybeFromSingle
,MaybeFromSupplier
,MaybeJust
,MaybeMapOptional
,MaybeNever
,MaybeSubject
,MaybeTimeInterval
,MaybeTimer
,MaybeUsing
,MaybeZipArray
,MaybeZipIterable
,ObservableElementAtMaybe
,ObservableLastMaybe
,ObservableReduceMaybe
,ObservableSingleMaybe
,SingleDematerialize
,SingleFlatMapMaybe
,SingleMapOptional
,SingleOnErrorComplete
public abstract class Maybe<@NonNull T> extends java.lang.Object implements MaybeSource<T>
TheMaybe
class represents a deferred computation and emission of a single value, no value at all or an exception.The
Maybe
class implements theMaybeSource
base interface and the default consumer type it interacts with is theMaybeObserver
via thesubscribe(MaybeObserver)
method.The
Maybe
operates with the following sequential protocol:onSubscribe (onSuccess | onError | onComplete)?
Note that
onSuccess
,onError
andonComplete
are mutually exclusive events; unlikeObservable
,onSuccess
is never followed byonError
oronComplete
.Like
Observable
, a runningMaybe
can be stopped through theDisposable
instance provided to consumers throughMaybeObserver.onSubscribe(io.reactivex.rxjava3.disposables.Disposable)
.Like an
Observable
, aMaybe
is lazy, can be either "hot" or "cold", synchronous or asynchronous.Maybe
instances returned by the methods of this class are cold and there is a standard hot implementation in the form of a subject:MaybeSubject
.The documentation for this class makes use of marble diagrams. The following legend explains these diagrams:
See
Flowable
orObservable
for the implementation of the Reactive Pattern for a stream or vector of values.Example:
Disposable d = Maybe.just("Hello World") .delay(10, TimeUnit.SECONDS, Schedulers.io()) .subscribeWith(new DisposableMaybeObserver<String>() { @Override public void onStart() { System.out.println("Started"); } @Override public void onSuccess(String value) { System.out.println("Success: " + value); } @Override public void onError(Throwable error) { error.printStackTrace(); } @Override public void onComplete() { System.out.println("Done!"); } }); Thread.sleep(5000); d.dispose();
Note that by design, subscriptions via
subscribe(MaybeObserver)
can't be disposed from the outside (hence thevoid
return of thesubscribe(MaybeObserver)
method) and it is the responsibility of the implementor of theMaybeObserver
to allow this to happen. RxJava supports such usage with the standardDisposableMaybeObserver
instance. For convenience, thesubscribeWith(MaybeObserver)
method is provided as well to allow working with aMaybeObserver
(or subclass) instance to be applied with in a fluent manner (such as in the example above).- Since:
- 2.0
- See Also:
DisposableMaybeObserver
-
-
Constructor Summary
Constructors Constructor Description Maybe()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <@NonNull T>
@NonNull Maybe<T>amb(@NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Runs multipleMaybeSource
s provided by anIterable
sequence and signals the events of the first one that signals (disposing the rest).static <@NonNull T>
@NonNull Maybe<T>ambArray(@NonNull MaybeSource<? extends @NonNull T>... sources)
Runs multipleMaybeSource
s and signals the events of the first one that signals (disposing the rest).@NonNull Maybe<T>
ambWith(@NonNull MaybeSource<? extends @NonNull T> other)
Mirrors theMaybeSource
(current or provided) that first signals an event.T
blockingGet()
Waits in a blocking fashion until the currentMaybe
signals a success value (which is returned),null
if completed or an exception (which is propagated).T
blockingGet(@NonNull T defaultValue)
Waits in a blocking fashion until the currentMaybe
signals a success value (which is returned), defaultValue if completed or an exception (which is propagated).void
blockingSubscribe()
Subscribes to the currentMaybe
and blocks the current thread until it terminates.void
blockingSubscribe(@NonNull MaybeObserver<? super @NonNull T> observer)
Subscribes to the currentMaybe
and calls the appropriateMaybeObserver
method on the current thread.void
blockingSubscribe(@NonNull Consumer<? super @NonNull T> onSuccess)
Subscribes to the currentMaybe
and calls givenonSuccess
callback on the current thread when it completes normally.void
blockingSubscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super java.lang.Throwable> onError)
Subscribes to the currentMaybe
and calls the appropriate callback on the current thread when it terminates.void
blockingSubscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super java.lang.Throwable> onError, @NonNull Action onComplete)
Subscribes to the currentMaybe
and calls the appropriate callback on the current thread when it terminates.@NonNull Maybe<T>
cache()
Returns aMaybe
that subscribes to thisMaybe
lazily, caches its event and replays it, to all the downstream subscribers.<@NonNull U>
@NonNull Maybe<U>cast(@NonNull java.lang.Class<? extends @NonNull U> clazz)
Casts the success value of the currentMaybe
into the target type or signals aClassCastException
if not compatible.<@NonNull R>
@NonNull Maybe<R>compose(@NonNull MaybeTransformer<? super @NonNull T,? extends @NonNull R> transformer)
Transform aMaybe
by applying a particularMaybeTransformer
function to it.static <@NonNull T>
@NonNull Flowable<T>concat(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2)
Returns aFlowable
that emits the items emitted by twoMaybeSource
s, one after the other.static <@NonNull T>
@NonNull Flowable<T>concat(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull MaybeSource<? extends @NonNull T> source3)
Returns aFlowable
that emits the items emitted by threeMaybeSource
s, one after the other.static <@NonNull T>
@NonNull Flowable<T>concat(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull MaybeSource<? extends @NonNull T> source3, @NonNull MaybeSource<? extends @NonNull T> source4)
Returns aFlowable
that emits the items emitted by fourMaybeSource
s, one after the other.static <@NonNull T>
@NonNull Flowable<T>concat(@NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenate the single values, in a non-overlapping fashion, of theMaybeSource
sources provided by anIterable
sequence as aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concat(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenate the single values, in a non-overlapping fashion, of theMaybeSource
sources provided by aPublisher
sequence as aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concat(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources, int prefetch)
Concatenate the single values, in a non-overlapping fashion, of theMaybeSource
sources provided by aPublisher
sequence as aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concatArray(@NonNull MaybeSource<? extends @NonNull T>... sources)
Concatenate the single values, in a non-overlapping fashion, of theMaybeSource
sources in the array as aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concatArrayDelayError(@NonNull MaybeSource<? extends @NonNull T>... sources)
Concatenates a variable number ofMaybeSource
sources and delays errors from any of them till all terminate as aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concatArrayEager(@NonNull MaybeSource<? extends @NonNull T>... sources)
Concatenates a sequence ofMaybeSource
eagerly into aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concatArrayEagerDelayError(@NonNull MaybeSource<? extends @NonNull T>... sources)
Concatenates a sequence ofMaybeSource
eagerly into aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concatDelayError(@NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenates theIterable
sequence ofMaybeSource
s into a single sequence by subscribing to eachMaybeSource
, one after the other, one at a time and delays any errors till the all innerMaybeSource
s terminate as aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concatDelayError(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenates thePublisher
sequence ofMaybeSource
s into a single sequence by subscribing to each innerMaybeSource
, one after the other, one at a time and delays any errors till the all inner and the outerPublisher
terminate as aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concatDelayError(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources, int prefetch)
Concatenates thePublisher
sequence ofMaybeSource
s into a single sequence by subscribing to each innerMaybeSource
, one after the other, one at a time and delays any errors till the all inner and the outerPublisher
terminate as aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concatEager(@NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenates a sequence ofMaybeSource
s eagerly into aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concatEager(@NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates a sequence ofMaybeSource
s eagerly into aFlowable
sequence and runs a limited number of the inner sequences at once.static <@NonNull T>
@NonNull Flowable<T>concatEager(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
static <@NonNull T>
@NonNull Flowable<T>concatEager(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates aPublisher
sequence ofMaybeSource
s eagerly into aFlowable
sequence, running at most the given number of innerMaybeSource
s at once.static <@NonNull T>
@NonNull Flowable<T>concatEagerDelayError(@NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenates a sequence ofMaybeSource
s eagerly into aFlowable
sequence, delaying errors until all innerMaybeSource
s terminate.static <@NonNull T>
@NonNull Flowable<T>concatEagerDelayError(@NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates a sequence ofMaybeSource
s eagerly into aFlowable
sequence, delaying errors until all innerMaybeSource
s terminate and runs a limited number of innerMaybeSource
s at once.static <@NonNull T>
@NonNull Flowable<T>concatEagerDelayError(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenates aPublisher
sequence ofMaybeSource
s eagerly into aFlowable
sequence, delaying errors until all the inner and the outer sequence terminate.static <@NonNull T>
@NonNull Flowable<T>concatEagerDelayError(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates aPublisher
sequence ofMaybeSource
s eagerly into aFlowable
sequence, delaying errors until all the inner and the outer sequence terminate and runs a limited number of the innerMaybeSource
s at once.<@NonNull R>
@NonNull Maybe<R>concatMap(@NonNull Function<? super @NonNull T,? extends MaybeSource<? extends @NonNull R>> mapper)
Returns aMaybe
that is based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aMaybeSource
.@NonNull Completable
concatMapCompletable(@NonNull Function<? super @NonNull T,? extends CompletableSource> mapper)
Returns aCompletable
that completes based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aCompletable
.<@NonNull R>
@NonNull Maybe<R>concatMapSingle(@NonNull Function<? super @NonNull T,? extends SingleSource<? extends @NonNull R>> mapper)
Returns aMaybe
based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aSingle
.@NonNull Flowable<T>
concatWith(@NonNull MaybeSource<? extends @NonNull T> other)
Returns aFlowable
that emits the items emitted from the currentMaybe
, then theother
MaybeSource
, one after the other, without interleaving them.@NonNull Single<java.lang.Boolean>
contains(@NonNull java.lang.Object item)
Returns aSingle
that emits aBoolean
that indicates whether the currentMaybe
emitted a specified item.@NonNull Single<java.lang.Long>
count()
Returns aSingle
that counts the total number of items emitted (0 or 1) by the currentMaybe
and emits this count as a 64-bitLong
.static <@NonNull T>
@NonNull Maybe<T>create(@NonNull MaybeOnSubscribe<@NonNull T> onSubscribe)
Provides an API (via a coldMaybe
) that bridges the reactive world with the callback-style world.@NonNull Single<T>
defaultIfEmpty(@NonNull T defaultItem)
Returns aSingle
that emits the item emitted by the currentMaybe
or a specified default item if the currentMaybe
is empty.static <@NonNull T>
@NonNull Maybe<T>defer(@NonNull Supplier<? extends @NonNull MaybeSource<? extends @NonNull T>> supplier)
Calls aSupplier
for each individualMaybeObserver
to return the actualMaybeSource
source to be subscribed to.@NonNull Maybe<T>
delay(long time, @NonNull java.util.concurrent.TimeUnit unit)
Returns aMaybe
that signals the events emitted by the currentMaybe
shifted forward in time by a specified delay.@NonNull Maybe<T>
delay(long time, @NonNull java.util.concurrent.TimeUnit unit, boolean delayError)
Returns aMaybe
that signals the events emitted by the currentMaybe
shifted forward in time by a specified delay.@NonNull Maybe<T>
delay(long time, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
Returns aMaybe
that signals the events emitted by the currentMaybe
shifted forward in time by a specified delay.@NonNull Maybe<T>
delay(long time, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler, boolean delayError)
Returns aMaybe
that signals the events emitted by the currentMaybe
shifted forward in time by a specified delay running on the specifiedScheduler
.<@NonNull U>
@NonNull Maybe<T>delay(@NonNull org.reactivestreams.Publisher<@NonNull U> delayIndicator)
Delays the emission of thisMaybe
until the givenPublisher
signals an item or completes.@NonNull Maybe<T>
delaySubscription(long time, @NonNull java.util.concurrent.TimeUnit unit)
Returns aMaybe
that delays the subscription to the currentMaybe
by a given amount of time.@NonNull Maybe<T>
delaySubscription(long time, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
Returns aMaybe
that delays the subscription to the currentMaybe
by a given amount of time, both waiting and subscribing on a givenScheduler
.<@NonNull U>
@NonNull Maybe<T>delaySubscription(@NonNull org.reactivestreams.Publisher<@NonNull U> subscriptionIndicator)
Returns aMaybe
that delays the subscription to thisMaybe
until the otherPublisher
emits an element or completes normally.<@NonNull R>
@NonNull Maybe<R>dematerialize(@NonNull Function<? super @NonNull T,@NonNull Notification<@NonNull R>> selector)
Maps theNotification
success value of the currentMaybe
back into normalonSuccess
,onError
oronComplete
signals.@NonNull Maybe<T>
doAfterSuccess(@NonNull Consumer<? super @NonNull T> onAfterSuccess)
Calls the specifiedConsumer
with the success item after this item has been emitted to the downstream.@NonNull Maybe<T>
doAfterTerminate(@NonNull Action onAfterTerminate)
@NonNull Maybe<T>
doFinally(@NonNull Action onFinally)
Calls the specified action after thisMaybe
signalsonSuccess
,onError
oronComplete
or gets disposed by the downstream.@NonNull Maybe<T>
doOnComplete(@NonNull Action onComplete)
@NonNull Maybe<T>
doOnDispose(@NonNull Action onDispose)
Calls the sharedAction
if aMaybeObserver
subscribed to the currentMaybe
disposes the commonDisposable
it received viaonSubscribe
.@NonNull Maybe<T>
doOnError(@NonNull Consumer<? super java.lang.Throwable> onError)
Calls the sharedConsumer
with the error sent viaonError
for eachMaybeObserver
that subscribes to the currentMaybe
.@NonNull Maybe<T>
doOnEvent(@NonNull BiConsumer<? super @NonNull T,? super java.lang.Throwable> onEvent)
Calls the givenonEvent
callback with the (success value,null
) for anonSuccess
, (null
, throwable) for anonError
or (null
,null
) for anonComplete
signal from thisMaybe
before delivering said signal to the downstream.@NonNull Maybe<T>
doOnLifecycle(@NonNull Consumer<? super Disposable> onSubscribe, @NonNull Action onDispose)
Calls the appropriateonXXX
method (shared between allMaybeObserver
s) for the lifecycle events of the sequence (subscription, disposal).@NonNull Maybe<T>
doOnSubscribe(@NonNull Consumer<? super Disposable> onSubscribe)
Calls the sharedConsumer
with theDisposable
sent through theonSubscribe
for eachMaybeObserver
that subscribes to the currentMaybe
.@NonNull Maybe<T>
doOnSuccess(@NonNull Consumer<? super @NonNull T> onSuccess)
Calls the sharedConsumer
with the success value sent viaonSuccess
for eachMaybeObserver
that subscribes to the currentMaybe
.@NonNull Maybe<T>
doOnTerminate(@NonNull Action onTerminate)
Returns aMaybe
instance that calls the given onTerminate callback just before thisMaybe
completes normally or with an exception.static <@NonNull T>
@NonNull Maybe<T>empty()
Returns a (singleton)Maybe
instance that callsonComplete
immediately.static <@NonNull T>
@NonNull Maybe<T>error(@NonNull Supplier<? extends @NonNull java.lang.Throwable> supplier)
Returns aMaybe
that invokes aMaybeObserver
'sonError
method when theMaybeObserver
subscribes to it.static <@NonNull T>
@NonNull Maybe<T>error(@NonNull java.lang.Throwable throwable)
Returns aMaybe
that invokes a subscriber'sonError
method when the subscriber subscribes to it.@NonNull Maybe<T>
filter(@NonNull Predicate<? super @NonNull T> predicate)
Filters the success item of theMaybe
via a predicate function and emitting it if the predicate returnstrue
, completing otherwise.<@NonNull R>
@NonNull Maybe<R>flatMap(@NonNull Function<? super @NonNull T,? extends MaybeSource<? extends @NonNull R>> mapper)
Returns aMaybe
that is based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aMaybeSource
.<@NonNull R>
@NonNull Maybe<R>flatMap(@NonNull Function<? super @NonNull T,? extends MaybeSource<? extends @NonNull R>> onSuccessMapper, @NonNull Function<? super java.lang.Throwable,? extends MaybeSource<? extends @NonNull R>> onErrorMapper, @NonNull Supplier<? extends MaybeSource<? extends @NonNull R>> onCompleteSupplier)
Maps theonSuccess
,onError
oronComplete
signals of the currentMaybe
into aMaybeSource
and emits thatMaybeSource
's signals.<@NonNull U,@NonNull R>
@NonNull Maybe<R>flatMap(@NonNull Function<? super @NonNull T,? extends MaybeSource<? extends @NonNull U>> mapper, @NonNull BiFunction<? super @NonNull T,? super @NonNull U,? extends @NonNull R> combiner)
Returns aMaybe
that emits the results of a specified function to the pair of values emitted by the currentMaybe
and a specified mappedMaybeSource
.@NonNull Completable
flatMapCompletable(@NonNull Function<? super @NonNull T,? extends CompletableSource> mapper)
Returns aCompletable
that completes based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aCompletable
.<@NonNull R>
@NonNull Observable<R>flatMapObservable(@NonNull Function<? super @NonNull T,? extends ObservableSource<? extends @NonNull R>> mapper)
Returns anObservable
that is based on applying a specified function to the item emitted by the currentMaybe
, where that function returns anObservableSource
.<@NonNull R>
@NonNull Flowable<R>flatMapPublisher(@NonNull Function<? super @NonNull T,? extends org.reactivestreams.Publisher<? extends @NonNull R>> mapper)
Returns aFlowable
that emits items based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aPublisher
.<@NonNull R>
@NonNull Maybe<R>flatMapSingle(@NonNull Function<? super @NonNull T,? extends SingleSource<? extends @NonNull R>> mapper)
Returns aMaybe
based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aSingle
.<@NonNull U>
@NonNull Flowable<U>flattenAsFlowable(@NonNull Function<? super @NonNull T,? extends java.lang.Iterable<? extends @NonNull U>> mapper)
Maps the success value of the currentMaybe
into anIterable
and emits its items as aFlowable
sequence.<@NonNull U>
@NonNull Observable<U>flattenAsObservable(@NonNull Function<? super @NonNull T,? extends java.lang.Iterable<? extends @NonNull U>> mapper)
Maps the success value of the currentMaybe
into anIterable
and emits its items as anObservable
sequence.<@NonNull R>
@NonNull Flowable<R>flattenStreamAsFlowable(@NonNull Function<? super @NonNull T,? extends java.util.stream.Stream<? extends @NonNull R>> mapper)
Maps the upstream succecss value into a JavaStream
and emits its items to the downstream consumer as aFlowable
.<@NonNull R>
@NonNull Observable<R>flattenStreamAsObservable(@NonNull Function<? super @NonNull T,? extends java.util.stream.Stream<? extends @NonNull R>> mapper)
Maps the upstream succecss value into a JavaStream
and emits its items to the downstream consumer as anObservable
.static <@NonNull T>
@NonNull Maybe<T>fromAction(@NonNull Action action)
Returns aMaybe
instance that runs the givenAction
for eachMaybeObserver
and emits either its exception or simply completes.static <T> @NonNull Maybe<@NonNull T>
fromCallable(@NonNull java.util.concurrent.Callable<? extends @Nullable T> callable)
Returns aMaybe
that invokes the givenCallable
for each individualMaybeObserver
that subscribes and emits the resulting non-null
item viaonSuccess
while considering anull
result from theCallable
as indication for valueless completion viaonComplete
.static <@NonNull T>
@NonNull Maybe<T>fromCompletable(@NonNull CompletableSource completableSource)
Wraps aCompletableSource
into aMaybe
.static <@NonNull T>
@NonNull Maybe<@NonNull T>fromCompletionStage(@NonNull java.util.concurrent.CompletionStage<@NonNull T> stage)
Signals the completion value or error of the given (hot)CompletionStage
-based asynchronous calculation.static <@NonNull T>
@NonNull Maybe<T>fromFuture(@NonNull java.util.concurrent.Future<? extends @NonNull T> future)
Converts aFuture
into aMaybe
, treating anull
result as an indication of emptiness.static <@NonNull T>
@NonNull Maybe<T>fromFuture(@NonNull java.util.concurrent.Future<? extends @NonNull T> future, long timeout, @NonNull java.util.concurrent.TimeUnit unit)
Converts aFuture
into aMaybe
, with a timeout on theFuture
.static <@NonNull T>
@NonNull Maybe<T>fromObservable(@NonNull ObservableSource<@NonNull T> source)
Wraps anObservableSource
into aMaybe
and emits the very first item or completes if the source is empty.static <@NonNull T>
@NonNull Maybe<@NonNull T>fromOptional(@NonNull java.util.Optional<@NonNull T> optional)
Converts the existing value of the provided optional into ajust(Object)
or an empty optional into anempty()
Maybe
instance.static <@NonNull T>
@NonNull Maybe<T>fromPublisher(@NonNull org.reactivestreams.Publisher<@NonNull T> source)
Wraps aPublisher
into aMaybe
and emits the very first item or completes if the source is empty.static <@NonNull T>
@NonNull Maybe<T>fromRunnable(@NonNull java.lang.Runnable run)
Returns aMaybe
instance that runs the givenRunnable
for eachMaybeObserver
and emits either its unchecked exception or simply completes.static <@NonNull T>
@NonNull Maybe<T>fromSingle(@NonNull SingleSource<@NonNull T> single)
Wraps aSingleSource
into aMaybe
.static <T> @NonNull Maybe<@NonNull T>
fromSupplier(@NonNull Supplier<? extends @Nullable T> supplier)
Returns aMaybe
that invokes the givenSupplier
for each individualMaybeObserver
that subscribes and emits the resulting non-null
item viaonSuccess
while considering anull
result from theSupplier
as indication for valueless completion viaonComplete
.@NonNull Maybe<T>
hide()
Hides the identity of thisMaybe
and itsDisposable
.@NonNull Completable
ignoreElement()
Returns aCompletable
that ignores the item emitted by the currentMaybe
and only callsonComplete
oronError
.@NonNull Single<java.lang.Boolean>
isEmpty()
static <@NonNull T>
@NonNull Maybe<T>just(@NonNull T item)
Returns aMaybe
that emits a specified item.<@NonNull R>
@NonNull Maybe<R>lift(@NonNull MaybeOperator<? extends @NonNull R,? super @NonNull T> lift)
This method requires advanced knowledge about building operators, please consider other standard composition methods first; Returns aMaybe
which, when subscribed to, invokes theapply(MaybeObserver)
method of the providedMaybeOperator
for each individual downstreamMaybe
and allows the insertion of a custom operator by accessing the downstream'sMaybeObserver
during this subscription phase and providing a newMaybeObserver
, containing the custom operator's intended business logic, that will be used in the subscription process going further upstream.<@NonNull R>
@NonNull Maybe<R>map(@NonNull Function<? super @NonNull T,? extends @NonNull R> mapper)
Returns aMaybe
that applies a specified function to the item emitted by the currentMaybe
and emits the result of this function application.<@NonNull R>
@NonNull Maybe<R>mapOptional(@NonNull Function<? super @NonNull T,@NonNull java.util.Optional<? extends @NonNull R>> mapper)
Maps the upstream success value into anOptional
and emits the contained item if not empty.@NonNull Single<Notification<T>>
materialize()
Maps the signal types of thisMaybe
into aNotification
of the same kind and emits it as aSingle
'sonSuccess
value to downstream.static <@NonNull T>
@NonNull Maybe<T>merge(@NonNull MaybeSource<? extends MaybeSource<? extends @NonNull T>> source)
Flattens aMaybeSource
that emits aMaybeSource
into a singleMaybeSource
that emits the item emitted by the nestedMaybeSource
, without any transformation.static <@NonNull T>
@NonNull Flowable<T>merge(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2)
Flattens twoMaybeSource
s into a singleFlowable
, without any transformation.static <@NonNull T>
@NonNull Flowable<T>merge(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull MaybeSource<? extends @NonNull T> source3)
Flattens threeMaybeSource
s into a singleFlowable
, without any transformation.static <@NonNull T>
@NonNull Flowable<T>merge(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull MaybeSource<? extends @NonNull T> source3, @NonNull MaybeSource<? extends @NonNull T> source4)
Flattens fourMaybeSource
s into a singleFlowable
, without any transformation.static <@NonNull T>
@NonNull Flowable<T>merge(@NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Merges anIterable
sequence ofMaybeSource
instances into a singleFlowable
sequence, running allMaybeSource
s at once.static <@NonNull T>
@NonNull Flowable<T>merge(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Merges aPublisher
sequence ofMaybeSource
instances into a singleFlowable
sequence, running allMaybeSource
s at once.static <@NonNull T>
@NonNull Flowable<T>merge(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency)
Merges aPublisher
sequence ofMaybeSource
instances into a singleFlowable
sequence, running at most maxConcurrencyMaybeSource
s at once.static <@NonNull T>
@NonNull Flowable<T>mergeArray(MaybeSource<? extends @NonNull T>... sources)
Merges an array ofMaybeSource
instances into a singleFlowable
sequence, running allMaybeSource
s at once.static <@NonNull T>
@NonNull Flowable<T>mergeArrayDelayError(@NonNull MaybeSource<? extends @NonNull T>... sources)
Flattens an array ofMaybeSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceMaybeSource
s without being interrupted by an error notification from one of them.static <@NonNull T>
@NonNull Flowable<T>mergeDelayError(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2)
Flattens twoMaybeSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceMaybeSource
s without being interrupted by an error notification from one of them.static <@NonNull T>
@NonNull Flowable<T>mergeDelayError(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull MaybeSource<? extends @NonNull T> source3)
Flattens threeMaybeSource
into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSource
s without being interrupted by an error notification from one of them.static <@NonNull T>
@NonNull Flowable<T>mergeDelayError(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull MaybeSource<? extends @NonNull T> source3, @NonNull MaybeSource<? extends @NonNull T> source4)
Flattens fourMaybeSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSource
s without being interrupted by an error notification from one of them.static <@NonNull T>
@NonNull Flowable<T>mergeDelayError(@NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Flattens anIterable
sequence ofMaybeSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceMaybeSource
s without being interrupted by an error notification from one of them.static <@NonNull T>
@NonNull Flowable<T>mergeDelayError(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Flattens aPublisher
that emitsMaybeSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSource
s without being interrupted by an error notification from one of them or even the mainPublisher
.static <@NonNull T>
@NonNull Flowable<T>mergeDelayError(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency)
Flattens aPublisher
that emitsMaybeSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSource
s without being interrupted by an error notification from one of them or even the mainPublisher
as well as limiting the total number of activeMaybeSource
s.@NonNull Flowable<T>
mergeWith(@NonNull MaybeSource<? extends @NonNull T> other)
static <@NonNull T>
@NonNull Maybe<T>never()
Returns aMaybe
that never sends any items or notifications to aMaybeObserver
.@NonNull Maybe<T>
observeOn(@NonNull Scheduler scheduler)
Wraps aMaybe
to emit its item (or notify of its error) on a specifiedScheduler
, asynchronously.<@NonNull U>
@NonNull Maybe<U>ofType(@NonNull java.lang.Class<@NonNull U> clazz)
Filters the items emitted by the currentMaybe
, only emitting its success value if that is an instance of the suppliedClass
.@NonNull Maybe<T>
onErrorComplete()
Returns aMaybe
instance that if thisMaybe
emits an error, it will emit anonComplete
and swallow the throwable.@NonNull Maybe<T>
onErrorComplete(@NonNull Predicate<? super java.lang.Throwable> predicate)
Returns aMaybe
instance that if thisMaybe
emits an error and the predicate returnstrue
, it will emit anonComplete
and swallow the throwable.@NonNull Maybe<T>
onErrorResumeNext(@NonNull Function<? super java.lang.Throwable,? extends MaybeSource<? extends @NonNull T>> fallbackSupplier)
Resumes the flow with aMaybeSource
returned for the failureThrowable
of the currentMaybe
by a function instead of signaling the error viaonError
.@NonNull Maybe<T>
onErrorResumeWith(@NonNull MaybeSource<? extends @NonNull T> fallback)
Resumes the flow with the givenMaybeSource
when the currentMaybe
fails instead of signaling the error viaonError
.@NonNull Maybe<T>
onErrorReturn(@NonNull Function<? super java.lang.Throwable,? extends @NonNull T> itemSupplier)
Ends the flow with a success item returned by a function for theThrowable
error signaled by the currentMaybe
instead of signaling the error viaonError
.@NonNull Maybe<T>
onErrorReturnItem(@NonNull T item)
Ends the flow with the given success item when the currentMaybe
fails instead of signaling the error viaonError
.@NonNull Maybe<T>
onTerminateDetach()
Nulls out references to the upstream producer and downstreamMaybeObserver
if the sequence is terminated or downstream callsdispose()
.@NonNull Flowable<T>
repeat()
Returns aFlowable
that repeats the sequence of items emitted by the currentMaybe
indefinitely.@NonNull Flowable<T>
repeat(long times)
Returns aFlowable
that repeats the sequence of items emitted by the currentMaybe
at mostcount
times.@NonNull Flowable<T>
repeatUntil(@NonNull BooleanSupplier stop)
Returns aFlowable
that repeats the sequence of items emitted by the currentMaybe
until the provided stop function returnstrue
.@NonNull Flowable<T>
repeatWhen(@NonNull Function<? super Flowable<java.lang.Object>,? extends org.reactivestreams.Publisher<?>> handler)
Returns aFlowable
that emits the same values as the currentMaybe
with the exception of anonComplete
.@NonNull Maybe<T>
retry()
Returns aMaybe
that mirrors the currentMaybe
, resubscribing to it if it callsonError
(infinite retry count).@NonNull Maybe<T>
retry(long times)
Returns aMaybe
that mirrors the currentMaybe
, resubscribing to it if it callsonError
up to a specified number of retries.@NonNull Maybe<T>
retry(long times, @NonNull Predicate<? super java.lang.Throwable> predicate)
Retries at mosttimes
or until the predicate returnsfalse
, whichever happens first.@NonNull Maybe<T>
retry(@NonNull BiPredicate<? super java.lang.Integer,? super java.lang.Throwable> predicate)
Returns aMaybe
that mirrors the currentMaybe
, resubscribing to it if it callsonError
and the predicate returnstrue
for that specific exception and retry count.@NonNull Maybe<T>
retry(@NonNull Predicate<? super java.lang.Throwable> predicate)
Retries the currentMaybe
if it fails and the predicate returnstrue
.@NonNull Maybe<T>
retryUntil(@NonNull BooleanSupplier stop)
Retries until the given stop function returnstrue
.@NonNull Maybe<T>
retryWhen(@NonNull Function<? super Flowable<java.lang.Throwable>,? extends org.reactivestreams.Publisher<?>> handler)
Returns aMaybe
that emits the same values as the currentMaybe
with the exception of anonError
.void
safeSubscribe(@NonNull MaybeObserver<? super @NonNull T> observer)
Wraps the givenMaybeObserver
, catches anyRuntimeException
s thrown by itsMaybeObserver.onSubscribe(Disposable)
,MaybeObserver.onSuccess(Object)
,MaybeObserver.onError(Throwable)
orMaybeObserver.onComplete()
methods and routes those to the global error handler viaRxJavaPlugins.onError(Throwable)
.static <@NonNull T>
@NonNull Single<java.lang.Boolean>sequenceEqual(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2)
Returns aSingle
that emits aBoolean
value that indicates whether twoMaybeSource
sequences are the same by comparing the items emitted by eachMaybeSource
pairwise.static <@NonNull T>
@NonNull Single<java.lang.Boolean>sequenceEqual(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull BiPredicate<? super @NonNull T,? super @NonNull T> isEqual)
Returns aSingle
that emits aBoolean
value that indicates whether twoMaybeSource
s are the same by comparing the items emitted by eachMaybeSource
pairwise based on the results of a specified equality function.@NonNull Flowable<T>
startWith(@NonNull CompletableSource other)
Returns aFlowable
which first runs the otherCompletableSource
then the currentMaybe
if the other completed normally.@NonNull Flowable<T>
startWith(@NonNull MaybeSource<@NonNull T> other)
Returns aFlowable
which first runs the otherMaybeSource
then the currentMaybe
if the other succeeded or completed normally.@NonNull Observable<T>
startWith(@NonNull ObservableSource<@NonNull T> other)
Returns anObservable
which first delivers the events of the otherObservableSource
then runs the currentMaybe
.@NonNull Flowable<T>
startWith(@NonNull SingleSource<@NonNull T> other)
Returns aFlowable
which first runs the otherSingleSource
then the currentMaybe
if the other succeeded normally.@NonNull Flowable<T>
startWith(@NonNull org.reactivestreams.Publisher<@NonNull T> other)
Returns aFlowable
which first delivers the events of the otherPublisher
then runs the currentMaybe
.@NonNull Disposable
subscribe()
Subscribes to aMaybe
and ignoresonSuccess
andonComplete
emissions.void
subscribe(@NonNull MaybeObserver<? super @NonNull T> observer)
Subscribes the givenMaybeObserver
to thisMaybeSource
instance.@NonNull Disposable
subscribe(@NonNull Consumer<? super @NonNull T> onSuccess)
Subscribes to aMaybe
and provides a callback to handle the items it emits.@NonNull Disposable
subscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super java.lang.Throwable> onError)
Subscribes to aMaybe
and provides callbacks to handle the items it emits and any error notification it issues.@NonNull Disposable
subscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super java.lang.Throwable> onError, @NonNull Action onComplete)
Subscribes to aMaybe
and provides callbacks to handle the items it emits and any error or completion notification it issues.@NonNull Disposable
subscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super java.lang.Throwable> onError, @NonNull Action onComplete, @NonNull DisposableContainer container)
Wraps the given onXXX callbacks into aDisposable
MaybeObserver
, adds it to the givenDisposableContainer
and ensures, that if the upstream terminates or this particularDisposable
is disposed, theMaybeObserver
is removed from the given composite.protected abstract void
subscribeActual(@NonNull MaybeObserver<? super @NonNull T> observer)
Implement this method in subclasses to handle the incomingMaybeObserver
s.@NonNull Maybe<T>
subscribeOn(@NonNull Scheduler scheduler)
Asynchronously subscribes subscribers to thisMaybe
on the specifiedScheduler
.<@NonNull E extends MaybeObserver<? super @NonNull T>>
EsubscribeWith(@NonNull E observer)
Subscribes a givenMaybeObserver
(subclass) to thisMaybe
and returns the givenMaybeObserver
as is.@NonNull Maybe<T>
switchIfEmpty(@NonNull MaybeSource<? extends @NonNull T> other)
Returns aMaybe
that emits the items emitted by the currentMaybe
or the items of an alternateMaybeSource
if the currentMaybe
is empty.@NonNull Single<T>
switchIfEmpty(@NonNull SingleSource<? extends @NonNull T> other)
Returns aSingle
that emits the items emitted by the currentMaybe
or the item of an alternateSingleSource
if the currentMaybe
is empty.static <@NonNull T>
@NonNull Flowable<T>switchOnNext(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Switches betweenMaybeSource
s emitted by the sourcePublisher
whenever a newMaybeSource
is emitted, disposing the previously runningMaybeSource
, exposing the success items as aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>switchOnNextDelayError(@NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Switches betweenMaybeSource
s emitted by the sourcePublisher
whenever a newMaybeSource
is emitted, disposing the previously runningMaybeSource
, exposing the success items as aFlowable
sequence and delaying all errors from all of them until all terminate.<@NonNull U>
@NonNull Maybe<T>takeUntil(@NonNull MaybeSource<@NonNull U> other)
Returns aMaybe
that emits the items emitted by the currentMaybe
until a secondMaybeSource
emits an item.<@NonNull U>
@NonNull Maybe<T>takeUntil(@NonNull org.reactivestreams.Publisher<@NonNull U> other)
Returns aMaybe
that emits the item emitted by the currentMaybe
until a secondPublisher
emits an item.@NonNull TestObserver<T>
test()
Creates aTestObserver
and subscribes it to thisMaybe
.@NonNull TestObserver<T>
test(boolean dispose)
Creates aTestObserver
optionally in cancelled state, then subscribes it to thisMaybe
.@NonNull Maybe<Timed<T>>
timeInterval()
Measures the time (in milliseconds) between the subscription and success item emission of the currentMaybe
and signals it as a tuple (Timed
) success value.@NonNull Maybe<Timed<T>>
timeInterval(@NonNull Scheduler scheduler)
Measures the time (in milliseconds) between the subscription and success item emission of the currentMaybe
and signals it as a tuple (Timed
) success value.@NonNull Maybe<Timed<T>>
timeInterval(@NonNull java.util.concurrent.TimeUnit unit)
Measures the time between the subscription and success item emission of the currentMaybe
and signals it as a tuple (Timed
) success value.@NonNull Maybe<Timed<T>>
timeInterval(@NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
Measures the time between the subscription and success item emission of the currentMaybe
and signals it as a tuple (Timed
) success value.@NonNull Maybe<T>
timeout(long timeout, @NonNull java.util.concurrent.TimeUnit unit)
Returns aMaybe
that mirrors the currentMaybe
but applies a timeout policy for each emitted item.@NonNull Maybe<T>
timeout(long timeout, @NonNull java.util.concurrent.TimeUnit unit, @NonNull MaybeSource<? extends @NonNull T> fallback)
Returns aMaybe
that mirrors the currentMaybe
but applies a timeout policy for each emitted item.@NonNull Maybe<T>
timeout(long timeout, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
Returns aMaybe
that mirrors the currentMaybe
but applies a timeout policy for each emitted item, where this policy is governed on a specifiedScheduler
.@NonNull Maybe<T>
timeout(long timeout, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler, @NonNull MaybeSource<? extends @NonNull T> fallback)
Returns aMaybe
that mirrors the currentMaybe
but applies a timeout policy for each emitted item using a specifiedScheduler
.<@NonNull U>
@NonNull Maybe<T>timeout(@NonNull MaybeSource<@NonNull U> timeoutIndicator)
If the currentMaybe
didn't signal an event before thetimeoutIndicator
MaybeSource
signals, aTimeoutException
is signaled instead.<@NonNull U>
@NonNull Maybe<T>timeout(@NonNull MaybeSource<@NonNull U> timeoutIndicator, @NonNull MaybeSource<? extends @NonNull T> fallback)
If the currentMaybe
didn't signal an event before thetimeoutIndicator
MaybeSource
signals, the currentMaybe
is disposed and thefallback
MaybeSource
subscribed to as a continuation.<@NonNull U>
@NonNull Maybe<T>timeout(@NonNull org.reactivestreams.Publisher<@NonNull U> timeoutIndicator)
If the currentMaybe
source didn't signal an event before thetimeoutIndicator
Publisher
signals, aTimeoutException
is signaled instead.<@NonNull U>
@NonNull Maybe<T>timeout(@NonNull org.reactivestreams.Publisher<@NonNull U> timeoutIndicator, @NonNull MaybeSource<? extends @NonNull T> fallback)
If the currentMaybe
didn't signal an event before thetimeoutIndicator
Publisher
signals, the currentMaybe
is disposed and thefallback
MaybeSource
subscribed to as a continuation.static @NonNull Maybe<java.lang.Long>
timer(long delay, @NonNull java.util.concurrent.TimeUnit unit)
Returns aMaybe
that emits0L
after a specified delay.static @NonNull Maybe<java.lang.Long>
timer(long delay, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
@NonNull Maybe<Timed<T>>
timestamp()
@NonNull Maybe<Timed<T>>
timestamp(@NonNull Scheduler scheduler)
@NonNull Maybe<Timed<T>>
timestamp(@NonNull java.util.concurrent.TimeUnit unit)
@NonNull Maybe<Timed<T>>
timestamp(@NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
<R> R
to(@NonNull MaybeConverter<@NonNull T,? extends R> converter)
Calls the specified converter function during assembly time and returns its resulting value.@NonNull java.util.concurrent.CompletionStage<T>
toCompletionStage()
Signals the upstream success item (or aNoSuchElementException
if the upstream is empty) via aCompletionStage
.@NonNull java.util.concurrent.CompletionStage<T>
toCompletionStage(@NonNull T defaultItem)
Signals the upstream success item (or the default item if the upstream is empty) via aCompletionStage
.@NonNull Flowable<T>
toFlowable()
Converts thisMaybe
into a backpressure-awareFlowable
instance composing cancellation through.@NonNull java.util.concurrent.Future<T>
toFuture()
Returns aFuture
representing the single value emitted by the currentMaybe
ornull
if the currentMaybe
is empty.@NonNull Observable<T>
toObservable()
Converts thisMaybe
into anObservable
instance composing disposal through.@NonNull Single<T>
toSingle()
Converts thisMaybe
into aSingle
instance composing disposal through and turning an emptyMaybe
into a signal ofNoSuchElementException
.static <@NonNull T>
@NonNull Maybe<T>unsafeCreate(@NonNull MaybeSource<@NonNull T> onSubscribe)
Advanced use only: creates aMaybe
instance without any safeguards by using a callback that is called with aMaybeObserver
.@NonNull Maybe<T>
unsubscribeOn(@NonNull Scheduler scheduler)
Returns aMaybe
which makes sure when aMaybeObserver
disposes theDisposable
, that call is propagated up on the specifiedScheduler
.static <@NonNull T,@NonNull D>
@NonNull Maybe<T>using(@NonNull Supplier<? extends @NonNull D> resourceSupplier, @NonNull Function<? super @NonNull D,? extends MaybeSource<? extends @NonNull T>> sourceSupplier, @NonNull Consumer<? super @NonNull D> resourceCleanup)
Constructs aMaybe
that creates a dependent resource object which is disposed of when the generatedMaybeSource
terminates or the downstream calls dispose().static <@NonNull T,@NonNull D>
@NonNull Maybe<T>using(@NonNull Supplier<? extends @NonNull D> resourceSupplier, @NonNull Function<? super @NonNull D,? extends MaybeSource<? extends @NonNull T>> sourceSupplier, @NonNull Consumer<? super @NonNull D> resourceCleanup, boolean eager)
Constructs aMaybe
that creates a dependent resource object which is disposed first ({code eager == true}) when the generatedMaybeSource
terminates or the downstream disposes; or after ({code eager == false}).static <@NonNull T>
@NonNull Maybe<T>wrap(@NonNull MaybeSource<@NonNull T> source)
static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull T4,@NonNull T5,@NonNull T6,@NonNull T7,@NonNull T8,@NonNull T9,@NonNull R>
@NonNull Maybe<R>zip(@NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull MaybeSource<? extends @NonNull T4> source4, @NonNull MaybeSource<? extends @NonNull T5> source5, @NonNull MaybeSource<? extends @NonNull T6> source6, @NonNull MaybeSource<? extends @NonNull T7> source7, @NonNull MaybeSource<? extends @NonNull T8> source8, @NonNull MaybeSource<? extends @NonNull T9> source9, @NonNull Function9<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? super @NonNull T4,? super @NonNull T5,? super @NonNull T6,? super @NonNull T7,? super @NonNull T8,? super @NonNull T9,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of nine items emitted, in sequence, by nine otherMaybeSource
s.static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull T4,@NonNull T5,@NonNull T6,@NonNull T7,@NonNull T8,@NonNull R>
@NonNull Maybe<R>zip(@NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull MaybeSource<? extends @NonNull T4> source4, @NonNull MaybeSource<? extends @NonNull T5> source5, @NonNull MaybeSource<? extends @NonNull T6> source6, @NonNull MaybeSource<? extends @NonNull T7> source7, @NonNull MaybeSource<? extends @NonNull T8> source8, @NonNull Function8<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? super @NonNull T4,? super @NonNull T5,? super @NonNull T6,? super @NonNull T7,? super @NonNull T8,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of eight items emitted, in sequence, by eight otherMaybeSource
s.static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull T4,@NonNull T5,@NonNull T6,@NonNull T7,@NonNull R>
@NonNull Maybe<R>zip(@NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull MaybeSource<? extends @NonNull T4> source4, @NonNull MaybeSource<? extends @NonNull T5> source5, @NonNull MaybeSource<? extends @NonNull T6> source6, @NonNull MaybeSource<? extends @NonNull T7> source7, @NonNull Function7<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? super @NonNull T4,? super @NonNull T5,? super @NonNull T6,? super @NonNull T7,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of seven items emitted, in sequence, by seven otherMaybeSource
s.static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull T4,@NonNull T5,@NonNull T6,@NonNull R>
@NonNull Maybe<R>zip(@NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull MaybeSource<? extends @NonNull T4> source4, @NonNull MaybeSource<? extends @NonNull T5> source5, @NonNull MaybeSource<? extends @NonNull T6> source6, @NonNull Function6<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? super @NonNull T4,? super @NonNull T5,? super @NonNull T6,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of six items emitted, in sequence, by six otherMaybeSource
s.static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull T4,@NonNull T5,@NonNull R>
@NonNull Maybe<R>zip(@NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull MaybeSource<? extends @NonNull T4> source4, @NonNull MaybeSource<? extends @NonNull T5> source5, @NonNull Function5<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? super @NonNull T4,? super @NonNull T5,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of five items emitted, in sequence, by five otherMaybeSource
s.static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull T4,@NonNull R>
@NonNull Maybe<R>zip(@NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull MaybeSource<? extends @NonNull T4> source4, @NonNull Function4<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? super @NonNull T4,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of four items emitted, in sequence, by four otherMaybeSource
s.static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull R>
@NonNull Maybe<R>zip(@NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull Function3<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of three items emitted, in sequence, by three otherMaybeSource
s.static <@NonNull T1,@NonNull T2,@NonNull R>
@NonNull Maybe<R>zip(@NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull BiFunction<? super @NonNull T1,? super @NonNull T2,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of two items emitted, in sequence, by two otherMaybeSource
s.static <@NonNull T,@NonNull R>
@NonNull Maybe<R>zip(@NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources, @NonNull Function<? super java.lang.Object[],? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by anIterable
of otherMaybeSource
s.static <@NonNull T,@NonNull R>
@NonNull Maybe<R>zipArray(@NonNull Function<? super java.lang.Object[],? extends @NonNull R> zipper, @NonNull MaybeSource<? extends @NonNull T>... sources)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by an array of otherMaybeSource
s.<@NonNull U,@NonNull R>
@NonNull Maybe<R>zipWith(@NonNull MaybeSource<? extends @NonNull U> other, @NonNull BiFunction<? super @NonNull T,? super @NonNull U,? extends @NonNull R> zipper)
Waits until this and the otherMaybeSource
signal a success value then applies the givenBiFunction
to those values and emits theBiFunction
's resulting value to downstream.
-
-
-
Method Detail
-
amb
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> amb(@NonNull @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Runs multipleMaybeSource
s provided by anIterable
sequence and signals the events of the first one that signals (disposing the rest).- Scheduler:
amb
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- theIterable
sequence of sources. A subscription to each source will occur in the same order as in theIterable
.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
ambArray
@CheckReturnValue @SchedulerSupport("none") @NonNull @SafeVarargs public static <@NonNull T> @NonNull Maybe<T> ambArray(@NonNull @NonNull MaybeSource<? extends @NonNull T>... sources)
Runs multipleMaybeSource
s and signals the events of the first one that signals (disposing the rest).- Scheduler:
ambArray
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- the array of sources. A subscription to each source will occur in the same order as in the array.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concat
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenate the single values, in a non-overlapping fashion, of theMaybeSource
sources provided by anIterable
sequence as aFlowable
sequence.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
concat
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- theIterable
sequence ofMaybeSource
instances- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concat
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull MaybeSource<? extends @NonNull T> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T> source2)
Returns aFlowable
that emits the items emitted by twoMaybeSource
s, one after the other.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
concat
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common value type- Parameters:
source1
- aMaybeSource
to be concatenatedsource2
- aMaybeSource
to be concatenated- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsource1
orsource2
isnull
- See Also:
- ReactiveX operators documentation: Concat
-
concat
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull MaybeSource<? extends @NonNull T> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull @NonNull MaybeSource<? extends @NonNull T> source3)
Returns aFlowable
that emits the items emitted by threeMaybeSource
s, one after the other.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
concat
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common value type- Parameters:
source1
- aMaybeSource
to be concatenatedsource2
- aMaybeSource
to be concatenatedsource3
- aMaybeSource
to be concatenated- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
orsource3
isnull
- See Also:
- ReactiveX operators documentation: Concat
-
concat
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull MaybeSource<? extends @NonNull T> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull @NonNull MaybeSource<? extends @NonNull T> source3, @NonNull @NonNull MaybeSource<? extends @NonNull T> source4)
Returns aFlowable
that emits the items emitted by fourMaybeSource
s, one after the other.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
concat
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common value type- Parameters:
source1
- aMaybeSource
to be concatenatedsource2
- aMaybeSource
to be concatenatedsource3
- aMaybeSource
to be concatenatedsource4
- aMaybeSource
to be concatenated- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
orsource4
isnull
- See Also:
- ReactiveX operators documentation: Concat
-
concat
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenate the single values, in a non-overlapping fashion, of theMaybeSource
sources provided by aPublisher
sequence as aFlowable
sequence.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer and expects thePublisher
to honor backpressure as well. If the sourcesPublisher
violates this, aMissingBackpressureException
is signaled. - Scheduler:
concat
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- thePublisher
ofMaybeSource
instances- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concat
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources, int prefetch)
Concatenate the single values, in a non-overlapping fashion, of theMaybeSource
sources provided by aPublisher
sequence as aFlowable
sequence.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer and expects thePublisher
to honor backpressure as well. If the sourcesPublisher
violates this, aMissingBackpressureException
is signaled. - Scheduler:
concat
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- thePublisher
ofMaybeSource
instancesprefetch
- the number ofMaybeSource
s to prefetch from thePublisher
- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifprefetch
is non-positive
-
concatArray
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static <@NonNull T> @NonNull Flowable<T> concatArray(@NonNull @NonNull MaybeSource<? extends @NonNull T>... sources)
Concatenate the single values, in a non-overlapping fashion, of theMaybeSource
sources in the array as aFlowable
sequence.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
concatArray
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- the array ofMaybeSource
instances- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concatArrayDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @SafeVarargs @NonNull public static <@NonNull T> @NonNull Flowable<T> concatArrayDelayError(@NonNull @NonNull MaybeSource<? extends @NonNull T>... sources)
Concatenates a variable number ofMaybeSource
sources and delays errors from any of them till all terminate as aFlowable
sequence.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
concatArrayDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common base value type- Parameters:
sources
- the array of sources- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concatArrayEager
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull @SafeVarargs public static <@NonNull T> @NonNull Flowable<T> concatArrayEager(@NonNull @NonNull MaybeSource<? extends @NonNull T>... sources)
Concatenates a sequence ofMaybeSource
eagerly into aFlowable
sequence.Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source
MaybeSource
s. The operator buffers the value emitted by theseMaybeSource
s and then drains them in order, each one after the previous one completes.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
- This method does not operate by default on a particular
Scheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- a sequence ofMaybeSource
s that need to be eagerly concatenated- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concatArrayEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull @SafeVarargs public static <@NonNull T> @NonNull Flowable<T> concatArrayEagerDelayError(@NonNull @NonNull MaybeSource<? extends @NonNull T>... sources)
Concatenates a sequence ofMaybeSource
eagerly into aFlowable
sequence.Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source
MaybeSource
s. The operator buffers the value emitted by theseMaybeSource
s and then drains them in order, each one after the previous one completes.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
- This method does not operate by default on a particular
Scheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- a sequence ofMaybeSource
s that need to be eagerly concatenated- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
-
concatDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatDelayError(@NonNull @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenates theIterable
sequence ofMaybeSource
s into a single sequence by subscribing to eachMaybeSource
, one after the other, one at a time and delays any errors till the all innerMaybeSource
s terminate as aFlowable
sequence.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
concatDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element base type- Parameters:
sources
- theIterable
sequence ofMaybeSource
s- Returns:
- the new
Flowable
with the concatenating behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concatDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenates thePublisher
sequence ofMaybeSource
s into a single sequence by subscribing to each innerMaybeSource
, one after the other, one at a time and delays any errors till the all inner and the outerPublisher
terminate as aFlowable
sequence.- Backpressure:
concatDelayError
fully supports backpressure.- Scheduler:
concatDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element base type- Parameters:
sources
- thePublisher
sequence ofMaybeSource
s- Returns:
- the new
Flowable
with the concatenating behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concatDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources, int prefetch)
Concatenates thePublisher
sequence ofMaybeSource
s into a single sequence by subscribing to each innerMaybeSource
, one after the other, one at a time and delays any errors till the all inner and the outerPublisher
terminate as aFlowable
sequence.- Backpressure:
concatDelayError
fully supports backpressure.- Scheduler:
concatDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element base type- Parameters:
sources
- thePublisher
sequence ofMaybeSource
sprefetch
- The number of upstream items to prefetch so that fresh items are ready to be mapped when a previousMaybeSource
terminates. The operator replenishes after half of the prefetch amount has been consumed and turned intoMaybeSource
s.- Returns:
- the new
Flowable
with the concatenating behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifprefetch
is non-positive- Since:
- 3.0.0
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenates a sequence ofMaybeSource
s eagerly into aFlowable
sequence.Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source
MaybeSource
s. The operator buffers the values emitted by theseMaybeSource
s and then drains them in order, each one after the previous one completes.- Backpressure:
- Backpressure is honored towards the downstream.
- Scheduler:
- This method does not operate by default on a particular
Scheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- a sequence ofMaybeSource
that need to be eagerly concatenated- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates a sequence ofMaybeSource
s eagerly into aFlowable
sequence and runs a limited number of the inner sequences at once.Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source
MaybeSource
s. The operator buffers the values emitted by theseMaybeSource
s and then drains them in order, each one after the previous one completes.- Backpressure:
- Backpressure is honored towards the downstream.
- Scheduler:
- This method does not operate by default on a particular
Scheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- a sequence ofMaybeSource
that need to be eagerly concatenatedmaxConcurrency
- the maximum number of concurrently running innerMaybeSource
s;Integer.MAX_VALUE
is interpreted as all innerMaybeSource
s can be active at the same time- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifmaxConcurrency
is non-positive- Since:
- 3.0.0
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenates aPublisher
sequence ofMaybeSource
s eagerly into aFlowable
sequence.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source
MaybeSource
s as they are observed. The operator buffers the values emitted by theseMaybeSource
s and then drains them in order, each one after the previous one completes.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisher
is expected to support backpressure. Violating this assumption, the operator will signalMissingBackpressureException
. - Scheduler:
- This method does not operate by default on a particular
Scheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- a sequence ofMaybeSource
s that need to be eagerly concatenated- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates aPublisher
sequence ofMaybeSource
s eagerly into aFlowable
sequence, running at most the given number of innerMaybeSource
s at once.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source
MaybeSource
s as they are observed. The operator buffers the values emitted by theseMaybeSource
s and then drains them in order, each one after the previous one completes.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisher
is expected to support backpressure. Violating this assumption, the operator will signalMissingBackpressureException
. - Scheduler:
- This method does not operate by default on a particular
Scheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- a sequence ofMaybeSource
s that need to be eagerly concatenatedmaxConcurrency
- the maximum number of concurrently running innerMaybeSource
s;Integer.MAX_VALUE
is interpreted as all innerMaybeSource
s can be active at the same time- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifmaxConcurrency
is non-positive- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenates a sequence ofMaybeSource
s eagerly into aFlowable
sequence, delaying errors until all innerMaybeSource
s terminate.Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source
MaybeSource
s. The operator buffers the values emitted by theseMaybeSource
s and then drains them in order, each one after the previous one completes.- Backpressure:
- Backpressure is honored towards the downstream.
- Scheduler:
- This method does not operate by default on a particular
Scheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- a sequence ofMaybeSource
that need to be eagerly concatenated- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates a sequence ofMaybeSource
s eagerly into aFlowable
sequence, delaying errors until all innerMaybeSource
s terminate and runs a limited number of innerMaybeSource
s at once.Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source
MaybeSource
s. The operator buffers the values emitted by theseMaybeSource
s and then drains them in order, each one after the previous one completes.- Backpressure:
- Backpressure is honored towards the downstream.
- Scheduler:
- This method does not operate by default on a particular
Scheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- a sequence ofMaybeSource
that need to be eagerly concatenatedmaxConcurrency
- the maximum number of concurrently running innerMaybeSource
s;Integer.MAX_VALUE
is interpreted as all innerMaybeSource
s can be active at the same time- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifmaxConcurrency
is non-positive- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Concatenates aPublisher
sequence ofMaybeSource
s eagerly into aFlowable
sequence, delaying errors until all the inner and the outer sequence terminate.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source
MaybeSource
s as they are observed. The operator buffers the values emitted by theseMaybeSource
s and then drains them in order, each one after the previous one completes.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisher
is expected to support backpressure. Violating this assumption, the operator will signalMissingBackpressureException
. - Scheduler:
- This method does not operate by default on a particular
Scheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- a sequence ofMaybeSource
s that need to be eagerly concatenated- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates aPublisher
sequence ofMaybeSource
s eagerly into aFlowable
sequence, delaying errors until all the inner and the outer sequence terminate and runs a limited number of the innerMaybeSource
s at once.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source
MaybeSource
s as they are observed. The operator buffers the values emitted by theseMaybeSource
s and then drains them in order, each one after the previous one completes.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisher
is expected to support backpressure. Violating this assumption, the operator will signalMissingBackpressureException
. - Scheduler:
- This method does not operate by default on a particular
Scheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- a sequence ofMaybeSource
s that need to be eagerly concatenatedmaxConcurrency
- the maximum number of concurrently running innerMaybeSource
s;Integer.MAX_VALUE
is interpreted as all innerMaybeSource
s can be active at the same time- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifmaxConcurrency
is non-positive- Since:
- 3.0.0
-
create
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> create(@NonNull @NonNull MaybeOnSubscribe<@NonNull T> onSubscribe)
Provides an API (via a coldMaybe
) that bridges the reactive world with the callback-style world.Example:
Maybe.<Event>create(emitter -> { Callback listener = new Callback() { @Override public void onEvent(Event e) { if (e.isNothing()) { emitter.onComplete(); } else { emitter.onSuccess(e); } } @Override public void onFailure(Exception e) { emitter.onError(e); } }; AutoCloseable c = api.someMethod(listener); emitter.setCancellable(c::close); });
Whenever a
MaybeObserver
subscribes to the returnedMaybe
, the providedMaybeOnSubscribe
callback is invoked with a fresh instance of aMaybeEmitter
that will interact only with that specificMaybeObserver
. If thisMaybeObserver
disposes the flow (makingMaybeEmitter.isDisposed()
returntrue
), other observers subscribed to the same returnedMaybe
are not affected.- Scheduler:
create
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
onSubscribe
- the emitter that is called when aMaybeObserver
subscribes to the returnedMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifonSubscribe
isnull
- See Also:
MaybeOnSubscribe
,Cancellable
-
defer
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> defer(@NonNull @NonNull Supplier<? extends @NonNull MaybeSource<? extends @NonNull T>> supplier)
Calls aSupplier
for each individualMaybeObserver
to return the actualMaybeSource
source to be subscribed to.- Scheduler:
defer
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
supplier
- theSupplier
that is called for each individualMaybeObserver
and returns aMaybeSource
instance to subscribe to- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsupplier
isnull
-
empty
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Maybe<T> empty()
Returns a (singleton)Maybe
instance that callsonComplete
immediately.- Scheduler:
empty
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Returns:
- the shared
Maybe
instance
-
error
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> error(@NonNull @NonNull java.lang.Throwable throwable)
Returns aMaybe
that invokes a subscriber'sonError
method when the subscriber subscribes to it.- Scheduler:
error
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of the item (ostensibly) emitted by theMaybe
- Parameters:
throwable
- the particularThrowable
to pass toonError
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifthrowable
isnull
- See Also:
- ReactiveX operators documentation: Throw
-
error
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> error(@NonNull @NonNull Supplier<? extends @NonNull java.lang.Throwable> supplier)
Returns aMaybe
that invokes aMaybeObserver
'sonError
method when theMaybeObserver
subscribes to it.- Scheduler:
error
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of the items (ostensibly) emitted by theMaybe
- Parameters:
supplier
- aSupplier
factory to return aThrowable
for each individualMaybeObserver
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsupplier
isnull
- See Also:
- ReactiveX operators documentation: Throw
-
fromAction
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromAction(@NonNull @NonNull Action action)
Returns aMaybe
instance that runs the givenAction
for eachMaybeObserver
and emits either its exception or simply completes.- Scheduler:
fromAction
does not operate by default on a particularScheduler
.- Error handling:
- If the
Action
throws an exception, the respectiveThrowable
is delivered to the downstream viaMaybeObserver.onError(Throwable)
, except when the downstream has disposed the resultingMaybe
source. In this latter case, theThrowable
is delivered to the global error handler viaRxJavaPlugins.onError(Throwable)
as anUndeliverableException
.
- Type Parameters:
T
- the target type- Parameters:
action
- theAction
to run for eachMaybeObserver
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifaction
isnull
-
fromCompletable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromCompletable(@NonNull @NonNull CompletableSource completableSource)
Wraps aCompletableSource
into aMaybe
.- Scheduler:
fromCompletable
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the target type- Parameters:
completableSource
- theCompletableSource
to convert from- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifcompletableSource
isnull
-
fromSingle
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromSingle(@NonNull @NonNull SingleSource<@NonNull T> single)
Wraps aSingleSource
into aMaybe
.- Scheduler:
fromSingle
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the target type- Parameters:
single
- theSingleSource
to convert from- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsingle
isnull
-
fromCallable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <T> @NonNull Maybe<@NonNull T> fromCallable(@NonNull @NonNull java.util.concurrent.Callable<? extends @Nullable T> callable)
Returns aMaybe
that invokes the givenCallable
for each individualMaybeObserver
that subscribes and emits the resulting non-null
item viaonSuccess
while considering anull
result from theCallable
as indication for valueless completion viaonComplete
.This operator allows you to defer the execution of the given
Callable
until aMaybeObserver
subscribes to the returnedMaybe
. In other terms, this source operator evaluates the givenCallable
"lazily".Note that the
null
handling of this operator differs from the similar source operators in the otherbase reactive classes
. Those operators signal aNullPointerException
if the value returned by theirCallable
isnull
while thisfromCallable
considers it to indicate the returnedMaybe
is empty.- Scheduler:
fromCallable
does not operate by default on a particularScheduler
.- Error handling:
- Any non-fatal exception thrown by
Callable.call()
will be forwarded toonError
, except if theMaybeObserver
disposed the subscription in the meantime. In this latter case, the exception is forwarded to the global error handler viaRxJavaPlugins.onError(Throwable)
wrapped into aUndeliverableException
. Fatal exceptions are rethrown and usually will end up in the executing thread'sThread.UncaughtExceptionHandler.uncaughtException(Thread, Throwable)
handler.
- Type Parameters:
T
- the type of the item emitted by theMaybe
.- Parameters:
callable
- aCallable
instance whose execution should be deferred and performed for each individualMaybeObserver
that subscribes to the returnedMaybe
.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifcallable
isnull
- See Also:
defer(Supplier)
,fromSupplier(Supplier)
-
fromFuture
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromFuture(@NonNull @NonNull java.util.concurrent.Future<? extends @NonNull T> future)
Converts aFuture
into aMaybe
, treating anull
result as an indication of emptiness.The operator calls
Future.get()
, which is a blocking method, on the subscription thread. It is recommended applyingsubscribeOn(Scheduler)
to move this blocking wait to a background thread, and if theScheduler
supports it, interrupt the wait when the flow is disposed.Unlike 1.x, disposing the
Maybe
won't cancel the future. If necessary, one can use composition to achieve the cancellation effect:futureMaybe.doOnDispose(() -> future.cancel(true));
.- Scheduler:
fromFuture
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of object that theFuture
returns, and also the type of item to be emitted by the resultingMaybe
- Parameters:
future
- the sourceFuture
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- iffuture
isnull
- See Also:
- ReactiveX operators documentation: From,
fromCompletionStage(CompletionStage)
-
fromFuture
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromFuture(@NonNull @NonNull java.util.concurrent.Future<? extends @NonNull T> future, long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Converts aFuture
into aMaybe
, with a timeout on theFuture
.The operator calls
Future.get(long, TimeUnit)
, which is a blocking method, on the subscription thread. It is recommended applyingsubscribeOn(Scheduler)
to move this blocking wait to a background thread, and if theScheduler
supports it, interrupt the wait when the flow is disposed.Unlike 1.x, disposing the
Maybe
won't cancel the future. If necessary, one can use composition to achieve the cancellation effect:futureMaybe.doOnCancel(() -> future.cancel(true));
.- Scheduler:
fromFuture
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of object that theFuture
returns, and also the type of item to be emitted by the resultingMaybe
- Parameters:
future
- the sourceFuture
timeout
- the maximum time to wait before callingget
unit
- theTimeUnit
of thetimeout
argument- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- iffuture
orunit
isnull
- See Also:
- ReactiveX operators documentation: From,
fromCompletionStage(CompletionStage)
-
fromObservable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromObservable(@NonNull @NonNull ObservableSource<@NonNull T> source)
Wraps anObservableSource
into aMaybe
and emits the very first item or completes if the source is empty.- Scheduler:
fromObservable
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the target type- Parameters:
source
- theObservableSource
to convert from- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsource
isnull
- Since:
- 3.0.0
-
fromPublisher
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(UNBOUNDED_IN) public static <@NonNull T> @NonNull Maybe<T> fromPublisher(@NonNull @NonNull org.reactivestreams.Publisher<@NonNull T> source)
Wraps aPublisher
into aMaybe
and emits the very first item or completes if the source is empty.- Backpressure:
- The operator consumes the given
Publisher
in an unbounded manner (requestingLong.MAX_VALUE
) but cancels it after one item received. - Scheduler:
fromPublisher
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the target type- Parameters:
source
- thePublisher
to convert from- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsource
isnull
- Since:
- 3.0.0
-
fromRunnable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromRunnable(@NonNull @NonNull java.lang.Runnable run)
Returns aMaybe
instance that runs the givenRunnable
for eachMaybeObserver
and emits either its unchecked exception or simply completes.If the code to be wrapped needs to throw a checked or more broader
Throwable
exception, that exception has to be converted to an unchecked exception by the wrapped code itself. Alternatively, use thefromAction(Action)
method which allows the wrapped code to throw anyThrowable
exception and will signal it to observers as-is.- Scheduler:
fromRunnable
does not operate by default on a particularScheduler
.- Error handling:
- If the
Runnable
throws an exception, the respectiveThrowable
is delivered to the downstream viaMaybeObserver.onError(Throwable)
, except when the downstream has disposed thisMaybe
source. In this latter case, theThrowable
is delivered to the global error handler viaRxJavaPlugins.onError(Throwable)
as anUndeliverableException
.
- Type Parameters:
T
- the target type- Parameters:
run
- theRunnable
to run for eachMaybeObserver
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifrun
isnull
- See Also:
fromAction(Action)
-
fromSupplier
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <T> @NonNull Maybe<@NonNull T> fromSupplier(@NonNull @NonNull Supplier<? extends @Nullable T> supplier)
Returns aMaybe
that invokes the givenSupplier
for each individualMaybeObserver
that subscribes and emits the resulting non-null
item viaonSuccess
while considering anull
result from theSupplier
as indication for valueless completion viaonComplete
.This operator allows you to defer the execution of the given
Supplier
until aMaybeObserver
subscribes to the returnedMaybe
. In other terms, this source operator evaluates the givenSupplier
"lazily".Note that the
null
handling of this operator differs from the similar source operators in the otherbase reactive classes
. Those operators signal aNullPointerException
if the value returned by theirSupplier
isnull
while thisfromSupplier
considers it to indicate the returnedMaybe
is empty.- Scheduler:
fromSupplier
does not operate by default on a particularScheduler
.- Error handling:
- Any non-fatal exception thrown by
Supplier.get()
will be forwarded toonError
, except if theMaybeObserver
disposed the subscription in the meantime. In this latter case, the exception is forwarded to the global error handler viaRxJavaPlugins.onError(Throwable)
wrapped into aUndeliverableException
. Fatal exceptions are rethrown and usually will end up in the executing thread'sThread.UncaughtExceptionHandler.uncaughtException(Thread, Throwable)
handler.
- Type Parameters:
T
- the type of the item emitted by theMaybe
.- Parameters:
supplier
- aSupplier
instance whose execution should be deferred and performed for each individualMaybeObserver
that subscribes to the returnedMaybe
.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsupplier
isnull
- Since:
- 3.0.0
- See Also:
defer(Supplier)
,fromCallable(Callable)
-
just
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> just(@NonNull T item)
Returns aMaybe
that emits a specified item.To convert any object into a
Maybe
that emits that object, pass that object into thejust
method.- Scheduler:
just
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of that item- Parameters:
item
- the item to emit- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifitem
isnull
- See Also:
- ReactiveX operators documentation: Just
-
merge
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Merges anIterable
sequence ofMaybeSource
instances into a singleFlowable
sequence, running allMaybeSource
s at once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
MaybeSource
s signal aThrowable
viaonError
, the resultingFlowable
terminates with thatThrowable
and all other sourceMaybeSource
s are disposed. If more than oneMaybeSource
signals an error, the resultingFlowable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedFlowable
has been cancelled or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(Iterable)
to merge sources and terminate only when all sourceMaybeSource
s have completed or failed with an error.
- Type Parameters:
T
- the common and resulting value type- Parameters:
sources
- theIterable
sequence ofMaybeSource
sources- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- See Also:
mergeDelayError(Iterable)
-
merge
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Merges aPublisher
sequence ofMaybeSource
instances into a singleFlowable
sequence, running allMaybeSource
s at once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
MaybeSource
s signal aThrowable
viaonError
, the resultingFlowable
terminates with thatThrowable
and all other sourceMaybeSource
s are disposed. If more than oneMaybeSource
signals an error, the resultingFlowable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedFlowable
has been cancelled or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(Publisher)
to merge sources and terminate only when all sourceMaybeSource
s have completed or failed with an error.
- Type Parameters:
T
- the common and resulting value type- Parameters:
sources
- theFlowable
sequence ofMaybeSource
sources- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- See Also:
mergeDelayError(Publisher)
-
merge
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency)
Merges aPublisher
sequence ofMaybeSource
instances into a singleFlowable
sequence, running at most maxConcurrencyMaybeSource
s at once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
MaybeSource
s signal aThrowable
viaonError
, the resultingFlowable
terminates with thatThrowable
and all other sourceMaybeSource
s are disposed. If more than oneMaybeSource
signals an error, the resultingFlowable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedFlowable
has been cancelled or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(Publisher, int)
to merge sources and terminate only when all sourceMaybeSource
s have completed or failed with an error.
- Type Parameters:
T
- the common and resulting value type- Parameters:
sources
- theFlowable
sequence ofMaybeSource
sourcesmaxConcurrency
- the maximum number of concurrently runningMaybeSource
s- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifmaxConcurrency
is non-positive- See Also:
mergeDelayError(Publisher, int)
-
merge
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> merge(@NonNull @NonNull MaybeSource<? extends MaybeSource<? extends @NonNull T>> source)
Flattens aMaybeSource
that emits aMaybeSource
into a singleMaybeSource
that emits the item emitted by the nestedMaybeSource
, without any transformation.- Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- The resulting
Maybe
emits the outer source's or the innerMaybeSource
'sThrowable
as is. Unlike the othermerge()
operators, this operator won't and can't produce aCompositeException
because there is only one possibility for the outer or the innerMaybeSource
to emit anonError
signal. Therefore, there is no need for amergeDelayError(MaybeSource<MaybeSource<T>>)
operator.
- Type Parameters:
T
- the value type of the sources and the output- Parameters:
source
- aMaybeSource
that emits aMaybeSource
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsource
isnull
- See Also:
- ReactiveX operators documentation: Merge
-
merge
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull MaybeSource<? extends @NonNull T> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T> source2)
Flattens twoMaybeSource
s into a singleFlowable
, without any transformation.You can combine items emitted by multiple
MaybeSource
s so that they appear as a singleFlowable
, by using themerge
method.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
MaybeSource
s signal aThrowable
viaonError
, the resultingFlowable
terminates with thatThrowable
and all other sourceMaybeSource
s are disposed. If more than oneMaybeSource
signals an error, the resultingFlowable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedFlowable
has been cancelled or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(MaybeSource, MaybeSource)
to merge sources and terminate only when all sourceMaybeSource
s have completed or failed with an error.
- Type Parameters:
T
- the common value type- Parameters:
source1
- aMaybeSource
to be mergedsource2
- aMaybeSource
to be merged- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsource1
orsource2
isnull
- See Also:
- ReactiveX operators documentation: Merge,
mergeDelayError(MaybeSource, MaybeSource)
-
merge
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull MaybeSource<? extends @NonNull T> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull @NonNull MaybeSource<? extends @NonNull T> source3)
Flattens threeMaybeSource
s into a singleFlowable
, without any transformation.You can combine items emitted by multiple
MaybeSource
s so that they appear as a singleFlowable
, by using themerge
method.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
MaybeSource
s signal aThrowable
viaonError
, the resultingFlowable
terminates with thatThrowable
and all other sourceMaybeSource
s are disposed. If more than oneMaybeSource
signals an error, the resultingFlowable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedFlowable
has been cancelled or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(MaybeSource, MaybeSource, MaybeSource)
to merge sources and terminate only when all sourceMaybeSource
s have completed or failed with an error.
- Type Parameters:
T
- the common value type- Parameters:
source1
- aMaybeSource
to be mergedsource2
- aMaybeSource
to be mergedsource3
- aMaybeSource
to be merged- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
orsource3
isnull
- See Also:
- ReactiveX operators documentation: Merge,
mergeDelayError(MaybeSource, MaybeSource, MaybeSource)
-
merge
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull MaybeSource<? extends @NonNull T> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull @NonNull MaybeSource<? extends @NonNull T> source3, @NonNull @NonNull MaybeSource<? extends @NonNull T> source4)
Flattens fourMaybeSource
s into a singleFlowable
, without any transformation.You can combine items emitted by multiple
MaybeSource
s so that they appear as a singleFlowable
, by using themerge
method.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
MaybeSource
s signal aThrowable
viaonError
, the resultingFlowable
terminates with thatThrowable
and all other sourceMaybeSource
s are disposed. If more than oneMaybeSource
signals an error, the resultingFlowable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedFlowable
has been cancelled or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(MaybeSource, MaybeSource, MaybeSource, MaybeSource)
to merge sources and terminate only when all sourceMaybeSource
s have completed or failed with an error.
- Type Parameters:
T
- the common value type- Parameters:
source1
- aMaybeSource
to be mergedsource2
- aMaybeSource
to be mergedsource3
- aMaybeSource
to be mergedsource4
- aMaybeSource
to be merged- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
orsource4
isnull
- See Also:
- ReactiveX operators documentation: Merge,
mergeDelayError(MaybeSource, MaybeSource, MaybeSource, MaybeSource)
-
mergeArray
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static <@NonNull T> @NonNull Flowable<T> mergeArray(MaybeSource<? extends @NonNull T>... sources)
Merges an array ofMaybeSource
instances into a singleFlowable
sequence, running allMaybeSource
s at once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeArray
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
MaybeSource
s signal aThrowable
viaonError
, the resultingFlowable
terminates with thatThrowable
and all other sourceMaybeSource
s are disposed. If more than oneMaybeSource
signals an error, the resultingFlowable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedFlowable
has been cancelled or terminated with a (composite) error will be sent to the same global error handler. UsemergeArrayDelayError(MaybeSource...)
to merge sources and terminate only when all sourceMaybeSource
s have completed or failed with an error.
- Type Parameters:
T
- the common and resulting value type- Parameters:
sources
- the array sequence ofMaybeSource
sources- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- See Also:
mergeArrayDelayError(MaybeSource...)
-
mergeArrayDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @SafeVarargs @NonNull public static <@NonNull T> @NonNull Flowable<T> mergeArrayDelayError(@NonNull @NonNull MaybeSource<? extends @NonNull T>... sources)
Flattens an array ofMaybeSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceMaybeSource
s without being interrupted by an error notification from one of them.This behaves like
merge(Publisher)
except that if any of the mergedMaybeSource
s notify of an error viaonError
,mergeArrayDelayError
will refrain from propagating that error notification until all of the mergedMaybeSource
s have finished emitting items.Even if multiple merged
MaybeSource
s sendonError
notifications,mergeArrayDelayError
will only invoke theonError
method of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeArrayDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element base type- Parameters:
sources
- the array ofMaybeSource
s- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- See Also:
- ReactiveX operators documentation: Merge
-
mergeDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
Flattens anIterable
sequence ofMaybeSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceMaybeSource
s without being interrupted by an error notification from one of them.This behaves like
merge(Publisher)
except that if any of the mergedMaybeSource
s notify of an error viaonError
,mergeDelayError
will refrain from propagating that error notification until all of the mergedMaybeSource
s have finished emitting items.Even if multiple merged
MaybeSource
s sendonError
notifications,mergeDelayError
will only invoke theonError
method of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element base type- Parameters:
sources
- theIterable
ofMaybeSource
s- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- See Also:
- ReactiveX operators documentation: Merge
-
mergeDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Flattens aPublisher
that emitsMaybeSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSource
s without being interrupted by an error notification from one of them or even the mainPublisher
.This behaves like
merge(Publisher)
except that if any of the mergedMaybeSource
s notify of an error viaonError
,mergeDelayError
will refrain from propagating that error notification until all of the mergedMaybeSource
s and the mainPublisher
have finished emitting items.Even if multiple merged
MaybeSource
s sendonError
notifications,mergeDelayError
will only invoke theonError
method of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream. The outer
Publisher
is consumed in unbounded mode (i.e., no backpressure is applied to it). - Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element base type- Parameters:
sources
- aPublisher
that emitsMaybeSource
s- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- See Also:
- ReactiveX operators documentation: Merge
-
mergeDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency)
Flattens aPublisher
that emitsMaybeSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSource
s without being interrupted by an error notification from one of them or even the mainPublisher
as well as limiting the total number of activeMaybeSource
s.This behaves like
merge(Publisher, int)
except that if any of the mergedMaybeSource
s notify of an error viaonError
,mergeDelayError
will refrain from propagating that error notification until all of the mergedMaybeSource
s and the mainPublisher
have finished emitting items.Even if multiple merged
MaybeSource
s sendonError
notifications,mergeDelayError
will only invoke theonError
method of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream. The outer
Publisher
is consumed in unbounded mode (i.e., no backpressure is applied to it). - Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
History: 2.1.9 - experimental
- Type Parameters:
T
- the common element base type- Parameters:
sources
- aPublisher
that emitsMaybeSource
smaxConcurrency
- the maximum number of active innerMaybeSource
s to be merged at a time- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifmaxConcurrency
is non-positive- Since:
- 2.2
- See Also:
- ReactiveX operators documentation: Merge
-
mergeDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull MaybeSource<? extends @NonNull T> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T> source2)
Flattens twoMaybeSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceMaybeSource
s without being interrupted by an error notification from one of them.This behaves like
merge(MaybeSource, MaybeSource)
except that if any of the mergedMaybeSource
s notify of an error viaonError
,mergeDelayError
will refrain from propagating that error notification until all of the mergedMaybeSource
s have finished emitting items.Even if both merged
MaybeSource
s sendonError
notifications,mergeDelayError
will only invoke theonError
method of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element base type- Parameters:
source1
- aMaybeSource
to be mergedsource2
- aMaybeSource
to be merged- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsource1
orsource2
isnull
- See Also:
- ReactiveX operators documentation: Merge
-
mergeDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull MaybeSource<? extends @NonNull T> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull @NonNull MaybeSource<? extends @NonNull T> source3)
Flattens threeMaybeSource
into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSource
s without being interrupted by an error notification from one of them.This behaves like
merge(MaybeSource, MaybeSource, MaybeSource)
except that if any of the mergedMaybeSource
s notify of an error viaonError
,mergeDelayError
will refrain from propagating that error notification until all of the mergedMaybeSource
s have finished emitting items.Even if multiple merged
MaybeSource
s sendonError
notifications,mergeDelayError
will only invoke theonError
method of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element base type- Parameters:
source1
- aMaybeSource
to be mergedsource2
- aMaybeSource
to be mergedsource3
- aMaybeSource
to be merged- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
orsource3
isnull
- See Also:
- ReactiveX operators documentation: Merge
-
mergeDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull MaybeSource<? extends @NonNull T> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull @NonNull MaybeSource<? extends @NonNull T> source3, @NonNull @NonNull MaybeSource<? extends @NonNull T> source4)
Flattens fourMaybeSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSource
s without being interrupted by an error notification from one of them.This behaves like
merge(MaybeSource, MaybeSource, MaybeSource, MaybeSource)
except that if any of the mergedMaybeSource
s notify of an error viaonError
,mergeDelayError
will refrain from propagating that error notification until all of the mergedMaybeSource
s have finished emitting items.Even if multiple merged
MaybeSource
s sendonError
notifications,mergeDelayError
will only invoke theonError
method of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element base type- Parameters:
source1
- aMaybeSource
to be mergedsource2
- aMaybeSource
to be mergedsource3
- aMaybeSource
to be mergedsource4
- aMaybeSource
to be merged- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
orsource4
isnull
- See Also:
- ReactiveX operators documentation: Merge
-
never
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Maybe<T> never()
Returns aMaybe
that never sends any items or notifications to aMaybeObserver
.This
Maybe
is useful primarily for testing purposes.- Scheduler:
never
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of items (not) emitted by theMaybe
- Returns:
- the shared
Maybe
instance - See Also:
- ReactiveX operators documentation: Never
-
sequenceEqual
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<java.lang.Boolean> sequenceEqual(@NonNull @NonNull MaybeSource<? extends @NonNull T> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T> source2)
Returns aSingle
that emits aBoolean
value that indicates whether twoMaybeSource
sequences are the same by comparing the items emitted by eachMaybeSource
pairwise.- Scheduler:
sequenceEqual
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of items emitted by eachMaybeSource
- Parameters:
source1
- the firstMaybeSource
to comparesource2
- the secondMaybeSource
to compare- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifsource1
orsource2
isnull
- See Also:
- ReactiveX operators documentation: SequenceEqual
-
sequenceEqual
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<java.lang.Boolean> sequenceEqual(@NonNull @NonNull MaybeSource<? extends @NonNull T> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull @NonNull BiPredicate<? super @NonNull T,? super @NonNull T> isEqual)
Returns aSingle
that emits aBoolean
value that indicates whether twoMaybeSource
s are the same by comparing the items emitted by eachMaybeSource
pairwise based on the results of a specified equality function.- Scheduler:
sequenceEqual
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of items emitted by eachMaybeSource
- Parameters:
source1
- the firstMaybeSource
to comparesource2
- the secondMaybeSource
to compareisEqual
- a function used to compare items emitted by eachMaybeSource
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
orisEqual
isnull
- See Also:
- ReactiveX operators documentation: SequenceEqual
-
switchOnNext
@BackpressureSupport(UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> switchOnNext(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Switches betweenMaybeSource
s emitted by the sourcePublisher
whenever a newMaybeSource
is emitted, disposing the previously runningMaybeSource
, exposing the success items as aFlowable
sequence.- Backpressure:
- The
sources
Publisher
is consumed in an unbounded manner (requestingLong.MAX_VALUE
). The returnedFlowable
respects the backpressure from the downstream. - Scheduler:
switchOnNext
does not operate by default on a particularScheduler
.- Error handling:
- The returned sequence fails with the first error signaled by the
sources
Publisher
or the currently runningMaybeSource
, disposing the rest. Late errors are forwarded to the global error handler viaRxJavaPlugins.onError(Throwable)
.
- Type Parameters:
T
- the element type of theMaybeSource
s- Parameters:
sources
- thePublisher
sequence of innerMaybeSource
s to switch between- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
- See Also:
switchOnNextDelayError(Publisher)
, ReactiveX operators documentation: Switch
-
switchOnNextDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> switchOnNextDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
Switches betweenMaybeSource
s emitted by the sourcePublisher
whenever a newMaybeSource
is emitted, disposing the previously runningMaybeSource
, exposing the success items as aFlowable
sequence and delaying all errors from all of them until all terminate.- Backpressure:
- The
sources
Publisher
is consumed in an unbounded manner (requestingLong.MAX_VALUE
). The returnedFlowable
respects the backpressure from the downstream. - Scheduler:
switchOnNextDelayError
does not operate by default on a particularScheduler
.- Error handling:
- The returned
Flowable
collects all errors emitted by either thesources
Publisher
or any innerMaybeSource
and emits them as aCompositeException
when all sources terminate. If only one source ever failed, its error is emitted as-is at the end.
- Type Parameters:
T
- the element type of theMaybeSource
s- Parameters:
sources
- thePublisher
sequence of innerMaybeSource
s to switch between- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
- See Also:
switchOnNext(Publisher)
, ReactiveX operators documentation: Switch
-
timer
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public static @NonNull Maybe<java.lang.Long> timer(long delay, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Returns aMaybe
that emits0L
after a specified delay.- Scheduler:
timer
operates by default on thecomputation
Scheduler
.
- Parameters:
delay
- the initial delay before emitting a single0L
unit
- time units to use fordelay
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- See Also:
- ReactiveX operators documentation: Timer
-
timer
@CheckReturnValue @NonNull @SchedulerSupport("custom") public static @NonNull Maybe<java.lang.Long> timer(long delay, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Returns aMaybe
that emits0L
after a specified delay on a specifiedScheduler
.- Scheduler:
- You specify which
Scheduler
this operator will use.
- Parameters:
delay
- the initial delay before emitting a single 0Lunit
- time units to use fordelay
scheduler
- theScheduler
to use for scheduling the item- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
- See Also:
- ReactiveX operators documentation: Timer
-
unsafeCreate
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> unsafeCreate(@NonNull @NonNull MaybeSource<@NonNull T> onSubscribe)
Advanced use only: creates aMaybe
instance without any safeguards by using a callback that is called with aMaybeObserver
.- Scheduler:
unsafeCreate
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
onSubscribe
- the function that is called with the subscribingMaybeObserver
- Returns:
- the new
Maybe
instance - Throws:
java.lang.IllegalArgumentException
- ifonSubscribe
is aMaybe
java.lang.NullPointerException
- ifonSubscribe
isnull
-
using
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T,@NonNull D> @NonNull Maybe<T> using(@NonNull @NonNull Supplier<? extends @NonNull D> resourceSupplier, @NonNull @NonNull Function<? super @NonNull D,? extends MaybeSource<? extends @NonNull T>> sourceSupplier, @NonNull @NonNull Consumer<? super @NonNull D> resourceCleanup)
Constructs aMaybe
that creates a dependent resource object which is disposed of when the generatedMaybeSource
terminates or the downstream calls dispose().- Scheduler:
using
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the element type of the generatedMaybeSource
D
- the type of the resource associated with the output sequence- Parameters:
resourceSupplier
- the factory function to create a resource object that depends on theMaybe
sourceSupplier
- the factory function to create aMaybeSource
resourceCleanup
- the function that will dispose of the resource- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifresourceSupplier
,sourceSupplier
orresourceCleanup
isnull
- See Also:
- ReactiveX operators documentation: Using
-
using
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T,@NonNull D> @NonNull Maybe<T> using(@NonNull @NonNull Supplier<? extends @NonNull D> resourceSupplier, @NonNull @NonNull Function<? super @NonNull D,? extends MaybeSource<? extends @NonNull T>> sourceSupplier, @NonNull @NonNull Consumer<? super @NonNull D> resourceCleanup, boolean eager)
Constructs aMaybe
that creates a dependent resource object which is disposed first ({code eager == true}) when the generatedMaybeSource
terminates or the downstream disposes; or after ({code eager == false}).Eager disposal is particularly appropriate for a synchronous
Maybe
that reuses resources.disposeAction
will only be called once per subscription.- Scheduler:
using
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the element type of the generatedMaybeSource
D
- the type of the resource associated with the output sequence- Parameters:
resourceSupplier
- the factory function to create a resource object that depends on theMaybe
sourceSupplier
- the factory function to create aMaybeSource
resourceCleanup
- the function that will dispose of the resourceeager
- Iftrue
then resource disposal will happen either on adispose()
call before the upstream is disposed or just before the emission of a terminal event (onSuccess
,onComplete
oronError
). Iffalse
the resource disposal will happen either on adispose()
call after the upstream is disposed or just after the emission of a terminal event (onSuccess
,onComplete
oronError
).- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifresourceSupplier
,sourceSupplier
orresourceCleanup
isnull
- See Also:
- ReactiveX operators documentation: Using
-
wrap
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> wrap(@NonNull @NonNull MaybeSource<@NonNull T> source)
Wraps aMaybeSource
instance into a newMaybe
instance if not already aMaybe
instance.- Scheduler:
wrap
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
source
- the source to wrap- Returns:
- the new wrapped or cast
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsource
isnull
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T,@NonNull R> @NonNull Maybe<R> zip(@NonNull @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources, @NonNull @NonNull Function<? super java.lang.Object[],? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by anIterable
of otherMaybeSource
s.Note on method signature: since Java doesn't allow creating a generic array with
new T[]
, the implementation of this operator has to create anObject[]
instead. Unfortunately, aFunction<Integer[], R>
passed to the method would trigger aClassCastException
.This operator terminates eagerly if any of the source
MaybeSource
s signal anonError
oronComplete
. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zip
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common value typeR
- the zipped result type- Parameters:
sources
- anIterable
of sourceMaybeSource
szipper
- a function that, when applied to an item emitted by each of the sourceMaybeSource
s, results in an item that will be emitted by the resultingMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifzipper
orsources
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1,@NonNull T2,@NonNull R> @NonNull Maybe<R> zip(@NonNull @NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull @NonNull BiFunction<? super @NonNull T1,? super @NonNull T2,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of two items emitted, in sequence, by two otherMaybeSource
s.This operator terminates eagerly if any of the source
MaybeSource
s signal anonError
oronComplete
. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zip
does not operate by default on a particularScheduler
.
- Type Parameters:
T1
- the value type of the first sourceT2
- the value type of the second sourceR
- the zipped result type- Parameters:
source1
- the first sourceMaybeSource
source2
- a second sourceMaybeSource
zipper
- a function that, when applied to an item emitted by each of the sourceMaybeSource
s, results in an item that will be emitted by the resultingMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull R> @NonNull Maybe<R> zip(@NonNull @NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull @NonNull Function3<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of three items emitted, in sequence, by three otherMaybeSource
s.This operator terminates eagerly if any of the source
MaybeSource
s signal anonError
oronComplete
. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zip
does not operate by default on a particularScheduler
.
- Type Parameters:
T1
- the value type of the first sourceT2
- the value type of the second sourceT3
- the value type of the third sourceR
- the zipped result type- Parameters:
source1
- the first sourceMaybeSource
source2
- a second sourceMaybeSource
source3
- a third sourceMaybeSource
zipper
- a function that, when applied to an item emitted by each of the sourceMaybeSource
s, results in an item that will be emitted by the resultingMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull T4,@NonNull R> @NonNull Maybe<R> zip(@NonNull @NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull @NonNull MaybeSource<? extends @NonNull T4> source4, @NonNull @NonNull Function4<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? super @NonNull T4,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of four items emitted, in sequence, by four otherMaybeSource
s.This operator terminates eagerly if any of the source
MaybeSource
s signal anonError
oronComplete
. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zip
does not operate by default on a particularScheduler
.
- Type Parameters:
T1
- the value type of the first sourceT2
- the value type of the second sourceT3
- the value type of the third sourceT4
- the value type of the fourth sourceR
- the zipped result type- Parameters:
source1
- the first sourceMaybeSource
source2
- a second sourceMaybeSource
source3
- a third sourceMaybeSource
source4
- a fourth sourceMaybeSource
zipper
- a function that, when applied to an item emitted by each of the sourceMaybeSource
s, results in an item that will be emitted by the resultingMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
,source4
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull T4,@NonNull T5,@NonNull R> @NonNull Maybe<R> zip(@NonNull @NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull @NonNull MaybeSource<? extends @NonNull T4> source4, @NonNull @NonNull MaybeSource<? extends @NonNull T5> source5, @NonNull @NonNull Function5<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? super @NonNull T4,? super @NonNull T5,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of five items emitted, in sequence, by five otherMaybeSource
s.This operator terminates eagerly if any of the source
MaybeSource
s signal anonError
oronComplete
. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zip
does not operate by default on a particularScheduler
.
- Type Parameters:
T1
- the value type of the first sourceT2
- the value type of the second sourceT3
- the value type of the third sourceT4
- the value type of the fourth sourceT5
- the value type of the fifth sourceR
- the zipped result type- Parameters:
source1
- the first sourceMaybeSource
source2
- a second sourceMaybeSource
source3
- a third sourceMaybeSource
source4
- a fourth sourceMaybeSource
source5
- a fifth sourceMaybeSource
zipper
- a function that, when applied to an item emitted by each of the sourceMaybeSource
s, results in an item that will be emitted by the resultingMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
,source4
,source5
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull T4,@NonNull T5,@NonNull T6,@NonNull R> @NonNull Maybe<R> zip(@NonNull @NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull @NonNull MaybeSource<? extends @NonNull T4> source4, @NonNull @NonNull MaybeSource<? extends @NonNull T5> source5, @NonNull @NonNull MaybeSource<? extends @NonNull T6> source6, @NonNull @NonNull Function6<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? super @NonNull T4,? super @NonNull T5,? super @NonNull T6,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of six items emitted, in sequence, by six otherMaybeSource
s.This operator terminates eagerly if any of the source
MaybeSource
s signal anonError
oronComplete
. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zip
does not operate by default on a particularScheduler
.
- Type Parameters:
T1
- the value type of the first sourceT2
- the value type of the second sourceT3
- the value type of the third sourceT4
- the value type of the fourth sourceT5
- the value type of the fifth sourceT6
- the value type of the sixth sourceR
- the zipped result type- Parameters:
source1
- the first sourceMaybeSource
source2
- a second sourceMaybeSource
source3
- a third sourceMaybeSource
source4
- a fourth sourceMaybeSource
source5
- a fifth sourceMaybeSource
source6
- a sixth sourceMaybeSource
zipper
- a function that, when applied to an item emitted by each of the sourceMaybeSource
s, results in an item that will be emitted by the resultingMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
,source4
,source5
,source6
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull T4,@NonNull T5,@NonNull T6,@NonNull T7,@NonNull R> @NonNull Maybe<R> zip(@NonNull @NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull @NonNull MaybeSource<? extends @NonNull T4> source4, @NonNull @NonNull MaybeSource<? extends @NonNull T5> source5, @NonNull @NonNull MaybeSource<? extends @NonNull T6> source6, @NonNull @NonNull MaybeSource<? extends @NonNull T7> source7, @NonNull @NonNull Function7<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? super @NonNull T4,? super @NonNull T5,? super @NonNull T6,? super @NonNull T7,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of seven items emitted, in sequence, by seven otherMaybeSource
s.This operator terminates eagerly if any of the source
MaybeSource
s signal anonError
oronComplete
. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zip
does not operate by default on a particularScheduler
.
- Type Parameters:
T1
- the value type of the first sourceT2
- the value type of the second sourceT3
- the value type of the third sourceT4
- the value type of the fourth sourceT5
- the value type of the fifth sourceT6
- the value type of the sixth sourceT7
- the value type of the seventh sourceR
- the zipped result type- Parameters:
source1
- the first sourceMaybeSource
source2
- a second sourceMaybeSource
source3
- a third sourceMaybeSource
source4
- a fourth sourceMaybeSource
source5
- a fifth sourceMaybeSource
source6
- a sixth sourceMaybeSource
source7
- a seventh sourceMaybeSource
zipper
- a function that, when applied to an item emitted by each of the sourceMaybeSource
s, results in an item that will be emitted by the resultingMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
,source4
,source5
,source6
,source7
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull T4,@NonNull T5,@NonNull T6,@NonNull T7,@NonNull T8,@NonNull R> @NonNull Maybe<R> zip(@NonNull @NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull @NonNull MaybeSource<? extends @NonNull T4> source4, @NonNull @NonNull MaybeSource<? extends @NonNull T5> source5, @NonNull @NonNull MaybeSource<? extends @NonNull T6> source6, @NonNull @NonNull MaybeSource<? extends @NonNull T7> source7, @NonNull @NonNull MaybeSource<? extends @NonNull T8> source8, @NonNull @NonNull Function8<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? super @NonNull T4,? super @NonNull T5,? super @NonNull T6,? super @NonNull T7,? super @NonNull T8,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of eight items emitted, in sequence, by eight otherMaybeSource
s.This operator terminates eagerly if any of the source
MaybeSource
s signal anonError
oronComplete
. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zip
does not operate by default on a particularScheduler
.
- Type Parameters:
T1
- the value type of the first sourceT2
- the value type of the second sourceT3
- the value type of the third sourceT4
- the value type of the fourth sourceT5
- the value type of the fifth sourceT6
- the value type of the sixth sourceT7
- the value type of the seventh sourceT8
- the value type of the eighth sourceR
- the zipped result type- Parameters:
source1
- the first sourceMaybeSource
source2
- a second sourceMaybeSource
source3
- a third sourceMaybeSource
source4
- a fourth sourceMaybeSource
source5
- a fifth sourceMaybeSource
source6
- a sixth sourceMaybeSource
source7
- a seventh sourceMaybeSource
source8
- an eighth sourceMaybeSource
zipper
- a function that, when applied to an item emitted by each of the sourceMaybeSource
s, results in an item that will be emitted by the resultingMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
,source4
,source5
,source6
,source7
,source8
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull T4,@NonNull T5,@NonNull T6,@NonNull T7,@NonNull T8,@NonNull T9,@NonNull R> @NonNull Maybe<R> zip(@NonNull @NonNull MaybeSource<? extends @NonNull T1> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T2> source2, @NonNull @NonNull MaybeSource<? extends @NonNull T3> source3, @NonNull @NonNull MaybeSource<? extends @NonNull T4> source4, @NonNull @NonNull MaybeSource<? extends @NonNull T5> source5, @NonNull @NonNull MaybeSource<? extends @NonNull T6> source6, @NonNull @NonNull MaybeSource<? extends @NonNull T7> source7, @NonNull @NonNull MaybeSource<? extends @NonNull T8> source8, @NonNull @NonNull MaybeSource<? extends @NonNull T9> source9, @NonNull @NonNull Function9<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? super @NonNull T4,? super @NonNull T5,? super @NonNull T6,? super @NonNull T7,? super @NonNull T8,? super @NonNull T9,? extends @NonNull R> zipper)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of nine items emitted, in sequence, by nine otherMaybeSource
s.This operator terminates eagerly if any of the source
MaybeSource
s signal anonError
oronComplete
. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zip
does not operate by default on a particularScheduler
.
- Type Parameters:
T1
- the value type of the first sourceT2
- the value type of the second sourceT3
- the value type of the third sourceT4
- the value type of the fourth sourceT5
- the value type of the fifth sourceT6
- the value type of the sixth sourceT7
- the value type of the seventh sourceT8
- the value type of the eighth sourceT9
- the value type of the ninth sourceR
- the zipped result type- Parameters:
source1
- the first sourceMaybeSource
source2
- a second sourceMaybeSource
source3
- a third sourceMaybeSource
source4
- a fourth sourceMaybeSource
source5
- a fifth sourceMaybeSource
source6
- a sixth sourceMaybeSource
source7
- a seventh sourceMaybeSource
source8
- an eighth sourceMaybeSource
source9
- a ninth sourceMaybeSource
zipper
- a function that, when applied to an item emitted by each of the sourceMaybeSource
s, results in an item that will be emitted by the resultingMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
,source4
,source5
,source6
,source7
,source8
,source9
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
zipArray
@CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static <@NonNull T,@NonNull R> @NonNull Maybe<R> zipArray(@NonNull @NonNull Function<? super java.lang.Object[],? extends @NonNull R> zipper, @NonNull @NonNull MaybeSource<? extends @NonNull T>... sources)
Returns aMaybe
that emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by an array of otherMaybeSource
s.Note on method signature: since Java doesn't allow creating a generic array with
new T[]
, the implementation of this operator has to create anObject[]
instead. Unfortunately, aFunction<Integer[], R>
passed to the method would trigger aClassCastException
.This operator terminates eagerly if any of the source
MaybeSource
s signal anonError
oronComplete
. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zipArray
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element typeR
- the result type- Parameters:
sources
- an array of sourceMaybeSource
szipper
- a function that, when applied to an item emitted by each of the sourceMaybeSource
s, results in an item that will be emitted by the resultingMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsources
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
ambWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> ambWith(@NonNull @NonNull MaybeSource<? extends @NonNull T> other)
Mirrors theMaybeSource
(current or provided) that first signals an event.- Scheduler:
ambWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- aMaybeSource
competing to react first. A subscription to this provided source will occur after subscribing to the current source.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- See Also:
- ReactiveX operators documentation: Amb
-
blockingGet
@CheckReturnValue @SchedulerSupport("none") @Nullable public final T blockingGet()
Waits in a blocking fashion until the currentMaybe
signals a success value (which is returned),null
if completed or an exception (which is propagated).- Scheduler:
blockingGet
does not operate by default on a particularScheduler
.- Error handling:
- If the source signals an error, the operator wraps a checked
Exception
intoRuntimeException
and throws that. Otherwise,RuntimeException
s andError
s are rethrown as they are.
- Returns:
- the success value
-
blockingGet
@CheckReturnValue @SchedulerSupport("none") @NonNull public final T blockingGet(@NonNull @NonNull T defaultValue)
Waits in a blocking fashion until the currentMaybe
signals a success value (which is returned), defaultValue if completed or an exception (which is propagated).- Scheduler:
blockingGet
does not operate by default on a particularScheduler
.- Error handling:
- If the source signals an error, the operator wraps a checked
Exception
intoRuntimeException
and throws that. Otherwise,RuntimeException
s andError
s are rethrown as they are.
- Parameters:
defaultValue
- the default item to return if thisMaybe
is empty- Returns:
- the success value
- Throws:
java.lang.NullPointerException
- ifdefaultValue
isnull
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe()
Subscribes to the currentMaybe
and blocks the current thread until it terminates.- Scheduler:
blockingSubscribe
does not operate by default on a particularScheduler
.- Error handling:
- If the current
Maybe
signals an error, theThrowable
is routed to the global error handler viaRxJavaPlugins.onError(Throwable)
. If the current thread is interrupted, anInterruptedException
is routed to the same global error handler.
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess)
Subscribes to the currentMaybe
and calls givenonSuccess
callback on the current thread when it completes normally.- Scheduler:
blockingSubscribe
does not operate by default on a particularScheduler
.- Error handling:
- If either the current
Maybe
signals an error oronSuccess
throws, the respectiveThrowable
is routed to the global error handler viaRxJavaPlugins.onError(Throwable)
. If the current thread is interrupted, anInterruptedException
is routed to the same global error handler.
- Parameters:
onSuccess
- theConsumer
to call if the currentMaybe
succeeds- Throws:
java.lang.NullPointerException
- ifonSuccess
isnull
- Since:
- 3.0.0
- See Also:
blockingSubscribe(Consumer, Consumer)
,blockingSubscribe(Consumer, Consumer, Action)
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super java.lang.Throwable> onError)
Subscribes to the currentMaybe
and calls the appropriate callback on the current thread when it terminates.- Scheduler:
blockingSubscribe
does not operate by default on a particularScheduler
.- Error handling:
- If either
onSuccess
oronError
throw, theThrowable
is routed to the global error handler viaRxJavaPlugins.onError(Throwable)
. If the current thread is interrupted, theonError
consumer is called with anInterruptedException
.
- Parameters:
onSuccess
- theConsumer
to call if the currentMaybe
succeedsonError
- theConsumer
to call if the currentMaybe
signals an error- Throws:
java.lang.NullPointerException
- ifonSuccess
oronError
isnull
- Since:
- 3.0.0
- See Also:
blockingSubscribe(Consumer, Consumer, Action)
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super java.lang.Throwable> onError, @NonNull @NonNull Action onComplete)
Subscribes to the currentMaybe
and calls the appropriate callback on the current thread when it terminates.- Scheduler:
blockingSubscribe
does not operate by default on a particularScheduler
.- Error handling:
- If either
onSuccess
,onError
oronComplete
throw, theThrowable
is routed to the global error handler viaRxJavaPlugins.onError(Throwable)
. If the current thread is interrupted, theonError
consumer is called with anInterruptedException
.
- Parameters:
onSuccess
- theConsumer
to call if the currentMaybe
succeedsonError
- theConsumer
to call if the currentMaybe
signals an erroronComplete
- theAction
to call if the currentMaybe
completes without a value- Throws:
java.lang.NullPointerException
- ifonSuccess
,onError
oronComplete
isnull
- Since:
- 3.0.0
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull MaybeObserver<? super @NonNull T> observer)
Subscribes to the currentMaybe
and calls the appropriateMaybeObserver
method on the current thread.- Scheduler:
blockingSubscribe
does not operate by default on a particularScheduler
.- Error handling:
- An
onError
signal is delivered to theMaybeObserver.onError(Throwable)
method. If any of theMaybeObserver
's methods throw, theRuntimeException
is propagated to the caller of this method. If the current thread is interrupted, anInterruptedException
is delivered toobserver.onError
.
- Parameters:
observer
- theMaybeObserver
to call methods on the current thread- Throws:
java.lang.NullPointerException
- ifobserver
isnull
- Since:
- 3.0.0
-
cache
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> cache()
Returns aMaybe
that subscribes to thisMaybe
lazily, caches its event and replays it, to all the downstream subscribers.The operator subscribes only when the first downstream subscriber subscribes and maintains a single subscription towards this
Maybe
.Note: You sacrifice the ability to dispose the origin when you use the
cache
.- Scheduler:
cache
does not operate by default on a particularScheduler
.
- Returns:
- the new
Maybe
instance - See Also:
- ReactiveX operators documentation: Replay
-
cast
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<U> cast(@NonNull @NonNull java.lang.Class<? extends @NonNull U> clazz)
Casts the success value of the currentMaybe
into the target type or signals aClassCastException
if not compatible.- Scheduler:
cast
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the target type- Parameters:
clazz
- the type token to use for casting the success result from the currentMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifclazz
isnull
-
compose
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Maybe<R> compose(@NonNull @NonNull MaybeTransformer<? super @NonNull T,? extends @NonNull R> transformer)
Transform aMaybe
by applying a particularMaybeTransformer
function to it.This method operates on the
Maybe
itself whereaslift(io.reactivex.rxjava3.core.MaybeOperator<? extends R, ? super T>)
operates on theMaybe
'sMaybeObserver
s.If the operator you are creating is designed to act on the individual item emitted by a
Maybe
, uselift(io.reactivex.rxjava3.core.MaybeOperator<? extends R, ? super T>)
. If your operator is designed to transform the currentMaybe
as a whole (for instance, by applying a particular set of existing RxJava operators to it) usecompose
.- Scheduler:
compose
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the value type of theMaybe
returned by the transformer function- Parameters:
transformer
- the transformer function, notnull
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- iftransformer
isnull
- See Also:
- RxJava wiki: Implementing Your Own Operators
-
concatMap
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Maybe<R> concatMap(@NonNull @NonNull Function<? super @NonNull T,? extends MaybeSource<? extends @NonNull R>> mapper)
Returns aMaybe
that is based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aMaybeSource
.Note that flatMap and concatMap for
Maybe
is the same operation.- Scheduler:
concatMap
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the result value type- Parameters:
mapper
- a function that, when applied to the item emitted by the currentMaybe
, returns aMaybeSource
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: FlatMap
-
concatMapCompletable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable concatMapCompletable(@NonNull @NonNull Function<? super @NonNull T,? extends CompletableSource> mapper)
Returns aCompletable
that completes based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aCompletable
.This operator is an alias for
flatMapCompletable(Function)
.- Scheduler:
concatMapCompletable
does not operate by default on a particularScheduler
.
- Parameters:
mapper
- a function that, when applied to the item emitted by the currentMaybe
, returns aCompletable
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: FlatMap
-
concatMapSingle
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Maybe<R> concatMapSingle(@NonNull @NonNull Function<? super @NonNull T,? extends SingleSource<? extends @NonNull R>> mapper)
Returns aMaybe
based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aSingle
. When thisMaybe
just completes the resultingMaybe
completes as well.This operator is an alias for
flatMapSingle(Function)
.- Scheduler:
concatMapSingle
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the result value type- Parameters:
mapper
- a function that, when applied to the item emitted by the currentMaybe
, returns aSingle
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: FlatMap
-
concatWith
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Flowable<T> concatWith(@NonNull @NonNull MaybeSource<? extends @NonNull T> other)
Returns aFlowable
that emits the items emitted from the currentMaybe
, then theother
MaybeSource
, one after the other, without interleaving them.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
concatWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- aMaybeSource
to be concatenated after the current- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- See Also:
- ReactiveX operators documentation: Concat
-
contains
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<java.lang.Boolean> contains(@NonNull @NonNull java.lang.Object item)
Returns aSingle
that emits aBoolean
that indicates whether the currentMaybe
emitted a specified item.- Scheduler:
contains
does not operate by default on a particularScheduler
.
- Parameters:
item
- the item to search for in the emissions from the currentMaybe
, notnull
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifitem
isnull
- See Also:
- ReactiveX operators documentation: Contains
-
count
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<java.lang.Long> count()
Returns aSingle
that counts the total number of items emitted (0 or 1) by the currentMaybe
and emits this count as a 64-bitLong
.- Scheduler:
count
does not operate by default on a particularScheduler
.
- Returns:
- the new
Single
instance - See Also:
- ReactiveX operators documentation: Count
-
defaultIfEmpty
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> defaultIfEmpty(@NonNull @NonNull T defaultItem)
Returns aSingle
that emits the item emitted by the currentMaybe
or a specified default item if the currentMaybe
is empty.- Scheduler:
defaultIfEmpty
does not operate by default on a particularScheduler
.
- Parameters:
defaultItem
- the item to emit if the currentMaybe
emits no items- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifdefaultItem
isnull
- See Also:
- ReactiveX operators documentation: DefaultIfEmpty
-
dematerialize
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Maybe<R> dematerialize(@NonNull @NonNull Function<? super @NonNull T,@NonNull Notification<@NonNull R>> selector)
Maps theNotification
success value of the currentMaybe
back into normalonSuccess
,onError
oronComplete
signals.The intended use of the
selector
function is to perform a type-safe identity mapping (see example) on a source that is already of typeNotification<T>
. The Java language doesn't allow limiting instance methods to a certain generic argument shape, therefore, a function is used to ensure the conversion remains type safe.Regular
onError
oronComplete
signals from the currentMaybe
are passed along to the downstream.- Scheduler:
dematerialize
does not operate by default on a particularScheduler
.
Example:
Maybe.just(Notification.createOnNext(1)) .dematerialize(notification -> notification) .test() .assertResult(1);
- Type Parameters:
R
- the result type- Parameters:
selector
- the function called with the success item and should return aNotification
instance.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifselector
isnull
- Since:
- 3.0.0
- See Also:
materialize()
-
delay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Maybe<T> delay(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Returns aMaybe
that signals the events emitted by the currentMaybe
shifted forward in time by a specified delay. An error signal will not be delayed.- Scheduler:
- This version of
delay
operates by default on thecomputation
Scheduler
.
- Parameters:
time
- the delay to shift the source byunit
- theTimeUnit
in whichtime
is defined- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- See Also:
- ReactiveX operators documentation: Delay,
delay(long, TimeUnit, Scheduler, boolean)
-
delay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Maybe<T> delay(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit, boolean delayError)
Returns aMaybe
that signals the events emitted by the currentMaybe
shifted forward in time by a specified delay.- Scheduler:
- This version of
delay
operates by default on thecomputation
Scheduler
.
- Parameters:
time
- the delay to shift the source byunit
- theTimeUnit
in whichtime
is defineddelayError
- iftrue
, both success and error signals are delayed. iffalse
, only success signals are delayed.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: Delay,
delay(long, TimeUnit, Scheduler, boolean)
-
delay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Maybe<T> delay(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Returns aMaybe
that signals the events emitted by the currentMaybe
shifted forward in time by a specified delay. An error signal will not be delayed.- Scheduler:
- you specify the
Scheduler
where the non-blocking wait and emission happens
- Parameters:
time
- the delay to shift the source byunit
- theTimeUnit
in whichtime
is definedscheduler
- theScheduler
to use for delaying- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
- See Also:
- ReactiveX operators documentation: Delay,
delay(long, TimeUnit, Scheduler, boolean)
-
delay
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<T> delay(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean delayError)
Returns aMaybe
that signals the events emitted by the currentMaybe
shifted forward in time by a specified delay running on the specifiedScheduler
.- Scheduler:
- you specify which
Scheduler
this operator will use.
- Parameters:
time
- the delay to shift the source byunit
- theTimeUnit
in whichtime
is definedscheduler
- theScheduler
to use for delayingdelayError
- iftrue
, both success and error signals are delayed. iffalse
, only success signals are delayed.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: Delay
-
delay
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(UNBOUNDED_IN) public final <@NonNull U> @NonNull Maybe<T> delay(@NonNull @NonNull org.reactivestreams.Publisher<@NonNull U> delayIndicator)
Delays the emission of thisMaybe
until the givenPublisher
signals an item or completes.- Backpressure:
- The
delayIndicator
is consumed in an unbounded manner but is cancelled after the first item it produces. - Scheduler:
- This version of
delay
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the subscription delay value type (ignored)- Parameters:
delayIndicator
- thePublisher
that gets subscribed to when thisMaybe
signals an event and that signal is emitted when thePublisher
signals an item or completes- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifdelayIndicator
isnull
- See Also:
- ReactiveX operators documentation: Delay
-
delaySubscription
@BackpressureSupport(UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<T> delaySubscription(@NonNull @NonNull org.reactivestreams.Publisher<@NonNull U> subscriptionIndicator)
Returns aMaybe
that delays the subscription to thisMaybe
until the otherPublisher
emits an element or completes normally.- Backpressure:
- The
Publisher
source is consumed in an unbounded fashion (without applying backpressure). - Scheduler:
- This method does not operate by default on a particular
Scheduler
.
- Type Parameters:
U
- the value type of the otherPublisher
, irrelevant- Parameters:
subscriptionIndicator
- the otherPublisher
that should trigger the subscription to thisPublisher
.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifsubscriptionIndicator
isnull
-
delaySubscription
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Maybe<T> delaySubscription(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Returns aMaybe
that delays the subscription to the currentMaybe
by a given amount of time.- Scheduler:
- This version of
delaySubscription
operates by default on thecomputation
Scheduler
.
- Parameters:
time
- the time to delay the subscriptionunit
- the time unit ofdelay
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- See Also:
- ReactiveX operators documentation: Delay,
delaySubscription(long, TimeUnit, Scheduler)
-
delaySubscription
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Maybe<T> delaySubscription(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Returns aMaybe
that delays the subscription to the currentMaybe
by a given amount of time, both waiting and subscribing on a givenScheduler
.- Scheduler:
- You specify which
Scheduler
this operator will use.
- Parameters:
time
- the time to delay the subscriptionunit
- the time unit ofdelay
scheduler
- theScheduler
on which the waiting and subscription will happen- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
- See Also:
- ReactiveX operators documentation: Delay
-
doAfterSuccess
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doAfterSuccess(@NonNull @NonNull Consumer<? super @NonNull T> onAfterSuccess)
Calls the specifiedConsumer
with the success item after this item has been emitted to the downstream.Note that the
onAfterSuccess
action is shared between subscriptions and as such should be thread-safe.- Scheduler:
doAfterSuccess
does not operate by default on a particularScheduler
.
History: 2.0.1 - experimental
- Parameters:
onAfterSuccess
- theConsumer
that will be called after emitting an item from upstream to the downstream- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifonAfterSuccess
isnull
- Since:
- 2.1
-
doAfterTerminate
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doAfterTerminate(@NonNull @NonNull Action onAfterTerminate)
Registers anAction
to be called when thisMaybe
invokes eitheronSuccess
,onComplete
oronError
.- Scheduler:
doAfterTerminate
does not operate by default on a particularScheduler
.
- Parameters:
onAfterTerminate
- anAction
to be invoked when the currentMaybe
finishes- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifonAfterTerminate
isnull
- See Also:
- ReactiveX operators documentation: Do
-
doFinally
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doFinally(@NonNull @NonNull Action onFinally)
Calls the specified action after thisMaybe
signalsonSuccess
,onError
oronComplete
or gets disposed by the downstream.In case of a race between a terminal event and a dispose call, the provided
onFinally
action is executed once per subscription.Note that the
onFinally
action is shared between subscriptions and as such should be thread-safe.- Scheduler:
doFinally
does not operate by default on a particularScheduler
.
History: 2.0.1 - experimental
- Parameters:
onFinally
- the action called when thisMaybe
terminates or gets disposed- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifonFinally
isnull
- Since:
- 2.1
-
doOnDispose
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doOnDispose(@NonNull @NonNull Action onDispose)
Calls the sharedAction
if aMaybeObserver
subscribed to the currentMaybe
disposes the commonDisposable
it received viaonSubscribe
.- Scheduler:
doOnDispose
does not operate by default on a particularScheduler
.
- Parameters:
onDispose
- the action called when the subscription is disposed- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifonDispose
isnull
-
doOnComplete
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doOnComplete(@NonNull @NonNull Action onComplete)
Invokes anAction
just before the currentMaybe
callsonComplete
.- Scheduler:
doOnComplete
does not operate by default on a particularScheduler
.
- Parameters:
onComplete
- the action to invoke when the currentMaybe
callsonComplete
- Returns:
- the new
Maybe
with the side-effecting behavior applied - Throws:
java.lang.NullPointerException
- ifonComplete
isnull
- See Also:
- ReactiveX operators documentation: Do
-
doOnError
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doOnError(@NonNull @NonNull Consumer<? super java.lang.Throwable> onError)
Calls the sharedConsumer
with the error sent viaonError
for eachMaybeObserver
that subscribes to the currentMaybe
.- Scheduler:
doOnError
does not operate by default on a particularScheduler
.
- Parameters:
onError
- the consumer called with the success value ofonError
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifonError
isnull
-
doOnEvent
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> doOnEvent(@NonNull @NonNull BiConsumer<? super @NonNull T,? super java.lang.Throwable> onEvent)
Calls the givenonEvent
callback with the (success value,null
) for anonSuccess
, (null
, throwable) for anonError
or (null
,null
) for anonComplete
signal from thisMaybe
before delivering said signal to the downstream.The exceptions thrown from the callback will override the event so the downstream receives the error instead of the original signal.
- Scheduler:
doOnEvent
does not operate by default on a particularScheduler
.
- Parameters:
onEvent
- the callback to call with the success value or the exception, whichever is notnull
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifonEvent
isnull
-
doOnLifecycle
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> doOnLifecycle(@NonNull @NonNull Consumer<? super Disposable> onSubscribe, @NonNull @NonNull Action onDispose)
Calls the appropriateonXXX
method (shared between allMaybeObserver
s) for the lifecycle events of the sequence (subscription, disposal).- Scheduler:
doOnLifecycle
does not operate by default on a particularScheduler
.
- Parameters:
onSubscribe
- aConsumer
called with theDisposable
sent viaMaybeObserver.onSubscribe(Disposable)
onDispose
- called when the downstream disposes theDisposable
viadispose()
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifonSubscribe
oronDispose
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: Do
-
doOnSubscribe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doOnSubscribe(@NonNull @NonNull Consumer<? super Disposable> onSubscribe)
Calls the sharedConsumer
with theDisposable
sent through theonSubscribe
for eachMaybeObserver
that subscribes to the currentMaybe
.- Scheduler:
doOnSubscribe
does not operate by default on a particularScheduler
.
- Parameters:
onSubscribe
- theConsumer
called with theDisposable
sent viaonSubscribe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifonSubscribe
isnull
-
doOnTerminate
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doOnTerminate(@NonNull @NonNull Action onTerminate)
Returns aMaybe
instance that calls the given onTerminate callback just before thisMaybe
completes normally or with an exception.This differs from
doAfterTerminate
in that this happens before theonComplete
oronError
notification.- Scheduler:
doOnTerminate
does not operate by default on a particularScheduler
.
History: 2.2.7 - experimental
- Parameters:
onTerminate
- the action to invoke when the consumer callsonComplete
oronError
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifonTerminate
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: Do,
doOnTerminate(Action)
-
doOnSuccess
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doOnSuccess(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess)
Calls the sharedConsumer
with the success value sent viaonSuccess
for eachMaybeObserver
that subscribes to the currentMaybe
.- Scheduler:
doOnSuccess
does not operate by default on a particularScheduler
.
- Parameters:
onSuccess
- theConsumer
called with the success value of the upstream- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifonSuccess
isnull
-
filter
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> filter(@NonNull @NonNull Predicate<? super @NonNull T> predicate)
Filters the success item of theMaybe
via a predicate function and emitting it if the predicate returnstrue
, completing otherwise.- Scheduler:
filter
does not operate by default on a particularScheduler
.
- Parameters:
predicate
- a function that evaluates the item emitted by the currentMaybe
, returningtrue
if it passes the filter- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifpredicate
isnull
- See Also:
- ReactiveX operators documentation: Filter
-
flatMap
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Maybe<R> flatMap(@NonNull @NonNull Function<? super @NonNull T,? extends MaybeSource<? extends @NonNull R>> mapper)
Returns aMaybe
that is based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aMaybeSource
.- Scheduler:
flatMap
does not operate by default on a particularScheduler
.
Note that flatMap and concatMap for
Maybe
is the same operation.- Type Parameters:
R
- the result value type- Parameters:
mapper
- a function that, when applied to the item emitted by the currentMaybe
, returns aMaybeSource
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: FlatMap
-
flatMap
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Maybe<R> flatMap(@NonNull @NonNull Function<? super @NonNull T,? extends MaybeSource<? extends @NonNull R>> onSuccessMapper, @NonNull @NonNull Function<? super java.lang.Throwable,? extends MaybeSource<? extends @NonNull R>> onErrorMapper, @NonNull @NonNull Supplier<? extends MaybeSource<? extends @NonNull R>> onCompleteSupplier)
Maps theonSuccess
,onError
oronComplete
signals of the currentMaybe
into aMaybeSource
and emits thatMaybeSource
's signals.- Scheduler:
flatMap
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the result type- Parameters:
onSuccessMapper
- a function that returns aMaybeSource
to merge for theonSuccess
item emitted by thisMaybe
onErrorMapper
- a function that returns aMaybeSource
to merge for anonError
notification from thisMaybe
onCompleteSupplier
- a function that returns aMaybeSource
to merge for anonComplete
notification thisMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifonSuccessMapper
,onErrorMapper
oronCompleteSupplier
isnull
- See Also:
- ReactiveX operators documentation: FlatMap
-
flatMap
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U,@NonNull R> @NonNull Maybe<R> flatMap(@NonNull @NonNull Function<? super @NonNull T,? extends MaybeSource<? extends @NonNull U>> mapper, @NonNull @NonNull BiFunction<? super @NonNull T,? super @NonNull U,? extends @NonNull R> combiner)
Returns aMaybe
that emits the results of a specified function to the pair of values emitted by the currentMaybe
and a specified mappedMaybeSource
.- Scheduler:
flatMap
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the type of items emitted by theMaybeSource
returned by themapper
functionR
- the type of items emitted by the resultingMaybe
- Parameters:
mapper
- a function that returns aMaybeSource
for the item emitted by the currentMaybe
combiner
- a function that combines one item emitted by each of the source and collectionMaybeSource
and returns an item to be emitted by the resultingMaybeSource
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifmapper
orcombiner
isnull
- See Also:
- ReactiveX operators documentation: FlatMap
-
flattenAsFlowable
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Flowable<U> flattenAsFlowable(@NonNull @NonNull Function<? super @NonNull T,? extends java.lang.Iterable<? extends @NonNull U>> mapper)
Maps the success value of the currentMaybe
into anIterable
and emits its items as aFlowable
sequence.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
flattenAsFlowable
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the type of item emitted by the innerIterable
- Parameters:
mapper
- a function that returns anIterable
sequence of values for when given an item emitted by the currentMaybe
- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: FlatMap,
flattenStreamAsFlowable(Function)
-
flattenAsObservable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Observable<U> flattenAsObservable(@NonNull @NonNull Function<? super @NonNull T,? extends java.lang.Iterable<? extends @NonNull U>> mapper)
Maps the success value of the currentMaybe
into anIterable
and emits its items as anObservable
sequence.- Scheduler:
flattenAsObservable
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the type of item emitted by the resultingIterable
- Parameters:
mapper
- a function that returns anIterable
sequence of values for when given an item emitted by the currentMaybe
- Returns:
- the new
Observable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: FlatMap
-
flatMapObservable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Observable<R> flatMapObservable(@NonNull @NonNull Function<? super @NonNull T,? extends ObservableSource<? extends @NonNull R>> mapper)
Returns anObservable
that is based on applying a specified function to the item emitted by the currentMaybe
, where that function returns anObservableSource
.- Scheduler:
flatMapObservable
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the result value type- Parameters:
mapper
- a function that, when applied to the item emitted by the currentMaybe
, returns anObservableSource
- Returns:
- the new
Observable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: FlatMap
-
flatMapPublisher
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Flowable<R> flatMapPublisher(@NonNull @NonNull Function<? super @NonNull T,? extends org.reactivestreams.Publisher<? extends @NonNull R>> mapper)
Returns aFlowable
that emits items based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aPublisher
.- Backpressure:
- The returned
Flowable
honors the downstream backpressure. - Scheduler:
flatMapPublisher
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the result value type- Parameters:
mapper
- a function that, when applied to the item emitted by the currentMaybe
, returns aFlowable
- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: FlatMap
-
flatMapSingle
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Maybe<R> flatMapSingle(@NonNull @NonNull Function<? super @NonNull T,? extends SingleSource<? extends @NonNull R>> mapper)
Returns aMaybe
based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aSingle
. When thisMaybe
just completes the resultingMaybe
completes as well.- Scheduler:
flatMapSingle
does not operate by default on a particularScheduler
.
History: 2.0.2 - experimental
- Type Parameters:
R
- the result value type- Parameters:
mapper
- a function that, when applied to the item emitted by the currentMaybe
, returns aSingle
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- Since:
- 2.1
- See Also:
- ReactiveX operators documentation: FlatMap
-
flatMapCompletable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable flatMapCompletable(@NonNull @NonNull Function<? super @NonNull T,? extends CompletableSource> mapper)
Returns aCompletable
that completes based on applying a specified function to the item emitted by the currentMaybe
, where that function returns aCompletable
.- Scheduler:
flatMapCompletable
does not operate by default on a particularScheduler
.
- Parameters:
mapper
- a function that, when applied to the item emitted by the currentMaybe
, returns aCompletable
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: FlatMap
-
hide
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> hide()
Hides the identity of thisMaybe
and itsDisposable
.Allows preventing certain identity-based optimizations (fusion).
- Scheduler:
hide
does not operate by default on a particularScheduler
.
- Returns:
- the new
Maybe
instance
-
ignoreElement
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable ignoreElement()
Returns aCompletable
that ignores the item emitted by the currentMaybe
and only callsonComplete
oronError
.- Scheduler:
ignoreElement
does not operate by default on a particularScheduler
.
- Returns:
- the new
Completable
instance - See Also:
- ReactiveX operators documentation: IgnoreElements
-
isEmpty
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<java.lang.Boolean> isEmpty()
Returns aSingle
that emitstrue
if the currentMaybe
is empty, otherwisefalse
.- Scheduler:
isEmpty
does not operate by default on a particularScheduler
.
- Returns:
- the new
Single
instance - See Also:
- ReactiveX operators documentation: Contains
-
lift
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Maybe<R> lift(@NonNull @NonNull MaybeOperator<? extends @NonNull R,? super @NonNull T> lift)
This method requires advanced knowledge about building operators, please consider other standard composition methods first; Returns aMaybe
which, when subscribed to, invokes theapply(MaybeObserver)
method of the providedMaybeOperator
for each individual downstreamMaybe
and allows the insertion of a custom operator by accessing the downstream'sMaybeObserver
during this subscription phase and providing a newMaybeObserver
, containing the custom operator's intended business logic, that will be used in the subscription process going further upstream.Generally, such a new
MaybeObserver
will wrap the downstream'sMaybeObserver
and forwards theonSuccess
,onError
andonComplete
events from the upstream directly or according to the emission pattern the custom operator's business logic requires. In addition, such operator can intercept the flow control calls ofdispose
andisDisposed
that would have traveled upstream and perform additional actions depending on the same business logic requirements.Example:
// Step 1: Create the consumer type that will be returned by the MaybeOperator.apply(): public final class CustomMaybeObserver<T> implements MaybeObserver<T>, Disposable { // The downstream's MaybeObserver that will receive the onXXX events final MaybeObserver<? super String> downstream; // The connection to the upstream source that will call this class' onXXX methods Disposable upstream; // The constructor takes the downstream subscriber and usually any other parameters public CustomMaybeObserver(MaybeObserver<? super String> downstream) { this.downstream = downstream; } // In the subscription phase, the upstream sends a Disposable to this class // and subsequently this class has to send a Disposable to the downstream. // Note that relaying the upstream's Disposable directly is not allowed in RxJava @Override public void onSubscribe(Disposable d) { if (upstream != null) { d.dispose(); } else { upstream = d; downstream.onSubscribe(this); } } // The upstream calls this with the next item and the implementation's // responsibility is to emit an item to the downstream based on the intended // business logic, or if it can't do so for the particular item, // request more from the upstream @Override public void onSuccess(T item) { String str = item.toString(); if (str.length() < 2) { downstream.onSuccess(str); } else { // Maybe is expected to produce one of the onXXX events only downstream.onComplete(); } } // Some operators may handle the upstream's error while others // could just forward it to the downstream. @Override public void onError(Throwable throwable) { downstream.onError(throwable); } // When the upstream completes, usually the downstream should complete as well. @Override public void onComplete() { downstream.onComplete(); } // Some operators may use their own resources which should be cleaned up if // the downstream disposes the flow before it completed. Operators without // resources can simply forward the dispose to the upstream. // In some cases, a disposed flag may be set by this method so that other parts // of this class may detect the dispose and stop sending events // to the downstream. @Override public void dispose() { upstream.dispose(); } // Some operators may simply forward the call to the upstream while others // can return the disposed flag set in dispose(). @Override public boolean isDisposed() { return upstream.isDisposed(); } } // Step 2: Create a class that implements the MaybeOperator interface and // returns the custom consumer type from above in its apply() method. // Such class may define additional parameters to be submitted to // the custom consumer type. final class CustomMaybeOperator<T> implements MaybeOperator<String> { @Override public MaybeObserver<? super String> apply(MaybeObserver<? super T> upstream) { return new CustomMaybeObserver<T>(upstream); } } // Step 3: Apply the custom operator via lift() in a flow by creating an instance of it // or reusing an existing one. Maybe.just(5) .lift(new CustomMaybeOperator<Integer>()) .test() .assertResult("5"); Maybe.just(15) .lift(new CustomMaybeOperator<Integer>()) .test() .assertResult();
Creating custom operators can be complicated and it is recommended one consults the RxJava wiki: Writing operators page about the tools, requirements, rules, considerations and pitfalls of implementing them.
Note that implementing custom operators via this
lift()
method adds slightly more overhead by requiring an additional allocation and indirection per assembled flows. Instead, extending the abstractMaybe
class and creating aMaybeTransformer
with it is recommended.Note also that it is not possible to stop the subscription phase in
lift()
as theapply()
method requires a non-null
MaybeObserver
instance to be returned, which is then unconditionally subscribed to the currentMaybe
. For example, if the operator decided there is no reason to subscribe to the upstream source because of some optimization possibility or a failure to prepare the operator, it still has to return aMaybeObserver
that should immediately dispose the upstream'sDisposable
in itsonSubscribe
method. Again, using aMaybeTransformer
and extending theMaybe
is a better option assubscribeActual(io.reactivex.rxjava3.core.MaybeObserver<? super T>)
can decide to not subscribe to its upstream after all.- Scheduler:
lift
does not operate by default on a particularScheduler
, however, theMaybeOperator
may use aScheduler
to support its own asynchronous behavior.
- Type Parameters:
R
- the output value type- Parameters:
lift
- theMaybeOperator
that receives the downstream'sMaybeObserver
and should return aMaybeObserver
with custom behavior to be used as the consumer for the currentMaybe
.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- iflift
isnull
- See Also:
- RxJava wiki: Writing operators,
compose(MaybeTransformer)
-
map
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Maybe<R> map(@NonNull @NonNull Function<? super @NonNull T,? extends @NonNull R> mapper)
Returns aMaybe
that applies a specified function to the item emitted by the currentMaybe
and emits the result of this function application.- Scheduler:
map
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the result value type- Parameters:
mapper
- a function to apply to the item emitted by theMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: Map
-
materialize
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<Notification<T>> materialize()
Maps the signal types of thisMaybe
into aNotification
of the same kind and emits it as aSingle
'sonSuccess
value to downstream.- Scheduler:
materialize
does not operate by default on a particularScheduler
.
History: 2.2.4 - experimental
- Returns:
- the new
Single
instance - Since:
- 3.0.0
- See Also:
Single.dematerialize(Function)
-
mergeWith
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Flowable<T> mergeWith(@NonNull @NonNull MaybeSource<? extends @NonNull T> other)
Flattens thisMaybe
and anotherMaybeSource
into a singleFlowable
, without any transformation.You can combine items emitted by multiple
Maybe
s so that they appear as a singleFlowable
, by using themergeWith
method.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- aMaybeSource
to be merged- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- See Also:
- ReactiveX operators documentation: Merge
-
observeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<T> observeOn(@NonNull @NonNull Scheduler scheduler)
Wraps aMaybe
to emit its item (or notify of its error) on a specifiedScheduler
, asynchronously.- Scheduler:
- you specify which
Scheduler
this operator will use.
- Parameters:
scheduler
- theScheduler
to notify subscribers on- Returns:
- the new
Maybe
instance that its subscribers are notified on the specifiedScheduler
- Throws:
java.lang.NullPointerException
- ifscheduler
isnull
- See Also:
- ReactiveX operators documentation: ObserveOn,
RxJava Threading Examples,
subscribeOn(io.reactivex.rxjava3.core.Scheduler)
-
ofType
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<U> ofType(@NonNull @NonNull java.lang.Class<@NonNull U> clazz)
Filters the items emitted by the currentMaybe
, only emitting its success value if that is an instance of the suppliedClass
.- Scheduler:
ofType
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the output type- Parameters:
clazz
- the class type to filter the items emitted by the currentMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifclazz
isnull
- See Also:
- ReactiveX operators documentation: Filter
-
to
@CheckReturnValue @SchedulerSupport("none") public final <R> R to(@NonNull @NonNull MaybeConverter<@NonNull T,? extends R> converter)
Calls the specified converter function during assembly time and returns its resulting value.This allows fluent conversion to any other type.
- Scheduler:
to
does not operate by default on a particularScheduler
.
History: 2.1.7 - experimental
- Type Parameters:
R
- the resulting object type- Parameters:
converter
- the function that receives the currentMaybe
instance and returns a value- Returns:
- the converted value
- Throws:
java.lang.NullPointerException
- ifconverter
isnull
- Since:
- 2.2
-
toFlowable
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> toFlowable()
Converts thisMaybe
into a backpressure-awareFlowable
instance composing cancellation through.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream. - Scheduler:
toFlowable
does not operate by default on a particularScheduler
.
- Returns:
- the new
Flowable
instance
-
toFuture
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull java.util.concurrent.Future<T> toFuture()
Returns aFuture
representing the single value emitted by the currentMaybe
ornull
if the currentMaybe
is empty.Cancelling the
Future
will cancel the subscription to the currentMaybe
.- Scheduler:
toFuture
does not operate by default on a particularScheduler
.
- Returns:
- the new
Future
instance - Since:
- 3.0.0
- See Also:
- ReactiveX documentation: To
-
toObservable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> toObservable()
Converts thisMaybe
into anObservable
instance composing disposal through.- Scheduler:
toObservable
does not operate by default on a particularScheduler
.
- Returns:
- the new
Observable
instance
-
toSingle
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> toSingle()
Converts thisMaybe
into aSingle
instance composing disposal through and turning an emptyMaybe
into a signal ofNoSuchElementException
.- Scheduler:
toSingle
does not operate by default on a particularScheduler
.
- Returns:
- the new
Single
instance - See Also:
defaultIfEmpty(Object)
-
onErrorComplete
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> onErrorComplete()
Returns aMaybe
instance that if thisMaybe
emits an error, it will emit anonComplete
and swallow the throwable.- Scheduler:
onErrorComplete
does not operate by default on a particularScheduler
.
- Returns:
- the new
Maybe
instance
-
onErrorComplete
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> onErrorComplete(@NonNull @NonNull Predicate<? super java.lang.Throwable> predicate)
Returns aMaybe
instance that if thisMaybe
emits an error and the predicate returnstrue
, it will emit anonComplete
and swallow the throwable.- Scheduler:
onErrorComplete
does not operate by default on a particularScheduler
.
- Parameters:
predicate
- the predicate to call when anThrowable
is emitted which should returntrue
if theThrowable
should be swallowed and replaced with anonComplete
.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifpredicate
isnull
-
onErrorResumeWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> onErrorResumeWith(@NonNull @NonNull MaybeSource<? extends @NonNull T> fallback)
Resumes the flow with the givenMaybeSource
when the currentMaybe
fails instead of signaling the error viaonError
.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorResumeWith
does not operate by default on a particularScheduler
.
- Parameters:
fallback
- the nextMaybeSource
that will take over if the currentMaybe
encounters an error- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- iffallback
isnull
- See Also:
- ReactiveX operators documentation: Catch
-
onErrorResumeNext
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> onErrorResumeNext(@NonNull @NonNull Function<? super java.lang.Throwable,? extends MaybeSource<? extends @NonNull T>> fallbackSupplier)
Resumes the flow with aMaybeSource
returned for the failureThrowable
of the currentMaybe
by a function instead of signaling the error viaonError
.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorResumeNext
does not operate by default on a particularScheduler
.
- Parameters:
fallbackSupplier
- a function that returns aMaybeSource
that will take over if the currentMaybe
encounters an error- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- iffallbackSupplier
isnull
- See Also:
- ReactiveX operators documentation: Catch
-
onErrorReturn
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> onErrorReturn(@NonNull @NonNull Function<? super java.lang.Throwable,? extends @NonNull T> itemSupplier)
Ends the flow with a success item returned by a function for theThrowable
error signaled by the currentMaybe
instead of signaling the error viaonError
.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorReturn
does not operate by default on a particularScheduler
.
- Parameters:
itemSupplier
- a function that returns a single value that will be emitted as success value the currentMaybe
signals anonError
event- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifitemSupplier
isnull
- See Also:
- ReactiveX operators documentation: Catch
-
onErrorReturnItem
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> onErrorReturnItem(@NonNull @NonNull T item)
Ends the flow with the given success item when the currentMaybe
fails instead of signaling the error viaonError
.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorReturnItem
does not operate by default on a particularScheduler
.
- Parameters:
item
- the value that is emitted asonSuccess
in case the currentMaybe
signals anonError
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifitem
isnull
- See Also:
- ReactiveX operators documentation: Catch
-
onTerminateDetach
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> onTerminateDetach()
Nulls out references to the upstream producer and downstreamMaybeObserver
if the sequence is terminated or downstream callsdispose()
.- Scheduler:
onTerminateDetach
does not operate by default on a particularScheduler
.
- Returns:
- the new
Maybe
instance the sequence is terminated or downstream callsdispose()
-
repeat
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeat()
Returns aFlowable
that repeats the sequence of items emitted by the currentMaybe
indefinitely.- Backpressure:
- The operator honors downstream backpressure.
- Scheduler:
repeat
does not operate by default on a particularScheduler
.
- Returns:
- the new
Flowable
instance - See Also:
- ReactiveX operators documentation: Repeat
-
repeat
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeat(long times)
Returns aFlowable
that repeats the sequence of items emitted by the currentMaybe
at mostcount
times.- Backpressure:
- This operator honors downstream backpressure.
- Scheduler:
repeat
does not operate by default on a particularScheduler
.
- Parameters:
times
- the number of times the currentMaybe
items are repeated, a count of 0 will yield an empty sequence- Returns:
- the new
Flowable
instance - Throws:
java.lang.IllegalArgumentException
- iftimes
is negative- See Also:
- ReactiveX operators documentation: Repeat
-
repeatUntil
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeatUntil(@NonNull @NonNull BooleanSupplier stop)
Returns aFlowable
that repeats the sequence of items emitted by the currentMaybe
until the provided stop function returnstrue
.- Backpressure:
- This operator honors downstream backpressure.
- Scheduler:
repeatUntil
does not operate by default on a particularScheduler
.
- Parameters:
stop
- a boolean supplier that is called when the currentFlowable
completes and unless it returnsfalse
, the currentFlowable
is resubscribed- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifstop
isnull
- See Also:
- ReactiveX operators documentation: Repeat
-
repeatWhen
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeatWhen(@NonNull @NonNull Function<? super Flowable<java.lang.Object>,? extends org.reactivestreams.Publisher<?>> handler)
Returns aFlowable
that emits the same values as the currentMaybe
with the exception of anonComplete
. AnonComplete
notification from the source will result in the emission of avoid
item to theFlowable
provided as an argument to thenotificationHandler
function. If thatPublisher
callsonComplete
oronError
thenrepeatWhen
will callonComplete
oronError
on the child observer. Otherwise, this operator will resubscribe to the currentMaybe
.- Backpressure:
- The operator honors downstream backpressure and expects the source
Publisher
to honor backpressure as well. If this expectation is violated, the operator may throw anIllegalStateException
. - Scheduler:
repeatWhen
does not operate by default on a particularScheduler
.
- Parameters:
handler
- receives aPublisher
of notifications with which a user can complete or error, aborting the repeat.- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifhandler
isnull
- See Also:
- ReactiveX operators documentation: Repeat
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> retry()
Returns aMaybe
that mirrors the currentMaybe
, resubscribing to it if it callsonError
(infinite retry count).If the current
Maybe
callsMaybeObserver.onError(java.lang.Throwable)
, this operator will resubscribe to the currentMaybe
rather than propagating theonError
call.- Scheduler:
retry
does not operate by default on a particularScheduler
.
- Returns:
- the new
Maybe
instance - See Also:
- ReactiveX operators documentation: Retry
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> retry(@NonNull @NonNull BiPredicate<? super java.lang.Integer,? super java.lang.Throwable> predicate)
Returns aMaybe
that mirrors the currentMaybe
, resubscribing to it if it callsonError
and the predicate returnstrue
for that specific exception and retry count.- Scheduler:
retry
does not operate by default on a particularScheduler
.
- Parameters:
predicate
- the predicate that determines if a resubscription may happen in case of a specific exception and retry count- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifpredicate
isnull
- See Also:
retry()
, ReactiveX operators documentation: Retry
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> retry(long times)
Returns aMaybe
that mirrors the currentMaybe
, resubscribing to it if it callsonError
up to a specified number of retries.If the current
Maybe
callsMaybeObserver.onError(java.lang.Throwable)
, this operator will resubscribe to the currentMaybe
for a maximum ofcount
resubscriptions rather than propagating theonError
call.- Scheduler:
retry
does not operate by default on a particularScheduler
.
- Parameters:
times
- the number of times to resubscribe if the currentMaybe
fails- Returns:
- the new
Maybe
instance - Throws:
java.lang.IllegalArgumentException
- iftimes
is negative- See Also:
- ReactiveX operators documentation: Retry
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> retry(long times, @NonNull @NonNull Predicate<? super java.lang.Throwable> predicate)
Retries at mosttimes
or until the predicate returnsfalse
, whichever happens first.- Scheduler:
retry
does not operate by default on a particularScheduler
.
- Parameters:
times
- the number of times to resubscribe if the currentMaybe
failspredicate
- the predicate called with the failureThrowable
and should returntrue
to trigger a retry.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifpredicate
isnull
java.lang.IllegalArgumentException
- iftimes
is negative
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> retry(@NonNull @NonNull Predicate<? super java.lang.Throwable> predicate)
Retries the currentMaybe
if it fails and the predicate returnstrue
.- Scheduler:
retry
does not operate by default on a particularScheduler
.
- Parameters:
predicate
- the predicate that receives the failureThrowable
and should returntrue
to trigger a retry.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifpredicate
isnull
-
retryUntil
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> retryUntil(@NonNull @NonNull BooleanSupplier stop)
Retries until the given stop function returnstrue
.- Scheduler:
retryUntil
does not operate by default on a particularScheduler
.
- Parameters:
stop
- the function that should returntrue
to stop retrying- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifstop
isnull
-
retryWhen
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> retryWhen(@NonNull @NonNull Function<? super Flowable<java.lang.Throwable>,? extends org.reactivestreams.Publisher<?>> handler)
Returns aMaybe
that emits the same values as the currentMaybe
with the exception of anonError
. AnonError
notification from the source will result in the emission of aThrowable
item to theFlowable
provided as an argument to thenotificationHandler
function. If the returnedPublisher
callsonComplete
oronError
thenretry
will callonComplete
oronError
on the child subscription. Otherwise, this operator will resubscribe to the currentMaybe
.Example: This retries 3 times, each time incrementing the number of seconds it waits.
Output is:Maybe.create((MaybeEmitter<? super String> s) -> { System.out.println("subscribing"); s.onError(new RuntimeException("always fails")); }, BackpressureStrategy.BUFFER).retryWhen(attempts -> { return attempts.zipWith(Publisher.range(1, 3), (n, i) -> i).flatMap(i -> { System.out.println("delay retry by " + i + " second(s)"); return Flowable.timer(i, TimeUnit.SECONDS); }); }).blockingForEach(System.out::println);
subscribing delay retry by 1 second(s) subscribing delay retry by 2 second(s) subscribing delay retry by 3 second(s) subscribing
Note that the inner
Publisher
returned by the handler function should signal eitheronNext
,onError
oronComplete
in response to the receivedThrowable
to indicate the operator should retry or terminate. If the upstream to the operator is asynchronous, signallingonNext
followed byonComplete
immediately may result in the sequence to be completed immediately. Similarly, if this innerPublisher
signalsonError
oronComplete
while the upstream is active, the sequence is terminated with the same signal immediately.The following example demonstrates how to retry an asynchronous source with a delay:
Maybe.timer(1, TimeUnit.SECONDS) .doOnSubscribe(s -> System.out.println("subscribing")) .map(v -> { throw new RuntimeException(); }) .retryWhen(errors -> { AtomicInteger counter = new AtomicInteger(); return errors .takeWhile(e -> counter.getAndIncrement() != 3) .flatMap(e -> { System.out.println("delay retry by " + counter.get() + " second(s)"); return Flowable.timer(counter.get(), TimeUnit.SECONDS); }); }) .blockingGet();
- Scheduler:
retryWhen
does not operate by default on a particularScheduler
.
- Parameters:
handler
- receives aPublisher
of notifications with which a user can complete or error, aborting the retry- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifhandler
isnull
- See Also:
- ReactiveX operators documentation: Retry
-
safeSubscribe
@SchedulerSupport("none") public final void safeSubscribe(@NonNull @NonNull MaybeObserver<? super @NonNull T> observer)
Wraps the givenMaybeObserver
, catches anyRuntimeException
s thrown by itsMaybeObserver.onSubscribe(Disposable)
,MaybeObserver.onSuccess(Object)
,MaybeObserver.onError(Throwable)
orMaybeObserver.onComplete()
methods and routes those to the global error handler viaRxJavaPlugins.onError(Throwable)
.By default, the
Maybe
protocol forbids theonXXX
methods to throw, but someMaybeObserver
implementation may do it anyway, causing undefined behavior in the upstream. This method and the underlying safe wrapper ensures such misbehaving consumers don't disrupt the protocol.- Scheduler:
safeSubscribe
does not operate by default on a particularScheduler
.
- Parameters:
observer
- the potentially misbehavingMaybeObserver
- Throws:
java.lang.NullPointerException
- ifobserver
isnull
- Since:
- 3.0.0
- See Also:
subscribe(Consumer,Consumer, Action)
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final @NonNull Flowable<T> startWith(@NonNull @NonNull CompletableSource other)
Returns aFlowable
which first runs the otherCompletableSource
then the currentMaybe
if the other completed normally.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherCompletableSource
to run first- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final @NonNull Flowable<T> startWith(@NonNull @NonNull SingleSource<@NonNull T> other)
Returns aFlowable
which first runs the otherSingleSource
then the currentMaybe
if the other succeeded normally.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherSingleSource
to run first- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final @NonNull Flowable<T> startWith(@NonNull @NonNull MaybeSource<@NonNull T> other)
Returns aFlowable
which first runs the otherMaybeSource
then the currentMaybe
if the other succeeded or completed normally.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherMaybeSource
to run first- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Observable<T> startWith(@NonNull @NonNull ObservableSource<@NonNull T> other)
Returns anObservable
which first delivers the events of the otherObservableSource
then runs the currentMaybe
.- Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherObservableSource
to run first- Returns:
- the new
Observable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public final @NonNull Flowable<T> startWith(@NonNull @NonNull org.reactivestreams.Publisher<@NonNull T> other)
Returns aFlowable
which first delivers the events of the otherPublisher
then runs the currentMaybe
.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well. - Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherPublisher
to run first- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 3.0.0
-
subscribe
@SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe()
Subscribes to aMaybe
and ignoresonSuccess
andonComplete
emissions.If the
Maybe
emits an error, it is wrapped into anOnErrorNotImplementedException
and routed to theRxJavaPlugins.onError(Throwable)
handler.- Scheduler:
subscribe
does not operate by default on a particularScheduler
.
- Returns:
- the new
Disposable
instance that can be used for disposing the subscription at any time - See Also:
- ReactiveX operators documentation: Subscribe,
subscribe(Consumer, Consumer, Action, DisposableContainer)
-
subscribe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess)
Subscribes to aMaybe
and provides a callback to handle the items it emits.If the
Maybe
emits an error, it is wrapped into anOnErrorNotImplementedException
and routed to theRxJavaPlugins.onError(Throwable)
handler.- Scheduler:
subscribe
does not operate by default on a particularScheduler
.
- Parameters:
onSuccess
- theConsumer<T>
you have designed to accept a success value from theMaybe
- Returns:
- the new
Disposable
instance that can be used for disposing the subscription at any time - Throws:
java.lang.NullPointerException
- ifonSuccess
isnull
- See Also:
- ReactiveX operators documentation: Subscribe,
subscribe(Consumer, Consumer, Action, DisposableContainer)
-
subscribe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super java.lang.Throwable> onError)
Subscribes to aMaybe
and provides callbacks to handle the items it emits and any error notification it issues.- Scheduler:
subscribe
does not operate by default on a particularScheduler
.
- Parameters:
onSuccess
- theConsumer<T>
you have designed to accept a success value from theMaybe
onError
- theConsumer<Throwable>
you have designed to accept any error notification from theMaybe
- Returns:
- the new
Disposable
instance that can be used for disposing the subscription at any time - Throws:
java.lang.NullPointerException
- ifonSuccess
isnull
, or ifonError
isnull
- See Also:
- ReactiveX operators documentation: Subscribe,
subscribe(Consumer, Consumer, Action, DisposableContainer)
-
subscribe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super java.lang.Throwable> onError, @NonNull @NonNull Action onComplete)
Subscribes to aMaybe
and provides callbacks to handle the items it emits and any error or completion notification it issues.- Scheduler:
subscribe
does not operate by default on a particularScheduler
.
- Parameters:
onSuccess
- theConsumer<T>
you have designed to accept a success value from theMaybe
onError
- theConsumer<Throwable>
you have designed to accept any error notification from theMaybe
onComplete
- theAction
you have designed to accept a completion notification from theMaybe
- Returns:
- the new
Disposable
instance that can be used for disposing the subscription at any time - Throws:
java.lang.NullPointerException
- ifonSuccess
,onError
oronComplete
isnull
- See Also:
- ReactiveX operators documentation: Subscribe,
subscribe(Consumer, Consumer, Action, DisposableContainer)
-
subscribe
@SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super java.lang.Throwable> onError, @NonNull @NonNull Action onComplete, @NonNull @NonNull DisposableContainer container)
Wraps the given onXXX callbacks into aDisposable
MaybeObserver
, adds it to the givenDisposableContainer
and ensures, that if the upstream terminates or this particularDisposable
is disposed, theMaybeObserver
is removed from the given composite.The
MaybeObserver
will be removed after the callback for the terminal event has been invoked.- Scheduler:
subscribe
does not operate by default on a particularScheduler
.
- Parameters:
onSuccess
- the callback for upstream itemsonError
- the callback for an upstream erroronComplete
- the callback for an upstream completion without any value or errorcontainer
- theDisposableContainer
(such asCompositeDisposable
) to add and remove the createdDisposable
MaybeObserver
- Returns:
- the
Disposable
that allows disposing the particular subscription. - Throws:
java.lang.NullPointerException
- ifonSuccess
,onError
,onComplete
orcontainer
isnull
- Since:
- 3.1.0
-
subscribe
@SchedulerSupport("none") public final void subscribe(@NonNull @NonNull MaybeObserver<? super @NonNull T> observer)
Description copied from interface:MaybeSource
Subscribes the givenMaybeObserver
to thisMaybeSource
instance.- Specified by:
subscribe
in interfaceMaybeSource<T>
- Parameters:
observer
- theMaybeObserver
, notnull
-
subscribeActual
protected abstract void subscribeActual(@NonNull @NonNull MaybeObserver<? super @NonNull T> observer)
Implement this method in subclasses to handle the incomingMaybeObserver
s.There is no need to call any of the plugin hooks on the current
Maybe
instance or theMaybeObserver
; all hooks and basic safeguards have been applied bysubscribe(MaybeObserver)
before this method gets called.- Parameters:
observer
- theMaybeObserver
to handle, notnull
-
subscribeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<T> subscribeOn(@NonNull @NonNull Scheduler scheduler)
Asynchronously subscribes subscribers to thisMaybe
on the specifiedScheduler
.- Scheduler:
- you specify which
Scheduler
this operator will use.
- Parameters:
scheduler
- theScheduler
to perform subscription actions on- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifscheduler
isnull
- See Also:
- ReactiveX operators documentation: SubscribeOn,
RxJava Threading Examples,
observeOn(io.reactivex.rxjava3.core.Scheduler)
-
subscribeWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull E extends MaybeObserver<? super @NonNull T>> E subscribeWith(@NonNull E observer)
Subscribes a givenMaybeObserver
(subclass) to thisMaybe
and returns the givenMaybeObserver
as is.Usage example:
Maybe<Integer> source = Maybe.just(1); CompositeDisposable composite = new CompositeDisposable(); DisposableMaybeObserver<Integer> ds = new DisposableMaybeObserver<>() { // ... }; composite.add(source.subscribeWith(ds));
- Scheduler:
subscribeWith
does not operate by default on a particularScheduler
.
- Type Parameters:
E
- the type of theMaybeObserver
to use and return- Parameters:
observer
- theMaybeObserver
(subclass) to use and return, notnull
- Returns:
- the input
observer
- Throws:
java.lang.NullPointerException
- ifobserver
isnull
-
switchIfEmpty
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> switchIfEmpty(@NonNull @NonNull MaybeSource<? extends @NonNull T> other)
Returns aMaybe
that emits the items emitted by the currentMaybe
or the items of an alternateMaybeSource
if the currentMaybe
is empty.- Scheduler:
switchIfEmpty
does not operate by default on a particularScheduler
.
- Parameters:
other
- the alternateMaybeSource
to subscribe to if the main does not emit any items- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
-
switchIfEmpty
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> switchIfEmpty(@NonNull @NonNull SingleSource<? extends @NonNull T> other)
Returns aSingle
that emits the items emitted by the currentMaybe
or the item of an alternateSingleSource
if the currentMaybe
is empty.- Scheduler:
switchIfEmpty
does not operate by default on a particularScheduler
.
History: 2.1.4 - experimental
- Parameters:
other
- the alternateSingleSource
to subscribe to if the main does not emit any items- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 2.2
-
takeUntil
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<T> takeUntil(@NonNull @NonNull MaybeSource<@NonNull U> other)
Returns aMaybe
that emits the items emitted by the currentMaybe
until a secondMaybeSource
emits an item.- Scheduler:
takeUntil
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the type of items emitted byother
- Parameters:
other
- theMaybeSource
whose first emitted item will causetakeUntil
to stop emitting items from the currentMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- See Also:
- ReactiveX operators documentation: TakeUntil
-
takeUntil
@BackpressureSupport(UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<T> takeUntil(@NonNull @NonNull org.reactivestreams.Publisher<@NonNull U> other)
Returns aMaybe
that emits the item emitted by the currentMaybe
until a secondPublisher
emits an item.- Backpressure:
- The
Publisher
is consumed in an unbounded fashion and is cancelled after the first item emitted. - Scheduler:
takeUntil
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the type of items emitted byother
- Parameters:
other
- thePublisher
whose first emitted item will causetakeUntil
to stop emitting items from the sourcePublisher
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- See Also:
- ReactiveX operators documentation: TakeUntil
-
timeInterval
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Maybe<Timed<T>> timeInterval()
Measures the time (in milliseconds) between the subscription and success item emission of the currentMaybe
and signals it as a tuple (Timed
) success value.If the current
Maybe
is empty or fails, the resultingMaybe
will pass along the signals to the downstream. To measure the time to termination, usematerialize()
and applySingle.timeInterval()
.- Scheduler:
timeInterval
uses thecomputation
Scheduler
for determining the current time upon subscription and upon receiving the success item from the currentMaybe
.
- Returns:
- the new
Maybe
instance - Since:
- 3.0.0
-
timeInterval
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<Timed<T>> timeInterval(@NonNull @NonNull Scheduler scheduler)
Measures the time (in milliseconds) between the subscription and success item emission of the currentMaybe
and signals it as a tuple (Timed
) success value.If the current
Maybe
is empty or fails, the resultingMaybe
will pass along the signals to the downstream. To measure the time to termination, usematerialize()
and applySingle.timeInterval(Scheduler)
.- Scheduler:
timeInterval
uses the providedScheduler
for determining the current time upon subscription and upon receiving the success item from the currentMaybe
.
- Parameters:
scheduler
- theScheduler
used for providing the current time- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifscheduler
isnull
- Since:
- 3.0.0
-
timeInterval
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Maybe<Timed<T>> timeInterval(@NonNull @NonNull java.util.concurrent.TimeUnit unit)
Measures the time between the subscription and success item emission of the currentMaybe
and signals it as a tuple (Timed
) success value.If the current
Maybe
is empty or fails, the resultingMaybe
will pass along the signals to the downstream. To measure the time to termination, usematerialize()
and applySingle.timeInterval(TimeUnit)
.- Scheduler:
timeInterval
uses thecomputation
Scheduler
for determining the current time upon subscription and upon receiving the success item from the currentMaybe
.
- Parameters:
unit
- the time unit for measurement- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- Since:
- 3.0.0
-
timeInterval
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<Timed<T>> timeInterval(@NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Measures the time between the subscription and success item emission of the currentMaybe
and signals it as a tuple (Timed
) success value.If the current
Maybe
is empty or fails, the resultingMaybe
will pass along the signals to the downstream. To measure the time to termination, usematerialize()
and applySingle.timeInterval(TimeUnit, Scheduler)
.- Scheduler:
timeInterval
uses the providedScheduler
for determining the current time upon subscription and upon receiving the success item from the currentMaybe
.
- Parameters:
unit
- the time unit for measurementscheduler
- theScheduler
used for providing the current time- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
- Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Maybe<Timed<T>> timestamp()
Combines the success value from the currentMaybe
with the current time (in milliseconds) of its reception, using thecomputation
Scheduler
as time source, then signals them as aTimed
instance.If the current
Maybe
is empty or fails, the resultingMaybe
will pass along the signals to the downstream. To measure the time to termination, usematerialize()
and applySingle.timestamp()
.- Scheduler:
timestamp
uses thecomputation
Scheduler
for determining the current time upon receiving the success item from the currentMaybe
.
- Returns:
- the new
Maybe
instance - Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<Timed<T>> timestamp(@NonNull @NonNull Scheduler scheduler)
Combines the success value from the currentMaybe
with the current time (in milliseconds) of its reception, using the givenScheduler
as time source, then signals them as aTimed
instance.If the current
Maybe
is empty or fails, the resultingMaybe
will pass along the signals to the downstream. To measure the time to termination, usematerialize()
and applySingle.timestamp(Scheduler)
.- Scheduler:
timestamp
uses the providedScheduler
for determining the current time upon receiving the success item from the currentMaybe
.
- Parameters:
scheduler
- theScheduler
used for providing the current time- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifscheduler
isnull
- Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Maybe<Timed<T>> timestamp(@NonNull @NonNull java.util.concurrent.TimeUnit unit)
Combines the success value from the currentMaybe
with the current time of its reception, using thecomputation
Scheduler
as time source, then signals it as aTimed
instance.If the current
Maybe
is empty or fails, the resultingMaybe
will pass along the signals to the downstream. To measure the time to termination, usematerialize()
and applySingle.timestamp(TimeUnit)
.- Scheduler:
timestamp
uses thecomputation
Scheduler
, for determining the current time upon receiving the success item from the currentMaybe
.
- Parameters:
unit
- the time unit for measurement- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<Timed<T>> timestamp(@NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Combines the success value from the currentMaybe
with the current time of its reception, using the givenScheduler
as time source, then signals it as aTimed
instance.If the current
Maybe
is empty or fails, the resultingMaybe
will pass along the signals to the downstream. To measure the time to termination, usematerialize()
and applySingle.timestamp(TimeUnit, Scheduler)
.- Scheduler:
timestamp
uses the providedScheduler
, which is used for determining the current time upon receiving the success item from the currentMaybe
.
- Parameters:
unit
- the time unit for measurementscheduler
- theScheduler
used for providing the current time- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
- Since:
- 3.0.0
-
timeout
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Maybe<T> timeout(long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Returns aMaybe
that mirrors the currentMaybe
but applies a timeout policy for each emitted item. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the resultingMaybe
terminates and notifiesMaybeObserver
s of aTimeoutException
.- Scheduler:
- This version of
timeout
operates by default on thecomputation
Scheduler
.
- Parameters:
timeout
- maximum duration between emitted items before a timeout occursunit
- the unit of time that applies to thetimeout
argument.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- See Also:
- ReactiveX operators documentation: Timeout
-
timeout
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Maybe<T> timeout(long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull MaybeSource<? extends @NonNull T> fallback)
Returns aMaybe
that mirrors the currentMaybe
but applies a timeout policy for each emitted item. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the currentMaybe
is disposed and resultingMaybe
begins instead to mirror a fallbackMaybeSource
.- Scheduler:
- This version of
timeout
operates by default on thecomputation
Scheduler
.
- Parameters:
timeout
- maximum duration between items before a timeout occursunit
- the unit of time that applies to thetimeout
argumentfallback
- the fallbackMaybeSource
to use in case of a timeout- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
orfallback
isnull
- See Also:
- ReactiveX operators documentation: Timeout
-
timeout
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<T> timeout(long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler, @NonNull @NonNull MaybeSource<? extends @NonNull T> fallback)
Returns aMaybe
that mirrors the currentMaybe
but applies a timeout policy for each emitted item using a specifiedScheduler
. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the currentMaybe
is disposed and resultingMaybe
begins instead to mirror a fallbackMaybeSource
.- Scheduler:
- You specify which
Scheduler
this operator will use.
- Parameters:
timeout
- maximum duration between items before a timeout occursunit
- the unit of time that applies to thetimeout
argumentfallback
- theMaybeSource
to use as the fallback in case of a timeoutscheduler
- theScheduler
to run the timeout timers on- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- iffallback
,unit
orscheduler
isnull
- See Also:
- ReactiveX operators documentation: Timeout
-
timeout
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Maybe<T> timeout(long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Returns aMaybe
that mirrors the currentMaybe
but applies a timeout policy for each emitted item, where this policy is governed on a specifiedScheduler
. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the resultingMaybe
terminates and notifiesMaybeObserver
s of aTimeoutException
.- Scheduler:
- You specify which
Scheduler
this operator will use.
- Parameters:
timeout
- maximum duration between items before a timeout occursunit
- the unit of time that applies to thetimeout
argumentscheduler
- theScheduler
to run the timeout timers on- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
- See Also:
- ReactiveX operators documentation: Timeout
-
timeout
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<T> timeout(@NonNull @NonNull MaybeSource<@NonNull U> timeoutIndicator)
If the currentMaybe
didn't signal an event before thetimeoutIndicator
MaybeSource
signals, aTimeoutException
is signaled instead.- Scheduler:
timeout
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the value type of the- Parameters:
timeoutIndicator
- theMaybeSource
that indicates the timeout by signalingonSuccess
oronComplete
.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- iftimeoutIndicator
isnull
-
timeout
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<T> timeout(@NonNull @NonNull MaybeSource<@NonNull U> timeoutIndicator, @NonNull @NonNull MaybeSource<? extends @NonNull T> fallback)
If the currentMaybe
didn't signal an event before thetimeoutIndicator
MaybeSource
signals, the currentMaybe
is disposed and thefallback
MaybeSource
subscribed to as a continuation.- Scheduler:
timeout
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the value type of the- Parameters:
timeoutIndicator
- theMaybeSource
that indicates the timeout by signalingonSuccess
oronComplete
.fallback
- theMaybeSource
that is subscribed to if the currentMaybe
times out- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- iftimeoutIndicator
orfallback
isnull
-
timeout
@BackpressureSupport(UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<T> timeout(@NonNull @NonNull org.reactivestreams.Publisher<@NonNull U> timeoutIndicator)
If the currentMaybe
source didn't signal an event before thetimeoutIndicator
Publisher
signals, aTimeoutException
is signaled instead.- Backpressure:
- The
timeoutIndicator
Publisher
is consumed in an unbounded manner and is cancelled after its first item. - Scheduler:
timeout
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the value type of the- Parameters:
timeoutIndicator
- thePublisher
that indicates the timeout by signalingonSuccess
oronComplete
.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- iftimeoutIndicator
isnull
-
timeout
@BackpressureSupport(UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<T> timeout(@NonNull @NonNull org.reactivestreams.Publisher<@NonNull U> timeoutIndicator, @NonNull @NonNull MaybeSource<? extends @NonNull T> fallback)
If the currentMaybe
didn't signal an event before thetimeoutIndicator
Publisher
signals, the currentMaybe
is disposed and thefallback
MaybeSource
subscribed to as a continuation.- Backpressure:
- The
timeoutIndicator
Publisher
is consumed in an unbounded manner and is cancelled after its first item. - Scheduler:
timeout
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the value type of the- Parameters:
timeoutIndicator
- theMaybeSource
that indicates the timeout by signalingonSuccess
oronComplete
fallback
- theMaybeSource
that is subscribed to if the currentMaybe
times out- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- iftimeoutIndicator
orfallback
isnull
-
unsubscribeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<T> unsubscribeOn(@NonNull @NonNull Scheduler scheduler)
Returns aMaybe
which makes sure when aMaybeObserver
disposes theDisposable
, that call is propagated up on the specifiedScheduler
.- Scheduler:
unsubscribeOn
callsdispose()
of the upstream on theScheduler
you specify.
- Parameters:
scheduler
- the target scheduler where to execute the disposal- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifscheduler
isnull
-
zipWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U,@NonNull R> @NonNull Maybe<R> zipWith(@NonNull @NonNull MaybeSource<? extends @NonNull U> other, @NonNull @NonNull BiFunction<? super @NonNull T,? super @NonNull U,? extends @NonNull R> zipper)
Waits until this and the otherMaybeSource
signal a success value then applies the givenBiFunction
to those values and emits theBiFunction
's resulting value to downstream.If either this or the other
MaybeSource
is empty or signals an error, the resultingMaybe
will terminate immediately and dispose the other source.- Scheduler:
zipWith
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the type of items emitted by theother
MaybeSource
R
- the type of items emitted by the resultingMaybe
- Parameters:
other
- the otherMaybeSource
zipper
- a function that combines the pairs of items from the twoMaybeSource
s to generate the items to be emitted by the resultingMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifother
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
test
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull TestObserver<T> test()
Creates aTestObserver
and subscribes it to thisMaybe
.- Scheduler:
test
does not operate by default on a particularScheduler
.
- Returns:
- the new
TestObserver
instance
-
test
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull TestObserver<T> test(boolean dispose)
Creates aTestObserver
optionally in cancelled state, then subscribes it to thisMaybe
.- Scheduler:
test
does not operate by default on a particularScheduler
.
- Parameters:
dispose
- iftrue
, theTestObserver
will be disposed before subscribing to thisMaybe
.- Returns:
- the new
TestObserver
instance
-
fromOptional
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Maybe<@NonNull T> fromOptional(@NonNull @NonNull java.util.Optional<@NonNull T> optional)
Converts the existing value of the provided optional into ajust(Object)
or an empty optional into anempty()
Maybe
instance.Note that the operator takes an already instantiated optional reference and does not by any means create this original optional. If the optional is to be created per consumer upon subscription, use
defer(Supplier)
aroundfromOptional
:Maybe.defer(() -> Maybe.fromOptional(createOptional()));
- Scheduler:
fromOptional
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the element type of the optional value- Parameters:
optional
- the optional value to convert into aMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifoptional
isnull
- Since:
- 3.0.0
- See Also:
just(Object)
,empty()
-
fromCompletionStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Maybe<@NonNull T> fromCompletionStage(@NonNull @NonNull java.util.concurrent.CompletionStage<@NonNull T> stage)
Signals the completion value or error of the given (hot)CompletionStage
-based asynchronous calculation.Note that the operator takes an already instantiated, running or terminated
CompletionStage
. If theCompletionStage
is to be created per consumer upon subscription, usedefer(Supplier)
aroundfromCompletionStage
:Maybe.defer(() -> Maybe.fromCompletionStage(createCompletionStage()));
If the
CompletionStage
completes withnull
, the resultingMaybe
is completed viaonComplete
.Canceling the flow can't cancel the execution of the
CompletionStage
becauseCompletionStage
itself doesn't support cancellation. Instead, the operator detaches from theCompletionStage
.- Scheduler:
fromCompletionStage
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the element type of theCompletionStage
- Parameters:
stage
- theCompletionStage
to convert toMaybe
and signal its terminal value or error- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifstage
isnull
- Since:
- 3.0.0
-
mapOptional
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Maybe<R> mapOptional(@NonNull @NonNull Function<? super @NonNull T,@NonNull java.util.Optional<? extends @NonNull R>> mapper)
Maps the upstream success value into anOptional
and emits the contained item if not empty.- Scheduler:
mapOptional
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the non-null
output type- Parameters:
mapper
- the function that receives the upstream success item and should return a non-emptyOptional
to emit as the success output or an emptyOptional
to complete theMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- Since:
- 3.0.0
- See Also:
map(Function)
,filter(Predicate)
-
toCompletionStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull java.util.concurrent.CompletionStage<T> toCompletionStage()
Signals the upstream success item (or aNoSuchElementException
if the upstream is empty) via aCompletionStage
.The upstream can be canceled by converting the resulting
CompletionStage
intoCompletableFuture
viaCompletionStage.toCompletableFuture()
and callingCompletableFuture.cancel(boolean)
on it. The upstream will be also cancelled if the resultingCompletionStage
is converted to and completed manually byCompletableFuture.complete(Object)
orCompletableFuture.completeExceptionally(Throwable)
.CompletionStage
s don't have a notion of emptiness and allownull
s, therefore, one can either usetoCompletionStage(Object)
withnull
or turn the upstream into a sequence ofOptional
s and default toOptional.empty()
:CompletionStage<Optional<T>> stage = source.map(Optional::of).toCompletionStage(Optional.empty());
- Scheduler:
toCompletionStage
does not operate by default on a particularScheduler
.
- Returns:
- the new
CompletionStage
instance - Since:
- 3.0.0
- See Also:
toCompletionStage(Object)
-
toCompletionStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull java.util.concurrent.CompletionStage<T> toCompletionStage(@Nullable @NonNull T defaultItem)
Signals the upstream success item (or the default item if the upstream is empty) via aCompletionStage
.The upstream can be canceled by converting the resulting
CompletionStage
intoCompletableFuture
viaCompletionStage.toCompletableFuture()
and callingCompletableFuture.cancel(boolean)
on it. The upstream will be also cancelled if the resultingCompletionStage
is converted to and completed manually byCompletableFuture.complete(Object)
orCompletableFuture.completeExceptionally(Throwable)
.CompletionStage
s don't have a notion of emptiness and allownull
s, therefore, one can either use adefaultItem
ofnull
or turn the flow into a sequence ofOptional
s and default toOptional.empty()
:CompletionStage<Optional<T>> stage = source.map(Optional::of).toCompletionStage(Optional.empty());
- Scheduler:
toCompletionStage
does not operate by default on a particularScheduler
.
- Parameters:
defaultItem
- the item to signal if the upstream is empty- Returns:
- the new
CompletionStage
instance - Since:
- 3.0.0
-
flattenStreamAsFlowable
@CheckReturnValue @SchedulerSupport("none") @BackpressureSupport(FULL) @NonNull public final <@NonNull R> @NonNull Flowable<R> flattenStreamAsFlowable(@NonNull @NonNull Function<? super @NonNull T,? extends java.util.stream.Stream<? extends @NonNull R>> mapper)
Maps the upstream succecss value into a JavaStream
and emits its items to the downstream consumer as aFlowable
.The operator closes the
Stream
upon cancellation and when it terminates. The exceptions raised when closing aStream
are routed to the global error handler (RxJavaPlugins.onError(Throwable)
. If aStream
should not be closed, turn it into anIterable
and useflattenAsFlowable(Function)
:source.flattenAsFlowable(item -> createStream(item)::iterator);
Primitive streams are not supported and items have to be boxed manually (e.g., via
IntStream.boxed()
):source.flattenStreamAsFlowable(item -> IntStream.rangeClosed(1, 10).boxed());
Stream
does not support concurrent usage so creating and/or consuming the same instance multiple times from multiple threads can lead to undefined behavior.- Backpressure:
- The operator honors backpressure from downstream and iterates the given
Stream
on demand (i.e., when requested). - Scheduler:
flattenStreamAsFlowable
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the element type of theStream
and the outputFlowable
- Parameters:
mapper
- the function that receives the upstream success item and should return aStream
of values to emit.- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- Since:
- 3.0.0
- See Also:
flattenAsFlowable(Function)
,flattenStreamAsObservable(Function)
-
flattenStreamAsObservable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flattenStreamAsObservable(@NonNull @NonNull Function<? super @NonNull T,? extends java.util.stream.Stream<? extends @NonNull R>> mapper)
Maps the upstream succecss value into a JavaStream
and emits its items to the downstream consumer as anObservable
.The operator closes the
Stream
upon cancellation and when it terminates. The exceptions raised when closing aStream
are routed to the global error handler (RxJavaPlugins.onError(Throwable)
. If aStream
should not be closed, turn it into anIterable
and useflattenAsObservable(Function)
:source.flattenAsObservable(item -> createStream(item)::iterator);
Primitive streams are not supported and items have to be boxed manually (e.g., via
IntStream.boxed()
):source.flattenStreamAsObservable(item -> IntStream.rangeClosed(1, 10).boxed());
Stream
does not support concurrent usage so creating and/or consuming the same instance multiple times from multiple threads can lead to undefined behavior.- Scheduler:
flattenStreamAsObservable
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the element type of theStream
and the outputObservable
- Parameters:
mapper
- the function that receives the upstream success item and should return aStream
of values to emit.- Returns:
- the new
Observable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- Since:
- 3.0.0
- See Also:
flattenAsObservable(Function)
,flattenStreamAsFlowable(Function)
-
-