Class Maybe<T>
- Type Parameters:
T- the value type
- All Implemented Interfaces:
MaybeSource<T>
- Direct Known Subclasses:
MaybeSubject
Maybe class represents a deferred computation and emission of a single value, no value at all or an exception.
The Maybe class implements the MaybeSource base interface and the default consumer
type it interacts with is the MaybeObserver via the subscribe(MaybeObserver) method.
The Maybe operates with the following sequential protocol:
onSubscribe (onSuccess | onError | onComplete)?
Note that onSuccess, onError and onComplete are mutually exclusive events; unlike Observable,
onSuccess is never followed by onError or onComplete.
Like Observable, a running Maybe can be stopped through the Disposable instance
provided to consumers through MaybeObserver.onSubscribe(Disposable).
Like an Observable, a Maybe 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 or Observable 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 the
void return of the subscribe(MaybeObserver) method) and it is the
responsibility of the implementor of the MaybeObserver to allow this to happen.
RxJava supports such usage with the standard
DisposableMaybeObserver instance.
For convenience, the subscribeWith(MaybeObserver) method is provided as well to
allow working with a MaybeObserver (or subclass) instance to be applied with in
a fluent manner (such as in the example above).
- Since:
- 2.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRuns multipleMaybeSources provided by anIterablesequence and signals the events of the first one that signals (disposing the rest).ambArray(@NonNull MaybeSource<? extends @NonNull T>... sources) Runs multipleMaybeSources and signals the events of the first one that signals (disposing the rest).ambWith(@NonNull MaybeSource<? extends @NonNull T> other) Mirrors theMaybeSource(current or provided) that first signals an event.final TWaits in a blocking fashion until the currentMaybesignals a success value (which is returned),nullif completed or an exception (which is propagated).final TblockingGet(@NonNull T defaultValue) Waits in a blocking fashion until the currentMaybesignals a success value (which is returned), defaultValue if completed or an exception (which is propagated).final voidSubscribes to the currentMaybeand blocks the current thread until it terminates.final voidblockingSubscribe(@NonNull MaybeObserver<? super @NonNull T> observer) Subscribes to the currentMaybeand calls the appropriateMaybeObservermethod on the current thread.final voidblockingSubscribe(@NonNull Consumer<? super @NonNull T> onSuccess) Subscribes to the currentMaybeand calls givenonSuccesscallback on the current thread when it completes normally.final voidblockingSubscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super Throwable> onError) Subscribes to the currentMaybeand calls the appropriate callback on the current thread when it terminates.final voidblockingSubscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super Throwable> onError, @NonNull Action onComplete) Subscribes to the currentMaybeand calls the appropriate callback on the current thread when it terminates.cache()Returns aMaybethat subscribes to thisMaybelazily, caches its event and replays it, to all the downstream subscribers.Casts the success value of the currentMaybeinto the target type or signals aClassCastExceptionif not compatible.Transform aMaybeby applying a particularMaybeTransformerfunction to it.concat(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2) Returns aFlowablethat emits the items emitted by twoMaybeSources, one after the other.concat(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull MaybeSource<? extends @NonNull T> source3) Returns aFlowablethat emits the items emitted by threeMaybeSources, one after the other.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 aFlowablethat emits the items emitted by fourMaybeSources, one after the other.Concatenate the single values, in a non-overlapping fashion, of theMaybeSourcesources provided by anIterablesequence as aFlowablesequence.concat(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenate the single values, in a non-overlapping fashion, of theMaybeSourcesources provided by aFlow.Publishersequence as aFlowablesequence.concat(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int prefetch) Concatenate the single values, in a non-overlapping fashion, of theMaybeSourcesources provided by aFlow.Publishersequence as aFlowablesequence.concatArray(@NonNull MaybeSource<? extends @NonNull T>... sources) Concatenate the single values, in a non-overlapping fashion, of theMaybeSourcesources in the array as aFlowablesequence.concatArrayDelayError(@NonNull MaybeSource<? extends @NonNull T>... sources) Concatenates a variable number ofMaybeSourcesources and delays errors from any of them till all terminate as aFlowablesequence.concatArrayEager(@NonNull MaybeSource<? extends @NonNull T>... sources) Concatenates a sequence ofMaybeSourceeagerly into aFlowablesequence.concatArrayEagerDelayError(@NonNull MaybeSource<? extends @NonNull T>... sources) Concatenates a sequence ofMaybeSourceeagerly into aFlowablesequence.concatDelayError(@NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenates theIterablesequence ofMaybeSources into a single sequence by subscribing to eachMaybeSource, one after the other, one at a time and delays any errors till the all innerMaybeSources terminate as aFlowablesequence.concatDelayError(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenates theFlow.Publishersequence ofMaybeSources 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 outerPublisherterminate as aFlowablesequence.concatDelayError(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int prefetch) Concatenates theFlow.Publishersequence ofMaybeSources 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 outerPublisherterminate as aFlowablesequence.concatEager(@NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenates a sequence ofMaybeSources eagerly into aFlowablesequence.concatEager(@NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency) Concatenates a sequence ofMaybeSources eagerly into aFlowablesequence and runs a limited number of the inner sequences at once.concatEager(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) concatEager(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency) Concatenates aFlow.Publishersequence ofMaybeSources eagerly into aFlowablesequence, running at most the given number of innerMaybeSources at once.concatEagerDelayError(@NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenates a sequence ofMaybeSources eagerly into aFlowablesequence, delaying errors until all innerMaybeSources terminate.concatEagerDelayError(@NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency) Concatenates a sequence ofMaybeSources eagerly into aFlowablesequence, delaying errors until all innerMaybeSources terminate and runs a limited number of innerMaybeSources at once.concatEagerDelayError(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenates aFlow.Publishersequence ofMaybeSources eagerly into aFlowablesequence, delaying errors until all the inner and the outer sequence terminate.concatEagerDelayError(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency) Concatenates aFlow.Publishersequence ofMaybeSources eagerly into aFlowablesequence, delaying errors until all the inner and the outer sequence terminate and runs a limited number of the innerMaybeSources at once.concatMap(@NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper) Returns aMaybethat is based on applying a specified function to the item emitted by the currentMaybe, where that function returns aMaybeSource.final @NonNull CompletableconcatMapCompletable(@NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Returns aCompletablethat completes based on applying a specified function to the item emitted by the currentMaybe, where that function returns aCompletable.concatMapSingle(@NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Returns aMaybebased on applying a specified function to the item emitted by the currentMaybe, where that function returns aSingle.concatWith(@NonNull MaybeSource<? extends @NonNull T> other) Returns aFlowablethat emits the items emitted from the currentMaybe, then theotherMaybeSource, one after the other, without interleaving them.count()create(@NonNull MaybeOnSubscribe<@NonNull T> onSubscribe) Provides an API (via a coldMaybe) that bridges the reactive world with the callback-style world.defaultIfEmpty(@NonNull T defaultItem) Returns aSinglethat emits the item emitted by the currentMaybeor a specified default item if the currentMaybeis empty.Calls aSupplierfor each individualMaybeObserverto return the actualMaybeSourcesource to be subscribed to.Returns aMaybethat signals the events emitted by the currentMaybeshifted forward in time by a specified delay.Returns aMaybethat signals the events emitted by the currentMaybeshifted forward in time by a specified delay.Returns aMaybethat signals the events emitted by the currentMaybeshifted forward in time by a specified delay.Returns aMaybethat signals the events emitted by the currentMaybeshifted forward in time by a specified delay running on the specifiedScheduler.delay(@NonNull Flow.Publisher<@NonNull U> delayIndicator) Delays the emission of thisMaybeuntil the givenFlow.Publishersignals an item or completes.delaySubscription(long time, @NonNull TimeUnit unit) Returns aMaybethat delays the subscription to the currentMaybeby a given amount of time.delaySubscription(long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler) Returns aMaybethat delays the subscription to the currentMaybeby a given amount of time, both waiting and subscribing on a givenScheduler.delaySubscription(@NonNull Flow.Publisher<@NonNull U> subscriptionIndicator) Returns aMaybethat delays the subscription to thisMaybeuntil the otherFlow.Publisheremits an element or completes normally.dematerialize(@NonNull Function<? super @NonNull T, @NonNull Notification<@NonNull R>> selector) Maps theNotificationsuccess value of the currentMaybeback into normalonSuccess,onErrororonCompletesignals.doAfterSuccess(@NonNull Consumer<? super @NonNull T> onAfterSuccess) Calls the specifiedConsumerwith the success item after this item has been emitted to the downstream.doAfterTerminate(@NonNull Action onAfterTerminate) Calls the specified action after thisMaybesignalsonSuccess,onErrororonCompleteor gets disposed by the downstream.doOnComplete(@NonNull Action onComplete) doOnDispose(@NonNull Action onDispose) Calls the sharedActionif aMaybeObserversubscribed to the currentMaybedisposes the commonDisposableit received viaonSubscribe.Calls the sharedConsumerwith the error sent viaonErrorfor eachMaybeObserverthat subscribes to the currentMaybe.Calls the givenonEventcallback with the (success value,null) for anonSuccess, (null, throwable) for anonErroror (null,null) for anonCompletesignal from thisMaybebefore delivering said signal to the downstream.doOnLifecycle(@NonNull Consumer<? super Disposable> onSubscribe, @NonNull Action onDispose) Calls the appropriateonXXXmethod (shared between allMaybeObservers) for the lifecycle events of the sequence (subscription, disposal).doOnSubscribe(@NonNull Consumer<? super Disposable> onSubscribe) Calls the sharedConsumerwith theDisposablesent through theonSubscribefor eachMaybeObserverthat subscribes to the currentMaybe.doOnSuccess(@NonNull Consumer<? super @NonNull T> onSuccess) Calls the sharedConsumerwith the success value sent viaonSuccessfor eachMaybeObserverthat subscribes to the currentMaybe.doOnTerminate(@NonNull Action onTerminate) Returns aMaybeinstance that calls the given onTerminate callback just before thisMaybecompletes normally or with an exception.empty()Returns a (singleton)Maybeinstance that callsonCompleteimmediately.Returns aMaybethat invokes aMaybeObserver'sonErrormethod when theMaybeObserversubscribes to it.Returns aMaybethat invokes a subscriber'sonErrormethod when the subscriber subscribes to it.Filters the success item of theMaybevia a predicate function and emitting it if the predicate returnstrue, completing otherwise.Returns aMaybethat is based on applying a specified function to the item emitted by the currentMaybe, where that function returns aMaybeSource.flatMap(@NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> onSuccessMapper, @NonNull Function<? super Throwable, ? extends MaybeSource<? extends @NonNull R>> onErrorMapper, @NonNull Supplier<? extends MaybeSource<? extends @NonNull R>> onCompleteSupplier) Maps theonSuccess,onErrororonCompletesignals of the currentMaybeinto aMaybeSourceand emits thatMaybeSource's signals.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 aMaybethat emits the results of a specified function to the pair of values emitted by the currentMaybeand a specified mappedMaybeSource.final @NonNull CompletableflatMapCompletable(@NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Returns aCompletablethat completes based on applying a specified function to the item emitted by the currentMaybe, where that function returns aCompletable.final <@NonNull R>
@NonNull Observable<R> flatMapObservable(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper) Returns anObservablethat is based on applying a specified function to the item emitted by the currentMaybe, where that function returns anObservableSource.flatMapPublisher(@NonNull Function<? super @NonNull T, @NonNull ? extends Flow.Publisher<? extends @NonNull R>> mapper) Returns aFlowablethat emits items based on applying a specified function to the item emitted by the currentMaybe, where that function returns aFlow.Publisher.flatMapSingle(@NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Returns aMaybebased on applying a specified function to the item emitted by the currentMaybe, where that function returns aSingle.flattenAsFlowable(@NonNull Function<? super @NonNull T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper) final <@NonNull U>
@NonNull Observable<U> flattenAsObservable(@NonNull Function<? super @NonNull T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper) Maps the success value of the currentMaybeinto anIterableand emits its items as anObservablesequence.flattenStreamAsFlowable(@NonNull Function<? super @NonNull T, @NonNull ? extends Stream<? extends @NonNull R>> mapper) final <@NonNull R>
@NonNull Observable<R> flattenStreamAsObservable(@NonNull Function<? super @NonNull T, @NonNull ? extends Stream<? extends @NonNull R>> mapper) Maps the upstream succecss value into a JavaStreamand emits its items to the downstream consumer as anObservable.fromAction(@NonNull Action action) Returns aMaybeinstance that runs the givenActionfor eachMaybeObserverand emits either its exception or simply completes.fromCallable(@NonNull Callable<? extends @Nullable T> callable) Returns aMaybethat invokes the givenCallablefor each individualMaybeObserverthat subscribes and emits the resulting non-nullitem viaonSuccesswhile considering anullresult from theCallableas indication for valueless completion viaonComplete.fromCompletable(@NonNull CompletableSource completableSource) Wraps aCompletableSourceinto aMaybe.fromCompletionStage(@NonNull CompletionStage<@NonNull T> stage) Signals the completion value or error of the given (hot)CompletionStage-based asynchronous calculation.fromFuture(@NonNull Future<? extends @NonNull T> future) fromObservable(@NonNull ObservableSource<@NonNull T> source) Wraps anObservableSourceinto aMaybeand emits the very first item or completes if the source is empty.fromOptional(@NonNull Optional<@NonNull T> optional) Converts the existing value of the provided optional into ajust(Object)or an empty optional into anempty()Maybeinstance.fromPublisher(@NonNull Flow.Publisher<@NonNull T> source) Wraps aFlow.Publisherinto aMaybeand emits the very first item or completes if the source is empty.fromRunnable(@NonNull Runnable run) Returns aMaybeinstance that runs the givenRunnablefor eachMaybeObserverand emits either its unchecked exception or simply completes.fromSingle(@NonNull SingleSource<@NonNull T> single) Wraps aSingleSourceinto aMaybe.fromSupplier(@NonNull Supplier<? extends @Nullable T> supplier) Returns aMaybethat invokes the givenSupplierfor each individualMaybeObserverthat subscribes and emits the resulting non-nullitem viaonSuccesswhile considering anullresult from theSupplieras indication for valueless completion viaonComplete.hide()Hides the identity of thisMaybeand itsDisposable.final @NonNull CompletableReturns aCompletablethat ignores the item emitted by the currentMaybeand only callsonCompleteoronError.isEmpty()Returns aMaybethat emits a specified item.This method requires advanced knowledge about building operators, please consider other standard composition methods first; Returns aMaybewhich, when subscribed to, invokes theapply(MaybeObserver)method of the providedMaybeOperatorfor each individual downstreamMaybeand allows the insertion of a custom operator by accessing the downstream'sMaybeObserverduring 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.Returns aMaybethat applies a specified function to the item emitted by the currentMaybeand emits the result of this function application.Maps the upstream success value into anOptionaland emits the contained item if not empty.final @NonNull Single<Notification<T>> Maps the signal types of thisMaybeinto aNotificationof the same kind and emits it as aSingle'sonSuccessvalue to downstream.merge(@NonNull MaybeSource<? extends MaybeSource<? extends @NonNull T>> source) Flattens aMaybeSourcethat emits aMaybeSourceinto a singleMaybeSourcethat emits the item emitted by the nestedMaybeSource, without any transformation.merge(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2) Flattens twoMaybeSources into a singleFlowable, without any transformation.merge(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull MaybeSource<? extends @NonNull T> source3) Flattens threeMaybeSources into a singleFlowable, without any transformation.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 fourMaybeSources into a singleFlowable, without any transformation.Merges anIterablesequence ofMaybeSourceinstances into a singleFlowablesequence, running allMaybeSources at once.merge(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Merges aFlow.Publishersequence ofMaybeSourceinstances into a singleFlowablesequence, running allMaybeSources at once.merge(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency) Merges aFlow.Publishersequence ofMaybeSourceinstances into a singleFlowablesequence, running at most maxConcurrencyMaybeSources at once.mergeArray(MaybeSource<? extends @NonNull T>... sources) Merges an array ofMaybeSourceinstances into a singleFlowablesequence, running allMaybeSources at once.mergeArrayDelayError(@NonNull MaybeSource<? extends @NonNull T>... sources) Flattens an array ofMaybeSources into oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceMaybeSources without being interrupted by an error notification from one of them.mergeDelayError(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2) Flattens twoMaybeSources into oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceMaybeSources without being interrupted by an error notification from one of them.mergeDelayError(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull MaybeSource<? extends @NonNull T> source3) Flattens threeMaybeSourceinto oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSources without being interrupted by an error notification from one of them.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 fourMaybeSources into oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSources without being interrupted by an error notification from one of them.mergeDelayError(@NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Flattens anIterablesequence ofMaybeSources into oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceMaybeSources without being interrupted by an error notification from one of them.mergeDelayError(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Flattens aFlow.Publisherthat emitsMaybeSources into oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSources without being interrupted by an error notification from one of them or even the mainPublisher.mergeDelayError(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency) Flattens aFlow.Publisherthat emitsMaybeSources into oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSources without being interrupted by an error notification from one of them or even the mainPublisheras well as limiting the total number of activeMaybeSources.mergeWith(@NonNull MaybeSource<? extends @NonNull T> other) never()Returns aMaybethat never sends any items or notifications to aMaybeObserver.Wraps aMaybeto emit its item (or notify of its error) on a specifiedScheduler, asynchronously.Filters the items emitted by the currentMaybe, only emitting its success value if that is an instance of the suppliedClass.Returns aMaybeinstance that if thisMaybeemits an error, it will emit anonCompleteand swallow the throwable.onErrorComplete(@NonNull Predicate<? super Throwable> predicate) Returns aMaybeinstance that if thisMaybeemits an error and the predicate returnstrue, it will emit anonCompleteand swallow the throwable.onErrorResumeNext(@NonNull Function<? super Throwable, ? extends MaybeSource<? extends @NonNull T>> fallbackSupplier) Resumes the flow with aMaybeSourcereturned for the failureThrowableof the currentMaybeby a function instead of signaling the error viaonError.onErrorResumeWith(@NonNull MaybeSource<? extends @NonNull T> fallback) Resumes the flow with the givenMaybeSourcewhen the currentMaybefails instead of signaling the error viaonError.Ends the flow with a success item returned by a function for theThrowableerror signaled by the currentMaybeinstead of signaling the error viaonError.onErrorReturnItem(@NonNull T item) Ends the flow with the given success item when the currentMaybefails instead of signaling the error viaonError.Nulls out references to the upstream producer and downstreamMaybeObserverif the sequence is terminated or downstream callsdispose().repeat()Returns aFlowablethat repeats the sequence of items emitted by the currentMaybeindefinitely.repeat(long times) Returns aFlowablethat repeats the sequence of items emitted by the currentMaybeat mostcounttimes.Returns aFlowablethat repeats the sequence of items emitted by the currentMaybeuntil the provided stop function returnstrue.repeatWhen(@NonNull Function<? super Flowable<Object>, @NonNull ? extends Flow.Publisher<@NonNull ?>> handler) Returns aFlowablethat emits the same values as the currentMaybewith the exception of anonComplete.retry()Returns aMaybethat mirrors the currentMaybe, resubscribing to it if it callsonError(infinite retry count).retry(long times) Returns aMaybethat mirrors the currentMaybe, resubscribing to it if it callsonErrorup to a specified number of retries.Retries at mosttimesor until the predicate returnsfalse, whichever happens first.retry(@NonNull BiPredicate<? super Integer, ? super Throwable> predicate) Returns aMaybethat mirrors the currentMaybe, resubscribing to it if it callsonErrorand the predicate returnstruefor that specific exception and retry count.Retries the currentMaybeif it fails and the predicate returnstrue.Retries until the given stop function returnstrue.retryWhen(@NonNull Function<? super Flowable<Throwable>, @NonNull ? extends Flow.Publisher<@NonNull ?>> handler) Returns aMaybethat emits the same values as the currentMaybewith the exception of anonError.final voidsafeSubscribe(@NonNull MaybeObserver<? super @NonNull T> observer) Wraps the givenMaybeObserver, catches anyRuntimeExceptions 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).sequenceEqual(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2) Returns aSinglethat emits aBooleanvalue that indicates whether twoMaybeSourcesequences are the same by comparing the items emitted by eachMaybeSourcepairwise.sequenceEqual(@NonNull MaybeSource<? extends @NonNull T> source1, @NonNull MaybeSource<? extends @NonNull T> source2, @NonNull BiPredicate<? super @NonNull T, ? super @NonNull T> isEqual) Returns aSinglethat emits aBooleanvalue that indicates whether twoMaybeSources are the same by comparing the items emitted by eachMaybeSourcepairwise based on the results of a specified equality function.startWith(@NonNull CompletableSource other) Returns aFlowablewhich first runs the otherCompletableSourcethen the currentMaybeif the other completed normally.startWith(@NonNull MaybeSource<@NonNull T> other) Returns aFlowablewhich first runs the otherMaybeSourcethen the currentMaybeif the other succeeded or completed normally.final @NonNull Observable<T> startWith(@NonNull ObservableSource<@NonNull T> other) Returns anObservablewhich first delivers the events of the otherObservableSourcethen runs the currentMaybe.startWith(@NonNull SingleSource<@NonNull T> other) Returns aFlowablewhich first runs the otherSingleSourcethen the currentMaybeif the other succeeded normally.startWith(@NonNull Flow.Publisher<@NonNull T> other) Returns aFlowablewhich first delivers the events of the otherFlow.Publisherthen runs the currentMaybe.final @NonNull DisposableSubscribes to aMaybeand ignoresonSuccessandonCompleteemissions.final voidsubscribe(@NonNull MaybeObserver<? super @NonNull T> observer) Subscribes the givenMaybeObserverto thisMaybeSourceinstance.final @NonNull DisposableSubscribes to aMaybeand provides a callback to handle the items it emits.final @NonNull Disposablesubscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super Throwable> onError) Subscribes to aMaybeand provides callbacks to handle the items it emits and any error notification it issues.final @NonNull Disposablesubscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super Throwable> onError, @NonNull Action onComplete) Subscribes to aMaybeand provides callbacks to handle the items it emits and any error or completion notification it issues.final @NonNull Disposablesubscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super Throwable> onError, @NonNull Action onComplete, @NonNull DisposableContainer container) Wraps the given onXXX callbacks into aDisposableMaybeObserver, adds it to the givenDisposableContainerand ensures, that if the upstream terminates or this particularDisposableis disposed, theMaybeObserveris removed from the given composite.protected abstract voidsubscribeActual(@NonNull MaybeObserver<? super @NonNull T> observer) Implement this method in subclasses to handle the incomingMaybeObservers.subscribeOn(@NonNull Scheduler scheduler) Asynchronously subscribes subscribers to thisMaybeon the specifiedScheduler.final <@NonNull E extends MaybeObserver<? super @NonNull T>>
EsubscribeWith(@NonNull E observer) Subscribes a givenMaybeObserver(subclass) to thisMaybeand returns the givenMaybeObserveras is.switchIfEmpty(@NonNull MaybeSource<? extends @NonNull T> other) Returns aMaybethat emits the items emitted by the currentMaybeor the items of an alternateMaybeSourceif the currentMaybeis empty.switchIfEmpty(@NonNull SingleSource<? extends @NonNull T> other) Returns aSinglethat emits the items emitted by the currentMaybeor the item of an alternateSingleSourceif the currentMaybeis empty.switchOnNext(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Switches betweenMaybeSources emitted by the sourceFlow.Publisherwhenever a newMaybeSourceis emitted, disposing the previously runningMaybeSource, exposing the success items as aFlowablesequence.switchOnNextDelayError(@NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Switches betweenMaybeSources emitted by the sourceFlow.Publisherwhenever a newMaybeSourceis emitted, disposing the previously runningMaybeSource, exposing the success items as aFlowablesequence and delaying all errors from all of them until all terminate.takeUntil(@NonNull MaybeSource<@NonNull U> other) Returns aMaybethat emits the items emitted by the currentMaybeuntil a secondMaybeSourceemits an item.takeUntil(@NonNull Flow.Publisher<@NonNull U> other) Returns aMaybethat emits the item emitted by the currentMaybeuntil a secondFlow.Publisheremits an item.final @NonNull TestObserver<T> test()Creates aTestObserverand subscribes it to thisMaybe.final @NonNull TestObserver<T> test(boolean dispose) Creates aTestObserveroptionally in cancelled state, then subscribes it to thisMaybe.Measures the time (in milliseconds) between the subscription and success item emission of the currentMaybeand signals it as a tuple (Timed) success value.timeInterval(@NonNull Scheduler scheduler) Measures the time (in milliseconds) between the subscription and success item emission of the currentMaybeand signals it as a tuple (Timed) success value.timeInterval(@NonNull TimeUnit unit) Measures the time between the subscription and success item emission of the currentMaybeand signals it as a tuple (Timed) success value.timeInterval(@NonNull TimeUnit unit, @NonNull Scheduler scheduler) Measures the time between the subscription and success item emission of the currentMaybeand signals it as a tuple (Timed) success value.Returns aMaybethat mirrors the currentMaybebut applies a timeout policy for each emitted item.Returns aMaybethat mirrors the currentMaybebut applies a timeout policy for each emitted item.Returns aMaybethat mirrors the currentMaybebut applies a timeout policy for each emitted item, where this policy is governed on a specifiedScheduler.timeout(long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, @NonNull MaybeSource<? extends @NonNull T> fallback) Returns aMaybethat mirrors the currentMaybebut applies a timeout policy for each emitted item using a specifiedScheduler.timeout(@NonNull MaybeSource<@NonNull U> timeoutIndicator) If the currentMaybedidn't signal an event before thetimeoutIndicatorMaybeSourcesignals, aTimeoutExceptionis signaled instead.timeout(@NonNull MaybeSource<@NonNull U> timeoutIndicator, @NonNull MaybeSource<? extends @NonNull T> fallback) If the currentMaybedidn't signal an event before thetimeoutIndicatorMaybeSourcesignals, the currentMaybeis disposed and thefallbackMaybeSourcesubscribed to as a continuation.timeout(@NonNull Flow.Publisher<@NonNull U> timeoutIndicator) If the currentMaybesource didn't signal an event before thetimeoutIndicatorFlow.Publishersignals, aTimeoutExceptionis signaled instead.timeout(@NonNull Flow.Publisher<@NonNull U> timeoutIndicator, @NonNull MaybeSource<? extends @NonNull T> fallback) If the currentMaybedidn't signal an event before thetimeoutIndicatorFlow.Publishersignals, the currentMaybeis disposed and thefallbackMaybeSourcesubscribed to as a continuation.Returns aMaybethat emits0Lafter a specified delay.final <R> Rto(@NonNull MaybeConverter<@NonNull T, ? extends R> converter) Calls the specified converter function during assembly time and returns its resulting value.final @NonNull CompletionStage<T> Signals the upstream success item (or aNoSuchElementExceptionif the upstream is empty) via aCompletionStage.final @NonNull CompletionStage<T> toCompletionStage(@NonNull T defaultItem) Signals the upstream success item (or the default item if the upstream is empty) via aCompletionStage.Converts thisMaybeinto a backpressure-awareFlowableinstance composing cancellation through.toFuture()Returns aFuturerepresenting the single value emitted by the currentMaybeornullif the currentMaybeis empty.final @NonNull Observable<T> Converts thisMaybeinto anObservableinstance composing disposal through.toSingle()Converts thisMaybeinto aSingleinstance composing disposal through and turning an emptyMaybeinto a signal ofNoSuchElementException.unsafeCreate(@NonNull MaybeSource<@NonNull T> onSubscribe) Advanced use only: creates aMaybeinstance without any safeguards by using a callback that is called with aMaybeObserver.unsubscribeOn(@NonNull Scheduler scheduler) Returns aMaybewhich makes sure when aMaybeObserverdisposes theDisposable, that call is propagated up on the specifiedScheduler.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 aMaybethat creates a dependent resource object which is disposed of when the generatedMaybeSourceterminates or the downstream calls dispose().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 aMaybethat creates a dependent resource object which is disposed first ({code eager == true}) when the generatedMaybeSourceterminates or the downstream disposes; or after ({code eager == false}).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 aMaybethat emits the results of a specified combiner function applied to combinations of nine items emitted, in sequence, by nine otherMaybeSources.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 aMaybethat emits the results of a specified combiner function applied to combinations of eight items emitted, in sequence, by eight otherMaybeSources.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 aMaybethat emits the results of a specified combiner function applied to combinations of seven items emitted, in sequence, by seven otherMaybeSources.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 aMaybethat emits the results of a specified combiner function applied to combinations of six items emitted, in sequence, by six otherMaybeSources.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 aMaybethat emits the results of a specified combiner function applied to combinations of five items emitted, in sequence, by five otherMaybeSources.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 aMaybethat emits the results of a specified combiner function applied to combinations of four items emitted, in sequence, by four otherMaybeSources.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 aMaybethat emits the results of a specified combiner function applied to combinations of three items emitted, in sequence, by three otherMaybeSources.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 aMaybethat emits the results of a specified combiner function applied to combinations of two items emitted, in sequence, by two otherMaybeSources.zip(@NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, @NonNull Function<? super Object[], ? extends @NonNull R> zipper) Returns aMaybethat emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by anIterableof otherMaybeSources.zipArray(@NonNull Function<? super Object[], ? extends @NonNull R> zipper, @NonNull MaybeSource<? extends @NonNull T>... sources) Returns aMaybethat emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by an array of otherMaybeSources.zipWith(@NonNull MaybeSource<? extends @NonNull U> other, @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> zipper) Waits until this and the otherMaybeSourcesignal a success value then applies the givenBiFunctionto those values and emits theBiFunction's resulting value to downstream.
-
Constructor Details
-
Maybe
public Maybe()
-
-
Method Details
-
amb
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> amb(@NonNull @NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Runs multipleMaybeSources provided by anIterablesequence and signals the events of the first one that signals (disposing the rest).
- Scheduler:
ambdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
sources- theIterablesequence of sources. A subscription to each source will occur in the same order as in theIterable.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsourcesisnull
-
ambArray
@CheckReturnValue @SchedulerSupport("none") @NonNull @SafeVarargs public static <@NonNull T> @NonNull Maybe<T> ambArray(@NonNull @NonNull MaybeSource<? extends @NonNull T>... sources) Runs multipleMaybeSources and signals the events of the first one that signals (disposing the rest).
- Scheduler:
ambArraydoes 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
Maybeinstance - Throws:
NullPointerException- ifsourcesisnull
-
concat
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenate the single values, in a non-overlapping fashion, of theMaybeSourcesources provided by anIterablesequence as aFlowablesequence.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
sources- theIterablesequence ofMaybeSourceinstances- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull
-
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 aFlowablethat emits the items emitted by twoMaybeSources, one after the other.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
source1- aMaybeSourceto be concatenatedsource2- aMaybeSourceto be concatenated- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsource1orsource2isnull- See Also:
-
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 aFlowablethat emits the items emitted by threeMaybeSources, one after the other.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
source1- aMaybeSourceto be concatenatedsource2- aMaybeSourceto be concatenatedsource3- aMaybeSourceto be concatenated- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsource1,source2orsource3isnull- See Also:
-
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 aFlowablethat emits the items emitted by fourMaybeSources, one after the other.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
source1- aMaybeSourceto be concatenatedsource2- aMaybeSourceto be concatenatedsource3- aMaybeSourceto be concatenatedsource4- aMaybeSourceto be concatenated- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsource1,source2,source3orsource4isnull- See Also:
-
concat
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenate the single values, in a non-overlapping fashion, of theMaybeSourcesources provided by aFlow.Publishersequence as aFlowablesequence.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer and expects thePublisherto honor backpressure as well. If the sourcesPublisherviolates this, aMissingBackpressureExceptionis signaled. - Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
sources- thePublisherofMaybeSourceinstances- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull
-
concat
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int prefetch) Concatenate the single values, in a non-overlapping fashion, of theMaybeSourcesources provided by aFlow.Publishersequence as aFlowablesequence.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer and expects thePublisherto honor backpressure as well. If the sourcesPublisherviolates this, aMissingBackpressureExceptionis signaled. - Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
sources- thePublisherofMaybeSourceinstancesprefetch- the number ofMaybeSources to prefetch from thePublisher- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifprefetchis 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 theMaybeSourcesources in the array as aFlowablesequence.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
concatArraydoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
sources- the array ofMaybeSourceinstances- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull
-
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 ofMaybeSourcesources and delays errors from any of them till all terminate as aFlowablesequence.
- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
concatArrayDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common base value type- Parameters:
sources- the array of sources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull
-
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 ofMaybeSourceeagerly into aFlowablesequence.Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source
MaybeSources. The operator buffers the value emitted by theseMaybeSources 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 ofMaybeSources that need to be eagerly concatenated- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull
-
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 ofMaybeSourceeagerly into aFlowablesequence.Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source
MaybeSources. The operator buffers the value emitted by theseMaybeSources 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 ofMaybeSources that need to be eagerly concatenated- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
-
concatDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatDelayError(@NonNull @NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenates theIterablesequence ofMaybeSources into a single sequence by subscribing to eachMaybeSource, one after the other, one at a time and delays any errors till the all innerMaybeSources terminate as aFlowablesequence.
- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
concatDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- theIterablesequence ofMaybeSources- Returns:
- the new
Flowablewith the concatenating behavior - Throws:
NullPointerException- ifsourcesisnull
-
concatDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatDelayError(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenates theFlow.Publishersequence ofMaybeSources 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 outerPublisherterminate as aFlowablesequence.
- Backpressure:
concatDelayErrorfully supports backpressure.- Scheduler:
concatDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- thePublishersequence ofMaybeSources- Returns:
- the new
Flowablewith the concatenating behavior - Throws:
NullPointerException- ifsourcesisnull
-
concatDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatDelayError(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int prefetch) Concatenates theFlow.Publishersequence ofMaybeSources 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 outerPublisherterminate as aFlowablesequence.
- Backpressure:
concatDelayErrorfully supports backpressure.- Scheduler:
concatDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- thePublishersequence ofMaybeSourcesprefetch- The number of upstream items to prefetch so that fresh items are ready to be mapped when a previousMaybeSourceterminates. The operator replenishes after half of the prefetch amount has been consumed and turned intoMaybeSources.- Returns:
- the new
Flowablewith the concatenating behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifprefetchis non-positive- Since:
- 3.0.0
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenates a sequence ofMaybeSources eagerly into aFlowablesequence.
Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source
MaybeSources. The operator buffers the values emitted by theseMaybeSources 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 ofMaybeSourcethat need to be eagerly concatenated- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency) Concatenates a sequence ofMaybeSources eagerly into aFlowablesequence 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
MaybeSources. The operator buffers the values emitted by theseMaybeSources 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 ofMaybeSourcethat need to be eagerly concatenatedmaxConcurrency- the maximum number of concurrently running innerMaybeSources;Integer.MAX_VALUEis interpreted as all innerMaybeSources can be active at the same time- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 3.0.0
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenates aFlow.Publishersequence ofMaybeSources eagerly into aFlowablesequence.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source
MaybeSources as they are observed. The operator buffers the values emitted by theseMaybeSources and then drains them in order, each one after the previous one completes.
- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisheris 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 ofMaybeSources that need to be eagerly concatenated- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency) Concatenates aFlow.Publishersequence ofMaybeSources eagerly into aFlowablesequence, running at most the given number of innerMaybeSources at once.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source
MaybeSources as they are observed. The operator buffers the values emitted by theseMaybeSources and then drains them in order, each one after the previous one completes.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisheris 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 ofMaybeSources that need to be eagerly concatenatedmaxConcurrency- the maximum number of concurrently running innerMaybeSources;Integer.MAX_VALUEis interpreted as all innerMaybeSources can be active at the same time- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenates a sequence ofMaybeSources eagerly into aFlowablesequence, delaying errors until all innerMaybeSources terminate.
Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source
MaybeSources. The operator buffers the values emitted by theseMaybeSources 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 ofMaybeSourcethat need to be eagerly concatenated- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency) Concatenates a sequence ofMaybeSources eagerly into aFlowablesequence, delaying errors until all innerMaybeSources terminate and runs a limited number of innerMaybeSources at once.
Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source
MaybeSources. The operator buffers the values emitted by theseMaybeSources 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 ofMaybeSourcethat need to be eagerly concatenatedmaxConcurrency- the maximum number of concurrently running innerMaybeSources;Integer.MAX_VALUEis interpreted as all innerMaybeSources can be active at the same time- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Concatenates aFlow.Publishersequence ofMaybeSources eagerly into aFlowablesequence, 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
MaybeSources as they are observed. The operator buffers the values emitted by theseMaybeSources and then drains them in order, each one after the previous one completes.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisheris 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 ofMaybeSources that need to be eagerly concatenated- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency) Concatenates aFlow.Publishersequence ofMaybeSources eagerly into aFlowablesequence, delaying errors until all the inner and the outer sequence terminate and runs a limited number of the innerMaybeSources at once.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source
MaybeSources as they are observed. The operator buffers the values emitted by theseMaybeSources and then drains them in order, each one after the previous one completes.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisheris 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 ofMaybeSources that need to be eagerly concatenatedmaxConcurrency- the maximum number of concurrently running innerMaybeSources;Integer.MAX_VALUEis interpreted as all innerMaybeSources can be active at the same time- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis 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
MaybeObserversubscribes to the returnedMaybe, the providedMaybeOnSubscribecallback is invoked with a fresh instance of aMaybeEmitterthat will interact only with that specificMaybeObserver. If thisMaybeObserverdisposes the flow (makingMaybeEmitter.isDisposed()returntrue), other observers subscribed to the same returnedMaybeare not affected.- Scheduler:
createdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
onSubscribe- the emitter that is called when aMaybeObserversubscribes to the returnedMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifonSubscribeisnull- See Also:
-
defer
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> defer(@NonNull @NonNull Supplier<? extends @NonNull MaybeSource<? extends @NonNull T>> supplier) Calls aSupplierfor each individualMaybeObserverto return the actualMaybeSourcesource to be subscribed to.
- Scheduler:
deferdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
supplier- theSupplierthat is called for each individualMaybeObserverand returns aMaybeSourceinstance to subscribe to- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsupplierisnull
-
empty
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Maybe<T> empty()Returns a (singleton)Maybeinstance that callsonCompleteimmediately.
- Scheduler:
emptydoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Returns:
- the shared
Maybeinstance
-
error
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> error(@NonNull @NonNull Throwable throwable) Returns aMaybethat invokes a subscriber'sonErrormethod when the subscriber subscribes to it.
- Scheduler:
errordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of the item (ostensibly) emitted by theMaybe- Parameters:
throwable- the particularThrowableto pass toonError- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifthrowableisnull- See Also:
-
error
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> error(@NonNull @NonNull Supplier<? extends @NonNull Throwable> supplier) Returns aMaybethat invokes aMaybeObserver'sonErrormethod when theMaybeObserversubscribes to it.
- Scheduler:
errordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of the items (ostensibly) emitted by theMaybe- Parameters:
supplier- aSupplierfactory to return aThrowablefor each individualMaybeObserver- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsupplierisnull- See Also:
-
fromAction
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromAction(@NonNull @NonNull Action action) Returns aMaybeinstance that runs the givenActionfor eachMaybeObserverand emits either its exception or simply completes.
- Scheduler:
fromActiondoes not operate by default on a particularScheduler.- Error handling:
- If the
Actionthrows an exception, the respectiveThrowableis delivered to the downstream viaMaybeObserver.onError(Throwable), except when the downstream has disposed the resultingMaybesource. In this latter case, theThrowableis delivered to the global error handler viaRxJavaPlugins.onError(Throwable)as anUndeliverableException.
- Type Parameters:
T- the target type- Parameters:
action- theActionto run for eachMaybeObserver- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifactionisnull
-
fromCompletable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromCompletable(@NonNull @NonNull CompletableSource completableSource) Wraps aCompletableSourceinto aMaybe.
- Scheduler:
fromCompletabledoes not operate by default on a particularScheduler.
- Type Parameters:
T- the target type- Parameters:
completableSource- theCompletableSourceto convert from- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifcompletableSourceisnull
-
fromSingle
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromSingle(@NonNull @NonNull SingleSource<@NonNull T> single) Wraps aSingleSourceinto aMaybe.
- Scheduler:
fromSingledoes not operate by default on a particularScheduler.
- Type Parameters:
T- the target type- Parameters:
single- theSingleSourceto convert from- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsingleisnull
-
fromCallable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <T> @NonNull Maybe<@NonNull T> fromCallable(@NonNull @NonNull Callable<? extends @Nullable T> callable) Returns aMaybethat invokes the givenCallablefor each individualMaybeObserverthat subscribes and emits the resulting non-nullitem viaonSuccesswhile considering anullresult from theCallableas indication for valueless completion viaonComplete.
This operator allows you to defer the execution of the given
Callableuntil aMaybeObserversubscribes to the returnedMaybe. In other terms, this source operator evaluates the givenCallable"lazily".Note that the
nullhandling of this operator differs from the similar source operators in the otherbase reactive classes. Those operators signal aNullPointerExceptionif the value returned by theirCallableisnullwhile thisfromCallableconsiders it to indicate the returnedMaybeis empty.- Scheduler:
fromCallabledoes not operate by default on a particularScheduler.- Error handling:
- Any non-fatal exception thrown by
Callable.call()will be forwarded toonError, except if theMaybeObserverdisposed 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- aCallableinstance whose execution should be deferred and performed for each individualMaybeObserverthat subscribes to the returnedMaybe.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifcallableisnull- See Also:
-
fromFuture
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromFuture(@NonNull @NonNull Future<? extends @NonNull T> future) Converts aFutureinto aMaybe, treating anullresult 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 theSchedulersupports it, interrupt the wait when the flow is disposed.Unlike 1.x, disposing the
Maybewon't cancel the future. If necessary, one can use composition to achieve the cancellation effect:futureMaybe.doOnDispose(() -> future.cancel(true));.- Scheduler:
fromFuturedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of object that theFuturereturns, and also the type of item to be emitted by the resultingMaybe- Parameters:
future- the sourceFuture- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- iffutureisnull- See Also:
-
fromFuture
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromFuture(@NonNull @NonNull Future<? extends @NonNull T> future, long timeout, @NonNull @NonNull TimeUnit unit) Converts aFutureinto 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 theSchedulersupports it, interrupt the wait when the flow is disposed.Unlike 1.x, disposing the
Maybewon't cancel the future. If necessary, one can use composition to achieve the cancellation effect:futureMaybe.doOnCancel(() -> future.cancel(true));.- Scheduler:
fromFuturedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of object that theFuturereturns, and also the type of item to be emitted by the resultingMaybe- Parameters:
future- the sourceFuturetimeout- the maximum time to wait before callinggetunit- theTimeUnitof thetimeoutargument- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- iffutureorunitisnull- See Also:
-
fromObservable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromObservable(@NonNull @NonNull ObservableSource<@NonNull T> source) Wraps anObservableSourceinto aMaybeand emits the very first item or completes if the source is empty.
- Scheduler:
fromObservabledoes not operate by default on a particularScheduler.
- Type Parameters:
T- the target type- Parameters:
source- theObservableSourceto convert from- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsourceisnull- Since:
- 3.0.0
-
fromPublisher
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(UNBOUNDED_IN) public static <@NonNull T> @NonNull Maybe<T> fromPublisher(@NonNull @NonNull Flow.Publisher<@NonNull T> source) Wraps aFlow.Publisherinto aMaybeand emits the very first item or completes if the source is empty.
- Backpressure:
- The operator consumes the given
Publisherin an unbounded manner (requestingLong.MAX_VALUE) but cancels it after one item received. - Scheduler:
fromPublisherdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the target type- Parameters:
source- thePublisherto convert from- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsourceisnull- Since:
- 3.0.0
-
fromRunnable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> fromRunnable(@NonNull @NonNull Runnable run) Returns aMaybeinstance that runs the givenRunnablefor eachMaybeObserverand emits either its unchecked exception or simply completes.
If the code to be wrapped needs to throw a checked or more broader
Throwableexception, 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 anyThrowableexception and will signal it to observers as-is.- Scheduler:
fromRunnabledoes not operate by default on a particularScheduler.- Error handling:
- If the
Runnablethrows an exception, the respectiveThrowableis delivered to the downstream viaMaybeObserver.onError(Throwable), except when the downstream has disposed thisMaybesource. In this latter case, theThrowableis delivered to the global error handler viaRxJavaPlugins.onError(Throwable)as anUndeliverableException.
- Type Parameters:
T- the target type- Parameters:
run- theRunnableto run for eachMaybeObserver- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifrunisnull- See Also:
-
fromSupplier
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <T> @NonNull Maybe<@NonNull T> fromSupplier(@NonNull @NonNull Supplier<? extends @Nullable T> supplier) Returns aMaybethat invokes the givenSupplierfor each individualMaybeObserverthat subscribes and emits the resulting non-nullitem viaonSuccesswhile considering anullresult from theSupplieras indication for valueless completion viaonComplete.This operator allows you to defer the execution of the given
Supplieruntil aMaybeObserversubscribes to the returnedMaybe. In other terms, this source operator evaluates the givenSupplier"lazily".
Note that the
nullhandling of this operator differs from the similar source operators in the otherbase reactive classes. Those operators signal aNullPointerExceptionif the value returned by theirSupplierisnullwhile thisfromSupplierconsiders it to indicate the returnedMaybeis empty.- Scheduler:
fromSupplierdoes not operate by default on a particularScheduler.- Error handling:
- Any non-fatal exception thrown by
Supplier.get()will be forwarded toonError, except if theMaybeObserverdisposed 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- aSupplierinstance whose execution should be deferred and performed for each individualMaybeObserverthat subscribes to the returnedMaybe.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsupplierisnull- Since:
- 3.0.0
- See Also:
-
just
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> just(@NonNull T item) Returns aMaybethat emits a specified item.
To convert any object into a
Maybethat emits that object, pass that object into thejustmethod.- Scheduler:
justdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of that item- Parameters:
item- the item to emit- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifitemisnull- See Also:
-
merge
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Merges anIterablesequence ofMaybeSourceinstances into a singleFlowablesequence, running allMaybeSources at once.
- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the source
MaybeSources signal aThrowableviaonError, the resultingFlowableterminates with thatThrowableand all other sourceMaybeSources are disposed. If more than oneMaybeSourcesignals an error, the resultingFlowablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedFlowablehas 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 sourceMaybeSources have completed or failed with an error.
- Type Parameters:
T- the common and resulting value type- Parameters:
sources- theIterablesequence ofMaybeSourcesources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
merge
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Merges aFlow.Publishersequence ofMaybeSourceinstances into a singleFlowablesequence, running allMaybeSources at once.
- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the source
MaybeSources signal aThrowableviaonError, the resultingFlowableterminates with thatThrowableand all other sourceMaybeSources are disposed. If more than oneMaybeSourcesignals an error, the resultingFlowablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedFlowablehas 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 sourceMaybeSources have completed or failed with an error.
- Type Parameters:
T- the common and resulting value type- Parameters:
sources- theFlowablesequence ofMaybeSourcesources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
merge
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency) Merges aFlow.Publishersequence ofMaybeSourceinstances into a singleFlowablesequence, running at most maxConcurrencyMaybeSources at once.
- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the source
MaybeSources signal aThrowableviaonError, the resultingFlowableterminates with thatThrowableand all other sourceMaybeSources are disposed. If more than oneMaybeSourcesignals an error, the resultingFlowablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedFlowablehas 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 sourceMaybeSources have completed or failed with an error.
- Type Parameters:
T- the common and resulting value type- Parameters:
sources- theFlowablesequence ofMaybeSourcesourcesmaxConcurrency- the maximum number of concurrently runningMaybeSources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- See Also:
-
merge
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> merge(@NonNull @NonNull MaybeSource<? extends MaybeSource<? extends @NonNull T>> source) Flattens aMaybeSourcethat emits aMaybeSourceinto a singleMaybeSourcethat emits the item emitted by the nestedMaybeSource, without any transformation.
- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- The resulting
Maybeemits the outer source's or the innerMaybeSource'sThrowableas is. Unlike the othermerge()operators, this operator won't and can't produce aCompositeExceptionbecause there is only one possibility for the outer or the innerMaybeSourceto emit anonErrorsignal. 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- aMaybeSourcethat emits aMaybeSource- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsourceisnull- See Also:
-
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 twoMaybeSources into a singleFlowable, without any transformation.
You can combine items emitted by multiple
MaybeSources so that they appear as a singleFlowable, by using themergemethod.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the source
MaybeSources signal aThrowableviaonError, the resultingFlowableterminates with thatThrowableand all other sourceMaybeSources are disposed. If more than oneMaybeSourcesignals an error, the resultingFlowablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedFlowablehas 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 sourceMaybeSources have completed or failed with an error.
- Type Parameters:
T- the common value type- Parameters:
source1- aMaybeSourceto be mergedsource2- aMaybeSourceto be merged- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsource1orsource2isnull- See Also:
-
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 threeMaybeSources into a singleFlowable, without any transformation.
You can combine items emitted by multiple
MaybeSources so that they appear as a singleFlowable, by using themergemethod.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the source
MaybeSources signal aThrowableviaonError, the resultingFlowableterminates with thatThrowableand all other sourceMaybeSources are disposed. If more than oneMaybeSourcesignals an error, the resultingFlowablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedFlowablehas 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 sourceMaybeSources have completed or failed with an error.
- Type Parameters:
T- the common value type- Parameters:
source1- aMaybeSourceto be mergedsource2- aMaybeSourceto be mergedsource3- aMaybeSourceto be merged- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsource1,source2orsource3isnull- See Also:
-
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 fourMaybeSources into a singleFlowable, without any transformation.
You can combine items emitted by multiple
MaybeSources so that they appear as a singleFlowable, by using themergemethod.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the source
MaybeSources signal aThrowableviaonError, the resultingFlowableterminates with thatThrowableand all other sourceMaybeSources are disposed. If more than oneMaybeSourcesignals an error, the resultingFlowablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedFlowablehas 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 sourceMaybeSources have completed or failed with an error.
- Type Parameters:
T- the common value type- Parameters:
source1- aMaybeSourceto be mergedsource2- aMaybeSourceto be mergedsource3- aMaybeSourceto be mergedsource4- aMaybeSourceto be merged- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsource1,source2,source3orsource4isnull- See Also:
-
mergeArray
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static <@NonNull T> @NonNull Flowable<T> mergeArray(MaybeSource<? extends @NonNull T>... sources) Merges an array ofMaybeSourceinstances into a singleFlowablesequence, running allMaybeSources at once.
- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeArraydoes not operate by default on a particularScheduler.- Error handling:
- If any of the source
MaybeSources signal aThrowableviaonError, the resultingFlowableterminates with thatThrowableand all other sourceMaybeSources are disposed. If more than oneMaybeSourcesignals an error, the resultingFlowablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedFlowablehas 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 sourceMaybeSources have completed or failed with an error.
- Type Parameters:
T- the common and resulting value type- Parameters:
sources- the array sequence ofMaybeSourcesources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
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 ofMaybeSources into oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceMaybeSources without being interrupted by an error notification from one of them.
This behaves like
merge(Publisher)except that if any of the mergedMaybeSources notify of an error viaonError,mergeArrayDelayErrorwill refrain from propagating that error notification until all of the mergedMaybeSources have finished emitting items.Even if multiple merged
MaybeSources sendonErrornotifications,mergeArrayDelayErrorwill only invoke theonErrormethod of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeArrayDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- the array ofMaybeSources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
mergeDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Flattens anIterablesequence ofMaybeSources into oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceMaybeSources without being interrupted by an error notification from one of them.
This behaves like
merge(Publisher)except that if any of the mergedMaybeSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedMaybeSources have finished emitting items.
Even if multiple merged
MaybeSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- theIterableofMaybeSources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
mergeDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Flattens aFlow.Publisherthat emitsMaybeSources into oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSources 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 mergedMaybeSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedMaybeSources and the mainPublisherhave finished emitting items.Even if multiple merged
MaybeSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream. The outer
Publisheris consumed in unbounded mode (i.e., no backpressure is applied to it). - Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- aPublisherthat emitsMaybeSources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
mergeDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, int maxConcurrency) Flattens aFlow.Publisherthat emitsMaybeSources into oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSources without being interrupted by an error notification from one of them or even the mainPublisheras well as limiting the total number of activeMaybeSources.
This behaves like
merge(Publisher, int)except that if any of the mergedMaybeSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedMaybeSources and the mainPublisherhave finished emitting items.Even if multiple merged
MaybeSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream. The outer
Publisheris consumed in unbounded mode (i.e., no backpressure is applied to it). - Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.9 - experimental
- Type Parameters:
T- the common element base type- Parameters:
sources- aPublisherthat emitsMaybeSourcesmaxConcurrency- the maximum number of active innerMaybeSources to be merged at a time- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 2.2
- See Also:
-
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 twoMaybeSources into oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceMaybeSources without being interrupted by an error notification from one of them.
This behaves like
merge(MaybeSource, MaybeSource)except that if any of the mergedMaybeSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedMaybeSources have finished emitting items.Even if both merged
MaybeSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
source1- aMaybeSourceto be mergedsource2- aMaybeSourceto be merged- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsource1orsource2isnull- See Also:
-
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 threeMaybeSourceinto oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSources without being interrupted by an error notification from one of them.
This behaves like
merge(MaybeSource, MaybeSource, MaybeSource)except that if any of the mergedMaybeSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedMaybeSources have finished emitting items.Even if multiple merged
MaybeSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
source1- aMaybeSourceto be mergedsource2- aMaybeSourceto be mergedsource3- aMaybeSourceto be merged- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsource1,source2orsource3isnull- See Also:
-
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 fourMaybeSources into oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from all of the sourceMaybeSources 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 mergedMaybeSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedMaybeSources have finished emitting items.Even if multiple merged
MaybeSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
source1- aMaybeSourceto be mergedsource2- aMaybeSourceto be mergedsource3- aMaybeSourceto be mergedsource4- aMaybeSourceto be merged- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsource1,source2,source3orsource4isnull- See Also:
-
never
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Maybe<T> never()Returns aMaybethat never sends any items or notifications to aMaybeObserver.
This
Maybeis useful primarily for testing purposes.- Scheduler:
neverdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of items (not) emitted by theMaybe- Returns:
- the shared
Maybeinstance - See Also:
-
sequenceEqual
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<Boolean> sequenceEqual(@NonNull @NonNull MaybeSource<? extends @NonNull T> source1, @NonNull @NonNull MaybeSource<? extends @NonNull T> source2) Returns aSinglethat emits aBooleanvalue that indicates whether twoMaybeSourcesequences are the same by comparing the items emitted by eachMaybeSourcepairwise.
- Scheduler:
sequenceEqualdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of items emitted by eachMaybeSource- Parameters:
source1- the firstMaybeSourceto comparesource2- the secondMaybeSourceto compare- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsource1orsource2isnull- See Also:
-
sequenceEqual
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<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 aSinglethat emits aBooleanvalue that indicates whether twoMaybeSources are the same by comparing the items emitted by eachMaybeSourcepairwise based on the results of a specified equality function.
- Scheduler:
sequenceEqualdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of items emitted by eachMaybeSource- Parameters:
source1- the firstMaybeSourceto comparesource2- the secondMaybeSourceto compareisEqual- a function used to compare items emitted by eachMaybeSource- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsource1,source2orisEqualisnull- See Also:
-
switchOnNext
@BackpressureSupport(UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> switchOnNext(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Switches betweenMaybeSources emitted by the sourceFlow.Publisherwhenever a newMaybeSourceis emitted, disposing the previously runningMaybeSource, exposing the success items as aFlowablesequence.
- Backpressure:
- The
sourcesPublisheris consumed in an unbounded manner (requestingLong.MAX_VALUE). The returnedFlowablerespects the backpressure from the downstream. - Scheduler:
switchOnNextdoes not operate by default on a particularScheduler.- Error handling:
- The returned sequence fails with the first error signaled by the
sourcesPublisheror 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 theMaybeSources- Parameters:
sources- thePublishersequence of innerMaybeSources to switch between- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
- See Also:
-
switchOnNextDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> switchOnNextDelayError(@NonNull @NonNull Flow.Publisher<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources) Switches betweenMaybeSources emitted by the sourceFlow.Publisherwhenever a newMaybeSourceis emitted, disposing the previously runningMaybeSource, exposing the success items as aFlowablesequence and delaying all errors from all of them until all terminate.
- Backpressure:
- The
sourcesPublisheris consumed in an unbounded manner (requestingLong.MAX_VALUE). The returnedFlowablerespects the backpressure from the downstream. - Scheduler:
switchOnNextDelayErrordoes not operate by default on a particularScheduler.- Error handling:
- The returned
Flowablecollects all errors emitted by either thesourcesPublisheror any innerMaybeSourceand emits them as aCompositeExceptionwhen 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 theMaybeSources- Parameters:
sources- thePublishersequence of innerMaybeSources to switch between- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
- See Also:
-
timer
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public static @NonNull Maybe<Long> timer(long delay, @NonNull @NonNull TimeUnit unit) Returns aMaybethat emits0Lafter a specified delay.
- Scheduler:
timeroperates by default on thecomputationScheduler.
- Parameters:
delay- the initial delay before emitting a single0Lunit- time units to use fordelay- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
timer
@CheckReturnValue @NonNull @SchedulerSupport("custom") public static @NonNull Maybe<Long> timer(long delay, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns aMaybethat emits0Lafter a specified delay on a specifiedScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
delay- the initial delay before emitting a single 0Lunit- time units to use fordelayscheduler- theSchedulerto use for scheduling the item- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
unsafeCreate
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> unsafeCreate(@NonNull @NonNull MaybeSource<@NonNull T> onSubscribe) Advanced use only: creates aMaybeinstance without any safeguards by using a callback that is called with aMaybeObserver.
- Scheduler:
unsafeCreatedoes 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
Maybeinstance - Throws:
IllegalArgumentException- ifonSubscribeis aMaybeNullPointerException- ifonSubscribeisnull
-
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 aMaybethat creates a dependent resource object which is disposed of when the generatedMaybeSourceterminates or the downstream calls dispose().
- Scheduler:
usingdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the element type of the generatedMaybeSourceD- the type of the resource associated with the output sequence- Parameters:
resourceSupplier- the factory function to create a resource object that depends on theMaybesourceSupplier- the factory function to create aMaybeSourceresourceCleanup- the function that will dispose of the resource- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifresourceSupplier,sourceSupplierorresourceCleanupisnull- See Also:
-
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 aMaybethat creates a dependent resource object which is disposed first ({code eager == true}) when the generatedMaybeSourceterminates or the downstream disposes; or after ({code eager == false}).
Eager disposal is particularly appropriate for a synchronous
Maybethat reuses resources.disposeActionwill only be called once per subscription.- Scheduler:
usingdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the element type of the generatedMaybeSourceD- the type of the resource associated with the output sequence- Parameters:
resourceSupplier- the factory function to create a resource object that depends on theMaybesourceSupplier- the factory function to create aMaybeSourceresourceCleanup- the function that will dispose of the resourceeager- Iftruethen resource disposal will happen either on adispose()call before the upstream is disposed or just before the emission of a terminal event (onSuccess,onCompleteoronError). Iffalsethe resource disposal will happen either on adispose()call after the upstream is disposed or just after the emission of a terminal event (onSuccess,onCompleteoronError).- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifresourceSupplier,sourceSupplierorresourceCleanupisnull- See Also:
-
wrap
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Maybe<T> wrap(@NonNull @NonNull MaybeSource<@NonNull T> source) Wraps aMaybeSourceinstance into a newMaybeinstance if not already aMaybeinstance.
- Scheduler:
wrapdoes 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
Maybeinstance - Throws:
NullPointerException- ifsourceisnull
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T, @NonNull R> @NonNull Maybe<R> zip(@NonNull @NonNull Iterable<@NonNull ? extends MaybeSource<? extends @NonNull T>> sources, @NonNull @NonNull Function<? super Object[], ? extends @NonNull R> zipper) Returns aMaybethat emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by anIterableof otherMaybeSources.
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
MaybeSources signal anonErrororonComplete. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value typeR- the zipped result type- Parameters:
sources- anIterableof sourceMaybeSourceszipper- a function that, when applied to an item emitted by each of the sourceMaybeSources, results in an item that will be emitted by the resultingMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifzipperorsourcesisnull- See Also:
-
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 aMaybethat emits the results of a specified combiner function applied to combinations of two items emitted, in sequence, by two otherMaybeSources.
This operator terminates eagerly if any of the source
MaybeSources signal anonErrororonComplete. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zipdoes 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 sourceMaybeSourcesource2- a second sourceMaybeSourcezipper- a function that, when applied to an item emitted by each of the sourceMaybeSources, results in an item that will be emitted by the resultingMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsource1,source2orzipperisnull- See Also:
-
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 aMaybethat emits the results of a specified combiner function applied to combinations of three items emitted, in sequence, by three otherMaybeSources.
This operator terminates eagerly if any of the source
MaybeSources signal anonErrororonComplete. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zipdoes 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 sourceMaybeSourcesource2- a second sourceMaybeSourcesource3- a third sourceMaybeSourcezipper- a function that, when applied to an item emitted by each of the sourceMaybeSources, results in an item that will be emitted by the resultingMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsource1,source2,source3orzipperisnull- See Also:
-
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 aMaybethat emits the results of a specified combiner function applied to combinations of four items emitted, in sequence, by four otherMaybeSources.
This operator terminates eagerly if any of the source
MaybeSources signal anonErrororonComplete. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zipdoes 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 sourceMaybeSourcesource2- a second sourceMaybeSourcesource3- a third sourceMaybeSourcesource4- a fourth sourceMaybeSourcezipper- a function that, when applied to an item emitted by each of the sourceMaybeSources, results in an item that will be emitted by the resultingMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4orzipperisnull- See Also:
-
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 aMaybethat emits the results of a specified combiner function applied to combinations of five items emitted, in sequence, by five otherMaybeSources.
This operator terminates eagerly if any of the source
MaybeSources signal anonErrororonComplete. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zipdoes 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 sourceMaybeSourcesource2- a second sourceMaybeSourcesource3- a third sourceMaybeSourcesource4- a fourth sourceMaybeSourcesource5- a fifth sourceMaybeSourcezipper- a function that, when applied to an item emitted by each of the sourceMaybeSources, results in an item that will be emitted by the resultingMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5orzipperisnull- See Also:
-
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 aMaybethat emits the results of a specified combiner function applied to combinations of six items emitted, in sequence, by six otherMaybeSources.
This operator terminates eagerly if any of the source
MaybeSources signal anonErrororonComplete. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zipdoes 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 sourceMaybeSourcesource2- a second sourceMaybeSourcesource3- a third sourceMaybeSourcesource4- a fourth sourceMaybeSourcesource5- a fifth sourceMaybeSourcesource6- a sixth sourceMaybeSourcezipper- a function that, when applied to an item emitted by each of the sourceMaybeSources, results in an item that will be emitted by the resultingMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5,source6orzipperisnull- See Also:
-
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 aMaybethat emits the results of a specified combiner function applied to combinations of seven items emitted, in sequence, by seven otherMaybeSources.
This operator terminates eagerly if any of the source
MaybeSources signal anonErrororonComplete. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zipdoes 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 sourceMaybeSourcesource2- a second sourceMaybeSourcesource3- a third sourceMaybeSourcesource4- a fourth sourceMaybeSourcesource5- a fifth sourceMaybeSourcesource6- a sixth sourceMaybeSourcesource7- a seventh sourceMaybeSourcezipper- a function that, when applied to an item emitted by each of the sourceMaybeSources, results in an item that will be emitted by the resultingMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5,source6,source7orzipperisnull- See Also:
-
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 aMaybethat emits the results of a specified combiner function applied to combinations of eight items emitted, in sequence, by eight otherMaybeSources.
This operator terminates eagerly if any of the source
MaybeSources signal anonErrororonComplete. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zipdoes 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 sourceMaybeSourcesource2- a second sourceMaybeSourcesource3- a third sourceMaybeSourcesource4- a fourth sourceMaybeSourcesource5- a fifth sourceMaybeSourcesource6- a sixth sourceMaybeSourcesource7- a seventh sourceMaybeSourcesource8- an eighth sourceMaybeSourcezipper- a function that, when applied to an item emitted by each of the sourceMaybeSources, results in an item that will be emitted by the resultingMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5,source6,source7,source8orzipperisnull- See Also:
-
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 aMaybethat emits the results of a specified combiner function applied to combinations of nine items emitted, in sequence, by nine otherMaybeSources.
This operator terminates eagerly if any of the source
MaybeSources signal anonErrororonComplete. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zipdoes 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 sourceMaybeSourcesource2- a second sourceMaybeSourcesource3- a third sourceMaybeSourcesource4- a fourth sourceMaybeSourcesource5- a fifth sourceMaybeSourcesource6- a sixth sourceMaybeSourcesource7- a seventh sourceMaybeSourcesource8- an eighth sourceMaybeSourcesource9- a ninth sourceMaybeSourcezipper- a function that, when applied to an item emitted by each of the sourceMaybeSources, results in an item that will be emitted by the resultingMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5,source6,source7,source8,source9orzipperisnull- See Also:
-
zipArray
@CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static <@NonNull T, @NonNull R> @NonNull Maybe<R> zipArray(@NonNull @NonNull Function<? super Object[], ? extends @NonNull R> zipper, @NonNull @NonNull MaybeSource<? extends @NonNull T>... sources) Returns aMaybethat emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by an array of otherMaybeSources.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
MaybeSources signal anonErrororonComplete. This also means it is possible some sources may not get subscribed to at all.- Scheduler:
zipArraydoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element typeR- the result type- Parameters:
zipper- a function that, when applied to an item emitted by each of the sourceMaybeSources, results in an item that will be emitted by the resultingMaybesources- an array of sourceMaybeSources- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsourcesorzipperisnull- See Also:
-
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:
ambWithdoes not operate by default on a particularScheduler.
- Parameters:
other- aMaybeSourcecompeting to react first. A subscription to this provided source will occur after subscribing to the current source.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifotherisnull- See Also:
-
blockingGet
Waits in a blocking fashion until the currentMaybesignals a success value (which is returned),nullif completed or an exception (which is propagated).
- Scheduler:
blockingGetdoes not operate by default on a particularScheduler.- Error handling:
- If the source signals an error, the operator wraps a checked
ExceptionintoRuntimeExceptionand throws that. Otherwise,RuntimeExceptions andErrors 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 currentMaybesignals a success value (which is returned), defaultValue if completed or an exception (which is propagated).
- Scheduler:
blockingGetdoes not operate by default on a particularScheduler.- Error handling:
- If the source signals an error, the operator wraps a checked
ExceptionintoRuntimeExceptionand throws that. Otherwise,RuntimeExceptions andErrors are rethrown as they are.
- Parameters:
defaultValue- the default item to return if thisMaybeis empty- Returns:
- the success value
- Throws:
NullPointerException- ifdefaultValueisnull
-
blockingSubscribe
Subscribes to the currentMaybeand blocks the current thread until it terminates.
- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.- Error handling:
- If the current
Maybesignals an error, theThrowableis routed to the global error handler viaRxJavaPlugins.onError(Throwable). If the current thread is interrupted, anInterruptedExceptionis routed to the same global error handler.
- Since:
- 3.0.0
- See Also:
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess) Subscribes to the currentMaybeand calls givenonSuccesscallback on the current thread when it completes normally.
- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.- Error handling:
- If either the current
Maybesignals an error oronSuccessthrows, the respectiveThrowableis routed to the global error handler viaRxJavaPlugins.onError(Throwable). If the current thread is interrupted, anInterruptedExceptionis routed to the same global error handler.
- Parameters:
onSuccess- theConsumerto call if the currentMaybesucceeds- Throws:
NullPointerException- ifonSuccessisnull- Since:
- 3.0.0
- See Also:
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super Throwable> onError) Subscribes to the currentMaybeand calls the appropriate callback on the current thread when it terminates.
- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.- Error handling:
- If either
onSuccessoronErrorthrow, theThrowableis routed to the global error handler viaRxJavaPlugins.onError(Throwable). If the current thread is interrupted, theonErrorconsumer is called with anInterruptedException.
- Parameters:
onSuccess- theConsumerto call if the currentMaybesucceedsonError- theConsumerto call if the currentMaybesignals an error- Throws:
NullPointerException- ifonSuccessoronErrorisnull- Since:
- 3.0.0
- See Also:
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super Throwable> onError, @NonNull @NonNull Action onComplete) Subscribes to the currentMaybeand calls the appropriate callback on the current thread when it terminates.
- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.- Error handling:
- If either
onSuccess,onErrororonCompletethrow, theThrowableis routed to the global error handler viaRxJavaPlugins.onError(Throwable). If the current thread is interrupted, theonErrorconsumer is called with anInterruptedException.
- Parameters:
onSuccess- theConsumerto call if the currentMaybesucceedsonError- theConsumerto call if the currentMaybesignals an erroronComplete- theActionto call if the currentMaybecompletes without a value- Throws:
NullPointerException- ifonSuccess,onErrororonCompleteisnull- Since:
- 3.0.0
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull MaybeObserver<? super @NonNull T> observer) Subscribes to the currentMaybeand calls the appropriateMaybeObservermethod on the current thread.
- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.- Error handling:
- An
onErrorsignal is delivered to theMaybeObserver.onError(Throwable)method. If any of theMaybeObserver's methods throw, theRuntimeExceptionis propagated to the caller of this method. If the current thread is interrupted, anInterruptedExceptionis delivered toobserver.onError.
- Parameters:
observer- theMaybeObserverto call methods on the current thread- Throws:
NullPointerException- ifobserverisnull- Since:
- 3.0.0
-
cache
Returns aMaybethat subscribes to thisMaybelazily, 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:
cachedoes not operate by default on a particularScheduler.
- Returns:
- the new
Maybeinstance - See Also:
-
cast
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<U> cast(@NonNull @NonNull Class<? extends @NonNull U> clazz) Casts the success value of the currentMaybeinto the target type or signals aClassCastExceptionif not compatible.
- Scheduler:
castdoes 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
Maybeinstance - Throws:
NullPointerException- ifclazzisnull
-
compose
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Maybe<R> compose(@NonNull @NonNull MaybeTransformer<? super @NonNull T, ? extends @NonNull R> transformer) Transform aMaybeby applying a particularMaybeTransformerfunction to it.
This method operates on the
Maybeitself whereaslift(MaybeOperator)operates on theMaybe'sMaybeObservers.If the operator you are creating is designed to act on the individual item emitted by a
Maybe, uselift(MaybeOperator). If your operator is designed to transform the currentMaybeas a whole (for instance, by applying a particular set of existing RxJava operators to it) usecompose.- Scheduler:
composedoes not operate by default on a particularScheduler.
- Type Parameters:
R- the value type of theMaybereturned by the transformer function- Parameters:
transformer- the transformer function, notnull- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- iftransformerisnull- See Also:
-
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 aMaybethat 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
Maybeis the same operation.- Scheduler:
concatMapdoes 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
Maybeinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
concatMapCompletable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable concatMapCompletable(@NonNull @NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Returns aCompletablethat 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:
concatMapCompletabledoes 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
Completableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-
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 aMaybebased on applying a specified function to the item emitted by the currentMaybe, where that function returns aSingle. When thisMaybejust completes the resultingMaybecompletes as well.
This operator is an alias for
flatMapSingle(Function).- Scheduler:
concatMapSingledoes 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
Maybeinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-
concatWith
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Flowable<T> concatWith(@NonNull @NonNull MaybeSource<? extends @NonNull T> other) Returns aFlowablethat emits the items emitted from the currentMaybe, then theotherMaybeSource, one after the other, without interleaving them.
- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
concatWithdoes not operate by default on a particularScheduler.
- Parameters:
other- aMaybeSourceto be concatenated after the current- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifotherisnull- See Also:
-
contains
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<Boolean> contains(@NonNull @NonNull Object item) Returns aSinglethat emits aBooleanthat indicates whether the currentMaybeemitted a specified item.
- Scheduler:
containsdoes not operate by default on a particularScheduler.
- Parameters:
item- the item to search for in the emissions from the currentMaybe, notnull- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifitemisnull- See Also:
-
count
-
defaultIfEmpty
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> defaultIfEmpty(@NonNull @NonNull T defaultItem) Returns aSinglethat emits the item emitted by the currentMaybeor a specified default item if the currentMaybeis empty.
- Scheduler:
defaultIfEmptydoes not operate by default on a particularScheduler.
- Parameters:
defaultItem- the item to emit if the currentMaybeemits no items- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifdefaultItemisnull- See Also:
-
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 theNotificationsuccess value of the currentMaybeback into normalonSuccess,onErrororonCompletesignals.
The intended use of the
selectorfunction 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
onErrororonCompletesignals from the currentMaybeare passed along to the downstream.- Scheduler:
dematerializedoes 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 aNotificationinstance.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifselectorisnull- Since:
- 3.0.0
- See Also:
-
delay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Maybe<T> delay(long time, @NonNull @NonNull TimeUnit unit) Returns aMaybethat signals the events emitted by the currentMaybeshifted forward in time by a specified delay. An error signal will not be delayed.
- Scheduler:
- This version of
delayoperates by default on thecomputationScheduler.
- Parameters:
time- the delay to shift the source byunit- theTimeUnitin whichtimeis defined- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
delay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Maybe<T> delay(long time, @NonNull @NonNull TimeUnit unit, boolean delayError) Returns aMaybethat signals the events emitted by the currentMaybeshifted forward in time by a specified delay.
- Scheduler:
- This version of
delayoperates by default on thecomputationScheduler.
- Parameters:
time- the delay to shift the source byunit- theTimeUnitin whichtimeis defineddelayError- iftrue, both success and error signals are delayed. iffalse, only success signals are delayed.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 3.0.0
- See Also:
-
delay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Maybe<T> delay(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns aMaybethat signals the events emitted by the currentMaybeshifted forward in time by a specified delay. An error signal will not be delayed.
- Scheduler:
- you specify the
Schedulerwhere the non-blocking wait and emission happens
- Parameters:
time- the delay to shift the source byunit- theTimeUnitin whichtimeis definedscheduler- theSchedulerto use for delaying- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
delay
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<T> delay(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean delayError) Returns aMaybethat signals the events emitted by the currentMaybeshifted forward in time by a specified delay running on the specifiedScheduler.
- Scheduler:
- you specify which
Schedulerthis operator will use.
- Parameters:
time- the delay to shift the source byunit- theTimeUnitin whichtimeis definedscheduler- theSchedulerto use for delayingdelayError- iftrue, both success and error signals are delayed. iffalse, only success signals are delayed.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitorschedulerisnull- Since:
- 3.0.0
- See Also:
-
delay
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(UNBOUNDED_IN) public final <@NonNull U> @NonNull Maybe<T> delay(@NonNull @NonNull Flow.Publisher<@NonNull U> delayIndicator) Delays the emission of thisMaybeuntil the givenFlow.Publishersignals an item or completes.
- Backpressure:
- The
delayIndicatoris consumed in an unbounded manner but is cancelled after the first item it produces. - Scheduler:
- This version of
delaydoes not operate by default on a particularScheduler.
- Type Parameters:
U- the subscription delay value type (ignored)- Parameters:
delayIndicator- thePublisherthat gets subscribed to when thisMaybesignals an event and that signal is emitted when thePublishersignals an item or completes- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifdelayIndicatorisnull- See Also:
-
delaySubscription
@BackpressureSupport(UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<T> delaySubscription(@NonNull @NonNull Flow.Publisher<@NonNull U> subscriptionIndicator) Returns aMaybethat delays the subscription to thisMaybeuntil the otherFlow.Publisheremits an element or completes normally.
- Backpressure:
- The
Publishersource 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 otherPublisherthat should trigger the subscription to thisPublisher.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifsubscriptionIndicatorisnull
-
delaySubscription
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Maybe<T> delaySubscription(long time, @NonNull @NonNull TimeUnit unit) Returns aMaybethat delays the subscription to the currentMaybeby a given amount of time.
- Scheduler:
- This version of
delaySubscriptionoperates by default on thecomputationScheduler.
- Parameters:
time- the time to delay the subscriptionunit- the time unit ofdelay- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
delaySubscription
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Maybe<T> delaySubscription(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns aMaybethat delays the subscription to the currentMaybeby a given amount of time, both waiting and subscribing on a givenScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
time- the time to delay the subscriptionunit- the time unit ofdelayscheduler- theScheduleron which the waiting and subscription will happen- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
doAfterSuccess
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doAfterSuccess(@NonNull @NonNull Consumer<? super @NonNull T> onAfterSuccess) Calls the specifiedConsumerwith the success item after this item has been emitted to the downstream.Note that the
onAfterSuccessaction is shared between subscriptions and as such should be thread-safe.
- Scheduler:
doAfterSuccessdoes not operate by default on a particularScheduler.
History: 2.0.1 - experimental
- Parameters:
onAfterSuccess- theConsumerthat will be called after emitting an item from upstream to the downstream- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifonAfterSuccessisnull- Since:
- 2.1
-
doAfterTerminate
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doAfterTerminate(@NonNull @NonNull Action onAfterTerminate) Registers anActionto be called when thisMaybeinvokes eitheronSuccess,onCompleteoronError.
- Scheduler:
doAfterTerminatedoes not operate by default on a particularScheduler.
- Parameters:
onAfterTerminate- anActionto be invoked when the currentMaybefinishes- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifonAfterTerminateisnull- See Also:
-
doFinally
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doFinally(@NonNull @NonNull Action onFinally) Calls the specified action after thisMaybesignalsonSuccess,onErrororonCompleteor gets disposed by the downstream.
In case of a race between a terminal event and a dispose call, the provided
onFinallyaction is executed once per subscription.Note that the
onFinallyaction is shared between subscriptions and as such should be thread-safe.- Scheduler:
doFinallydoes not operate by default on a particularScheduler.
History: 2.0.1 - experimental
- Parameters:
onFinally- the action called when thisMaybeterminates or gets disposed- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifonFinallyisnull- Since:
- 2.1
-
doOnDispose
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doOnDispose(@NonNull @NonNull Action onDispose) Calls the sharedActionif aMaybeObserversubscribed to the currentMaybedisposes the commonDisposableit received viaonSubscribe.
- Scheduler:
doOnDisposedoes not operate by default on a particularScheduler.
- Parameters:
onDispose- the action called when the subscription is disposed- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifonDisposeisnull
-
doOnComplete
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doOnComplete(@NonNull @NonNull Action onComplete) Invokes anActionjust before the currentMaybecallsonComplete.
- Scheduler:
doOnCompletedoes not operate by default on a particularScheduler.
- Parameters:
onComplete- the action to invoke when the currentMaybecallsonComplete- Returns:
- the new
Maybewith the side-effecting behavior applied - Throws:
NullPointerException- ifonCompleteisnull- See Also:
-
doOnError
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doOnError(@NonNull @NonNull Consumer<? super Throwable> onError) Calls the sharedConsumerwith the error sent viaonErrorfor eachMaybeObserverthat subscribes to the currentMaybe.
- Scheduler:
doOnErrordoes not operate by default on a particularScheduler.
- Parameters:
onError- the consumer called with the success value ofonError- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifonErrorisnull
-
doOnEvent
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> doOnEvent(@NonNull @NonNull BiConsumer<@Nullable ? super @NonNull T, @Nullable ? super Throwable> onEvent) Calls the givenonEventcallback with the (success value,null) for anonSuccess, (null, throwable) for anonErroror (null,null) for anonCompletesignal from thisMaybebefore 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:
doOnEventdoes 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
Maybeinstance - Throws:
NullPointerException- ifonEventisnull
-
doOnLifecycle
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> doOnLifecycle(@NonNull @NonNull Consumer<? super Disposable> onSubscribe, @NonNull @NonNull Action onDispose) Calls the appropriateonXXXmethod (shared between allMaybeObservers) for the lifecycle events of the sequence (subscription, disposal).
- Scheduler:
doOnLifecycledoes not operate by default on a particularScheduler.
- Parameters:
onSubscribe- aConsumercalled with theDisposablesent viaMaybeObserver.onSubscribe(Disposable)onDispose- called when the downstream disposes theDisposableviadispose()- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifonSubscribeoronDisposeisnull- Since:
- 3.0.0
- See Also:
-
doOnSubscribe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doOnSubscribe(@NonNull @NonNull Consumer<? super Disposable> onSubscribe) Calls the sharedConsumerwith theDisposablesent through theonSubscribefor eachMaybeObserverthat subscribes to the currentMaybe.
- Scheduler:
doOnSubscribedoes not operate by default on a particularScheduler.
- Parameters:
onSubscribe- theConsumercalled with theDisposablesent viaonSubscribe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifonSubscribeisnull
-
doOnTerminate
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doOnTerminate(@NonNull @NonNull Action onTerminate) Returns aMaybeinstance that calls the given onTerminate callback just before thisMaybecompletes normally or with an exception.
This differs from
doAfterTerminatein that this happens before theonCompleteoronErrornotification.- Scheduler:
doOnTerminatedoes not operate by default on a particularScheduler.
History: 2.2.7 - experimental
- Parameters:
onTerminate- the action to invoke when the consumer callsonCompleteoronError- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifonTerminateisnull- Since:
- 3.0.0
- See Also:
-
doOnSuccess
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> doOnSuccess(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess) Calls the sharedConsumerwith the success value sent viaonSuccessfor eachMaybeObserverthat subscribes to the currentMaybe.
- Scheduler:
doOnSuccessdoes not operate by default on a particularScheduler.
- Parameters:
onSuccess- theConsumercalled with the success value of the upstream- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifonSuccessisnull
-
filter
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> filter(@NonNull @NonNull Predicate<? super @NonNull T> predicate) Filters the success item of theMaybevia a predicate function and emitting it if the predicate returnstrue, completing otherwise.
- Scheduler:
filterdoes not operate by default on a particularScheduler.
- Parameters:
predicate- a function that evaluates the item emitted by the currentMaybe, returningtrueif it passes the filter- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifpredicateisnull- See Also:
-
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 aMaybethat is based on applying a specified function to the item emitted by the currentMaybe, where that function returns aMaybeSource.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
Note that flatMap and concatMap for
Maybeis 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
Maybeinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
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 Throwable, ? extends MaybeSource<? extends @NonNull R>> onErrorMapper, @NonNull @NonNull Supplier<? extends MaybeSource<? extends @NonNull R>> onCompleteSupplier) Maps theonSuccess,onErrororonCompletesignals of the currentMaybeinto aMaybeSourceand emits thatMaybeSource's signals.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result type- Parameters:
onSuccessMapper- a function that returns aMaybeSourceto merge for theonSuccessitem emitted by thisMaybeonErrorMapper- a function that returns aMaybeSourceto merge for anonErrornotification from thisMaybeonCompleteSupplier- a function that returns aMaybeSourceto merge for anonCompletenotification thisMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifonSuccessMapper,onErrorMapperoronCompleteSupplierisnull- See Also:
-
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 aMaybethat emits the results of a specified function to the pair of values emitted by the currentMaybeand a specified mappedMaybeSource.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted by theMaybeSourcereturned by themapperfunctionR- the type of items emitted by the resultingMaybe- Parameters:
mapper- a function that returns aMaybeSourcefor the item emitted by the currentMaybecombiner- a function that combines one item emitted by each of the source and collectionMaybeSourceand returns an item to be emitted by the resultingMaybeSource- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifmapperorcombinerisnull- See Also:
-
flattenAsFlowable
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Flowable<U> flattenAsFlowable(@NonNull @NonNull Function<? super @NonNull T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper) Maps the success value of the currentMaybeinto anIterableand emits its items as aFlowablesequence.
- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
flattenAsFlowabledoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of item emitted by the innerIterable- Parameters:
mapper- a function that returns anIterablesequence of values for when given an item emitted by the currentMaybe- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
flattenAsObservable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Observable<U> flattenAsObservable(@NonNull @NonNull Function<? super @NonNull T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper) Maps the success value of the currentMaybeinto anIterableand emits its items as anObservablesequence.
- Scheduler:
flattenAsObservabledoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of item emitted by the resultingIterable- Parameters:
mapper- a function that returns anIterablesequence of values for when given an item emitted by the currentMaybe- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
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 anObservablethat is based on applying a specified function to the item emitted by the currentMaybe, where that function returns anObservableSource.
- Scheduler:
flatMapObservabledoes 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
Observableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
flatMapPublisher
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Flowable<R> flatMapPublisher(@NonNull @NonNull Function<? super @NonNull T, @NonNull ? extends Flow.Publisher<? extends @NonNull R>> mapper) Returns aFlowablethat emits items based on applying a specified function to the item emitted by the currentMaybe, where that function returns aFlow.Publisher.
- Backpressure:
- The returned
Flowablehonors the downstream backpressure. - Scheduler:
flatMapPublisherdoes 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
Flowableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
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 aMaybebased on applying a specified function to the item emitted by the currentMaybe, where that function returns aSingle. When thisMaybejust completes the resultingMaybecompletes as well.
- Scheduler:
flatMapSingledoes 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
Maybeinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.1
- See Also:
-
flatMapCompletable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable flatMapCompletable(@NonNull @NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Returns aCompletablethat completes based on applying a specified function to the item emitted by the currentMaybe, where that function returns aCompletable.
- Scheduler:
flatMapCompletabledoes 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
Completableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
hide
Hides the identity of thisMaybeand itsDisposable.
Allows preventing certain identity-based optimizations (fusion).
- Scheduler:
hidedoes not operate by default on a particularScheduler.
- Returns:
- the new
Maybeinstance
-
ignoreElement
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable ignoreElement()Returns aCompletablethat ignores the item emitted by the currentMaybeand only callsonCompleteoronError.
- Scheduler:
ignoreElementdoes not operate by default on a particularScheduler.
- Returns:
- the new
Completableinstance - See Also:
-
isEmpty
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<Boolean> isEmpty()Returns aSinglethat emitstrueif the currentMaybeis empty, otherwisefalse.
- Scheduler:
isEmptydoes not operate by default on a particularScheduler.
- Returns:
- the new
Singleinstance - See Also:
-
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 aMaybewhich, when subscribed to, invokes theapply(MaybeObserver)method of the providedMaybeOperatorfor each individual downstreamMaybeand allows the insertion of a custom operator by accessing the downstream'sMaybeObserverduring 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
MaybeObserverwill wrap the downstream'sMaybeObserverand forwards theonSuccess,onErrorandonCompleteevents 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 ofdisposeandisDisposedthat 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 abstractMaybeclass and creating aMaybeTransformerwith it is recommended.Note also that it is not possible to stop the subscription phase in
lift()as theapply()method requires a non-nullMaybeObserverinstance 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 aMaybeObserverthat should immediately dispose the upstream'sDisposablein itsonSubscribemethod. Again, using aMaybeTransformerand extending theMaybeis a better option assubscribeActual(MaybeObserver)can decide to not subscribe to its upstream after all.- Scheduler:
liftdoes not operate by default on a particularScheduler, however, theMaybeOperatormay use aSchedulerto support its own asynchronous behavior.
- Type Parameters:
R- the output value type- Parameters:
lift- theMaybeOperatorthat receives the downstream'sMaybeObserverand should return aMaybeObserverwith custom behavior to be used as the consumer for the currentMaybe.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifliftisnull- See Also:
-
map
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Maybe<R> map(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull R> mapper) Returns aMaybethat applies a specified function to the item emitted by the currentMaybeand emits the result of this function application.
- Scheduler:
mapdoes 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
Maybeinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
materialize
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<Notification<T>> materialize()Maps the signal types of thisMaybeinto aNotificationof the same kind and emits it as aSingle'sonSuccessvalue to downstream.
- Scheduler:
materializedoes not operate by default on a particularScheduler.
History: 2.2.4 - experimental
- Returns:
- the new
Singleinstance - Since:
- 3.0.0
- See Also:
-
mergeWith
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Flowable<T> mergeWith(@NonNull @NonNull MaybeSource<? extends @NonNull T> other) Flattens thisMaybeand anotherMaybeSourceinto a singleFlowable, without any transformation.
You can combine items emitted by multiple
Maybes so that they appear as a singleFlowable, by using themergeWithmethod.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeWithdoes not operate by default on a particularScheduler.
- Parameters:
other- aMaybeSourceto be merged- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifotherisnull- See Also:
-
observeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<T> observeOn(@NonNull @NonNull Scheduler scheduler) Wraps aMaybeto emit its item (or notify of its error) on a specifiedScheduler, asynchronously.
- Scheduler:
- you specify which
Schedulerthis operator will use.
- Parameters:
scheduler- theSchedulerto notify subscribers on- Returns:
- the new
Maybeinstance that its subscribers are notified on the specifiedScheduler - Throws:
NullPointerException- ifschedulerisnull- See Also:
-
ofType
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<U> ofType(@NonNull @NonNull 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:
ofTypedoes 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
Maybeinstance - Throws:
NullPointerException- ifclazzisnull- See Also:
-
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:
todoes 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 currentMaybeinstance and returns a value- Returns:
- the converted value
- Throws:
NullPointerException- ifconverterisnull- Since:
- 2.2
-
toFlowable
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> toFlowable()Converts thisMaybeinto a backpressure-awareFlowableinstance composing cancellation through.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream. - Scheduler:
toFlowabledoes not operate by default on a particularScheduler.
- Returns:
- the new
Flowableinstance
-
toFuture
Returns aFuturerepresenting the single value emitted by the currentMaybeornullif the currentMaybeis empty.
Cancelling the
Futurewill cancel the subscription to the currentMaybe.- Scheduler:
toFuturedoes not operate by default on a particularScheduler.
- Returns:
- the new
Futureinstance - Since:
- 3.0.0
- See Also:
-
toObservable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> toObservable()Converts thisMaybeinto anObservableinstance composing disposal through.
- Scheduler:
toObservabledoes not operate by default on a particularScheduler.
- Returns:
- the new
Observableinstance
-
toSingle
Converts thisMaybeinto aSingleinstance composing disposal through and turning an emptyMaybeinto a signal ofNoSuchElementException.
- Scheduler:
toSingledoes not operate by default on a particularScheduler.
- Returns:
- the new
Singleinstance - See Also:
-
onErrorComplete
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> onErrorComplete()Returns aMaybeinstance that if thisMaybeemits an error, it will emit anonCompleteand swallow the throwable.
- Scheduler:
onErrorCompletedoes not operate by default on a particularScheduler.
- Returns:
- the new
Maybeinstance
-
onErrorComplete
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> onErrorComplete(@NonNull @NonNull Predicate<? super Throwable> predicate) Returns aMaybeinstance that if thisMaybeemits an error and the predicate returnstrue, it will emit anonCompleteand swallow the throwable.
- Scheduler:
onErrorCompletedoes not operate by default on a particularScheduler.
- Parameters:
predicate- the predicate to call when anThrowableis emitted which should returntrueif theThrowableshould be swallowed and replaced with anonComplete.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifpredicateisnull
-
onErrorResumeWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> onErrorResumeWith(@NonNull @NonNull MaybeSource<? extends @NonNull T> fallback) Resumes the flow with the givenMaybeSourcewhen the currentMaybefails 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:
onErrorResumeWithdoes not operate by default on a particularScheduler.
- Parameters:
fallback- the nextMaybeSourcethat will take over if the currentMaybeencounters an error- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- iffallbackisnull- See Also:
-
onErrorResumeNext
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> onErrorResumeNext(@NonNull @NonNull Function<? super Throwable, ? extends MaybeSource<? extends @NonNull T>> fallbackSupplier) Resumes the flow with aMaybeSourcereturned for the failureThrowableof the currentMaybeby 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:
onErrorResumeNextdoes not operate by default on a particularScheduler.
- Parameters:
fallbackSupplier- a function that returns aMaybeSourcethat will take over if the currentMaybeencounters an error- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- iffallbackSupplierisnull- See Also:
-
onErrorReturn
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> onErrorReturn(@NonNull @NonNull Function<? super Throwable, ? extends @NonNull T> itemSupplier) Ends the flow with a success item returned by a function for theThrowableerror signaled by the currentMaybeinstead of signaling the error viaonError.
You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorReturndoes not operate by default on a particularScheduler.
- Parameters:
itemSupplier- a function that returns a single value that will be emitted as success value the currentMaybesignals anonErrorevent- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifitemSupplierisnull- See Also:
-
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 currentMaybefails 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:
onErrorReturnItemdoes not operate by default on a particularScheduler.
- Parameters:
item- the value that is emitted asonSuccessin case the currentMaybesignals anonError- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifitemisnull- See Also:
-
onTerminateDetach
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> onTerminateDetach()Nulls out references to the upstream producer and downstreamMaybeObserverif the sequence is terminated or downstream callsdispose().
- Scheduler:
onTerminateDetachdoes not operate by default on a particularScheduler.
- Returns:
- the new
Maybeinstance the sequence is terminated or downstream callsdispose()
-
repeat
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeat()Returns aFlowablethat repeats the sequence of items emitted by the currentMaybeindefinitely.
- Backpressure:
- The operator honors downstream backpressure.
- Scheduler:
repeatdoes not operate by default on a particularScheduler.
- Returns:
- the new
Flowableinstance - See Also:
-
repeat
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeat(long times) Returns aFlowablethat repeats the sequence of items emitted by the currentMaybeat mostcounttimes.
- Backpressure:
- This operator honors downstream backpressure.
- Scheduler:
repeatdoes not operate by default on a particularScheduler.
- Parameters:
times- the number of times the currentMaybeitems are repeated, a count of 0 will yield an empty sequence- Returns:
- the new
Flowableinstance - Throws:
IllegalArgumentException- iftimesis negative- See Also:
-
repeatUntil
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeatUntil(@NonNull @NonNull BooleanSupplier stop) Returns aFlowablethat repeats the sequence of items emitted by the currentMaybeuntil the provided stop function returnstrue.
- Backpressure:
- This operator honors downstream backpressure.
- Scheduler:
repeatUntildoes not operate by default on a particularScheduler.
- Parameters:
stop- a boolean supplier that is called when the currentFlowablecompletes and unless it returnsfalse, the currentFlowableis resubscribed- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifstopisnull- See Also:
-
repeatWhen
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeatWhen(@NonNull @NonNull Function<? super Flowable<Object>, @NonNull ? extends Flow.Publisher<@NonNull ?>> handler) Returns aFlowablethat emits the same values as the currentMaybewith the exception of anonComplete. AnonCompletenotification from the source will result in the emission of avoiditem to theFlowableprovided as an argument to thenotificationHandlerfunction. If thatFlow.PublishercallsonCompleteoronErrorthenrepeatWhenwill callonCompleteoronErroron the child observer. Otherwise, this operator will resubscribe to the currentMaybe.
- Backpressure:
- The operator honors downstream backpressure and expects the source
Publisherto honor backpressure as well. If this expectation is violated, the operator may throw anIllegalStateException. - Scheduler:
repeatWhendoes not operate by default on a particularScheduler.
- Parameters:
handler- receives aPublisherof notifications with which a user can complete or error, aborting the repeat.- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifhandlerisnull- See Also:
-
retry
Returns aMaybethat mirrors the currentMaybe, resubscribing to it if it callsonError(infinite retry count).
If the current
MaybecallsMaybeObserver.onError(Throwable), this operator will resubscribe to the currentMayberather than propagating theonErrorcall.- Scheduler:
retrydoes not operate by default on a particularScheduler.
- Returns:
- the new
Maybeinstance - See Also:
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> retry(@NonNull @NonNull BiPredicate<? super Integer, ? super Throwable> predicate) Returns aMaybethat mirrors the currentMaybe, resubscribing to it if it callsonErrorand the predicate returnstruefor that specific exception and retry count.
- Scheduler:
retrydoes 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
Maybeinstance - Throws:
NullPointerException- ifpredicateisnull- See Also:
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> retry(long times) Returns aMaybethat mirrors the currentMaybe, resubscribing to it if it callsonErrorup to a specified number of retries.
If the current
MaybecallsMaybeObserver.onError(Throwable), this operator will resubscribe to the currentMaybefor a maximum ofcountresubscriptions rather than propagating theonErrorcall.- Scheduler:
retrydoes not operate by default on a particularScheduler.
- Parameters:
times- the number of times to resubscribe if the currentMaybefails- Returns:
- the new
Maybeinstance - Throws:
IllegalArgumentException- iftimesis negative- See Also:
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> retry(long times, @NonNull @NonNull Predicate<? super Throwable> predicate) Retries at mosttimesor until the predicate returnsfalse, whichever happens first.
- Scheduler:
retrydoes not operate by default on a particularScheduler.
- Parameters:
times- the number of times to resubscribe if the currentMaybefailspredicate- the predicate called with the failureThrowableand should returntrueto trigger a retry.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifpredicateisnullIllegalArgumentException- iftimesis negative
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> retry(@NonNull @NonNull Predicate<? super Throwable> predicate) Retries the currentMaybeif it fails and the predicate returnstrue.
- Scheduler:
retrydoes not operate by default on a particularScheduler.
- Parameters:
predicate- the predicate that receives the failureThrowableand should returntrueto trigger a retry.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifpredicateisnull
-
retryUntil
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> retryUntil(@NonNull @NonNull BooleanSupplier stop) Retries until the given stop function returnstrue.
- Scheduler:
retryUntildoes not operate by default on a particularScheduler.
- Parameters:
stop- the function that should returntrueto stop retrying- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifstopisnull
-
retryWhen
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> retryWhen(@NonNull @NonNull Function<? super Flowable<Throwable>, @NonNull ? extends Flow.Publisher<@NonNull ?>> handler) Returns aMaybethat emits the same values as the currentMaybewith the exception of anonError. AnonErrornotification from the source will result in the emission of aThrowableitem to theFlowableprovided as an argument to thenotificationHandlerfunction. If the returnedFlow.PublishercallsonCompleteoronErrorthenretrywill callonCompleteoronErroron 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) subscribingNote that the inner
Publisherreturned by the handler function should signal eitheronNext,onErrororonCompletein response to the receivedThrowableto indicate the operator should retry or terminate. If the upstream to the operator is asynchronous, signallingonNextfollowed byonCompleteimmediately may result in the sequence to be completed immediately. Similarly, if this innerPublishersignalsonErrororonCompletewhile 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:
retryWhendoes not operate by default on a particularScheduler.
- Parameters:
handler- receives aPublisherof notifications with which a user can complete or error, aborting the retry- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifhandlerisnull- See Also:
-
safeSubscribe
@SchedulerSupport("none") public final void safeSubscribe(@NonNull @NonNull MaybeObserver<? super @NonNull T> observer) Wraps the givenMaybeObserver, catches anyRuntimeExceptions 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
Maybeprotocol forbids theonXXXmethods to throw, but someMaybeObserverimplementation 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:
safeSubscribedoes not operate by default on a particularScheduler.
- Parameters:
observer- the potentially misbehavingMaybeObserver- Throws:
NullPointerException- ifobserverisnull- Since:
- 3.0.0
- See Also:
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final @NonNull Flowable<T> startWith(@NonNull @NonNull CompletableSource other) Returns aFlowablewhich first runs the otherCompletableSourcethen the currentMaybeif the other completed normally.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherCompletableSourceto run first- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final @NonNull Flowable<T> startWith(@NonNull @NonNull SingleSource<@NonNull T> other) Returns aFlowablewhich first runs the otherSingleSourcethen the currentMaybeif the other succeeded normally.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherSingleSourceto run first- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final @NonNull Flowable<T> startWith(@NonNull @NonNull MaybeSource<@NonNull T> other) Returns aFlowablewhich first runs the otherMaybeSourcethen the currentMaybeif the other succeeded or completed normally.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherMaybeSourceto run first- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Observable<T> startWith(@NonNull @NonNull ObservableSource<@NonNull T> other) Returns anObservablewhich first delivers the events of the otherObservableSourcethen runs the currentMaybe.
- Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherObservableSourceto run first- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public final @NonNull Flowable<T> startWith(@NonNull @NonNull Flow.Publisher<@NonNull T> other) Returns aFlowablewhich first delivers the events of the otherFlow.Publisherthen runs the currentMaybe.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer and expects the otherPublisherto honor it as well. - Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherPublisherto run first- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 3.0.0
-
subscribe
Subscribes to aMaybeand ignoresonSuccessandonCompleteemissions.If the
Maybeemits an error, it is wrapped into anOnErrorNotImplementedExceptionand routed to theRxJavaPlugins.onError(Throwable)handler.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Returns:
- the new
Disposableinstance that can be used for disposing the subscription at any time - See Also:
-
subscribe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess) Subscribes to aMaybeand provides a callback to handle the items it emits.If the
Maybeemits an error, it is wrapped into anOnErrorNotImplementedExceptionand routed to theRxJavaPlugins.onError(Throwable)handler.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
onSuccess- theConsumer<T>you have designed to accept a success value from theMaybe- Returns:
- the new
Disposableinstance that can be used for disposing the subscription at any time - Throws:
NullPointerException- ifonSuccessisnull- See Also:
-
subscribe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super Throwable> onError) Subscribes to aMaybeand provides callbacks to handle the items it emits and any error notification it issues.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
onSuccess- theConsumer<T>you have designed to accept a success value from theMaybeonError- theConsumer<Throwable>you have designed to accept any error notification from theMaybe- Returns:
- the new
Disposableinstance that can be used for disposing the subscription at any time - Throws:
NullPointerException- ifonSuccessisnull, or ifonErrorisnull- See Also:
-
subscribe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super Throwable> onError, @NonNull @NonNull Action onComplete) Subscribes to aMaybeand provides callbacks to handle the items it emits and any error or completion notification it issues.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
onSuccess- theConsumer<T>you have designed to accept a success value from theMaybeonError- theConsumer<Throwable>you have designed to accept any error notification from theMaybeonComplete- theActionyou have designed to accept a completion notification from theMaybe- Returns:
- the new
Disposableinstance that can be used for disposing the subscription at any time - Throws:
NullPointerException- ifonSuccess,onErrororonCompleteisnull- See Also:
-
subscribe
@SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super Throwable> onError, @NonNull @NonNull Action onComplete, @NonNull @NonNull DisposableContainer container) Wraps the given onXXX callbacks into aDisposableMaybeObserver, adds it to the givenDisposableContainerand ensures, that if the upstream terminates or this particularDisposableis disposed, theMaybeObserveris removed from the given composite.The
MaybeObserverwill be removed after the callback for the terminal event has been invoked.- Scheduler:
subscribedoes 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 createdDisposableMaybeObserver- Returns:
- the
Disposablethat allows disposing the particular subscription. - Throws:
NullPointerException- ifonSuccess,onError,onCompleteorcontainerisnull- Since:
- 3.1.0
-
subscribe
@SchedulerSupport("none") public final void subscribe(@NonNull @NonNull MaybeObserver<? super @NonNull T> observer) Description copied from interface:MaybeSourceSubscribes the givenMaybeObserverto thisMaybeSourceinstance.- Specified by:
subscribein 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 incomingMaybeObservers.There is no need to call any of the plugin hooks on the current
Maybeinstance or theMaybeObserver; all hooks and basic safeguards have been applied bysubscribe(MaybeObserver)before this method gets called.- Parameters:
observer- theMaybeObserverto handle, notnull
-
subscribeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<T> subscribeOn(@NonNull @NonNull Scheduler scheduler) Asynchronously subscribes subscribers to thisMaybeon the specifiedScheduler.
- Scheduler:
- you specify which
Schedulerthis operator will use.
- Parameters:
scheduler- theSchedulerto perform subscription actions on- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifschedulerisnull- See Also:
-
subscribeWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull E extends MaybeObserver<? super @NonNull T>> E subscribeWith(@NonNull E observer) Subscribes a givenMaybeObserver(subclass) to thisMaybeand returns the givenMaybeObserveras is.Usage example:
Maybe<Integer> source = Maybe.just(1); CompositeDisposable composite = new CompositeDisposable(); DisposableMaybeObserver<Integer> ds = new DisposableMaybeObserver<>() { // ... }; composite.add(source.subscribeWith(ds));- Scheduler:
subscribeWithdoes not operate by default on a particularScheduler.
- Type Parameters:
E- the type of theMaybeObserverto use and return- Parameters:
observer- theMaybeObserver(subclass) to use and return, notnull- Returns:
- the input
observer - Throws:
NullPointerException- ifobserverisnull
-
switchIfEmpty
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> switchIfEmpty(@NonNull @NonNull MaybeSource<? extends @NonNull T> other) Returns aMaybethat emits the items emitted by the currentMaybeor the items of an alternateMaybeSourceif the currentMaybeis empty.
- Scheduler:
switchIfEmptydoes not operate by default on a particularScheduler.
- Parameters:
other- the alternateMaybeSourceto subscribe to if the main does not emit any items- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifotherisnull
-
switchIfEmpty
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> switchIfEmpty(@NonNull @NonNull SingleSource<? extends @NonNull T> other) Returns aSinglethat emits the items emitted by the currentMaybeor the item of an alternateSingleSourceif the currentMaybeis empty.
- Scheduler:
switchIfEmptydoes not operate by default on a particularScheduler.
History: 2.1.4 - experimental
- Parameters:
other- the alternateSingleSourceto subscribe to if the main does not emit any items- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 2.2
-
takeUntil
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<T> takeUntil(@NonNull @NonNull MaybeSource<@NonNull U> other) Returns aMaybethat emits the items emitted by the currentMaybeuntil a secondMaybeSourceemits an item.
- Scheduler:
takeUntildoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted byother- Parameters:
other- theMaybeSourcewhose first emitted item will causetakeUntilto stop emitting items from the currentMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifotherisnull- See Also:
-
takeUntil
@BackpressureSupport(UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<T> takeUntil(@NonNull @NonNull Flow.Publisher<@NonNull U> other) Returns aMaybethat emits the item emitted by the currentMaybeuntil a secondFlow.Publisheremits an item.
- Backpressure:
- The
Publisheris consumed in an unbounded fashion and is cancelled after the first item emitted. - Scheduler:
takeUntildoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted byother- Parameters:
other- thePublisherwhose first emitted item will causetakeUntilto stop emitting items from the sourcePublisher- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifotherisnull- See Also:
-
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 currentMaybeand signals it as a tuple (Timed) success value.
If the current
Maybeis empty or fails, the resultingMaybewill pass along the signals to the downstream. To measure the time to termination, usematerialize()and applySingle.timeInterval().- Scheduler:
timeIntervaluses thecomputationSchedulerfor determining the current time upon subscription and upon receiving the success item from the currentMaybe.
- Returns:
- the new
Maybeinstance - 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 currentMaybeand signals it as a tuple (Timed) success value.
If the current
Maybeis empty or fails, the resultingMaybewill pass along the signals to the downstream. To measure the time to termination, usematerialize()and applySingle.timeInterval(Scheduler).- Scheduler:
timeIntervaluses the providedSchedulerfor determining the current time upon subscription and upon receiving the success item from the currentMaybe.
- Parameters:
scheduler- theSchedulerused for providing the current time- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifschedulerisnull- Since:
- 3.0.0
-
timeInterval
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Maybe<Timed<T>> timeInterval(@NonNull @NonNull TimeUnit unit) Measures the time between the subscription and success item emission of the currentMaybeand signals it as a tuple (Timed) success value.
If the current
Maybeis empty or fails, the resultingMaybewill pass along the signals to the downstream. To measure the time to termination, usematerialize()and applySingle.timeInterval(TimeUnit).- Scheduler:
timeIntervaluses thecomputationSchedulerfor 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
Maybeinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 3.0.0
-
timeInterval
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<Timed<T>> timeInterval(@NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Measures the time between the subscription and success item emission of the currentMaybeand signals it as a tuple (Timed) success value.
If the current
Maybeis empty or fails, the resultingMaybewill pass along the signals to the downstream. To measure the time to termination, usematerialize()and applySingle.timeInterval(TimeUnit, Scheduler).- Scheduler:
timeIntervaluses the providedSchedulerfor determining the current time upon subscription and upon receiving the success item from the currentMaybe.
- Parameters:
unit- the time unit for measurementscheduler- theSchedulerused for providing the current time- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitorschedulerisnull- Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Maybe<Timed<T>> timestamp()Combines the success value from the currentMaybewith the current time (in milliseconds) of its reception, using thecomputationScheduleras time source, then signals them as aTimedinstance.
If the current
Maybeis empty or fails, the resultingMaybewill pass along the signals to the downstream. To measure the time to termination, usematerialize()and applySingle.timestamp().- Scheduler:
timestampuses thecomputationSchedulerfor determining the current time upon receiving the success item from the currentMaybe.
- Returns:
- the new
Maybeinstance - 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 currentMaybewith the current time (in milliseconds) of its reception, using the givenScheduleras time source, then signals them as aTimedinstance.
If the current
Maybeis empty or fails, the resultingMaybewill pass along the signals to the downstream. To measure the time to termination, usematerialize()and applySingle.timestamp(Scheduler).- Scheduler:
timestampuses the providedSchedulerfor determining the current time upon receiving the success item from the currentMaybe.
- Parameters:
scheduler- theSchedulerused for providing the current time- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifschedulerisnull- Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Maybe<Timed<T>> timestamp(@NonNull @NonNull TimeUnit unit) Combines the success value from the currentMaybewith the current time of its reception, using thecomputationScheduleras time source, then signals it as aTimedinstance.
If the current
Maybeis empty or fails, the resultingMaybewill pass along the signals to the downstream. To measure the time to termination, usematerialize()and applySingle.timestamp(TimeUnit).- Scheduler:
timestampuses thecomputationScheduler, for determining the current time upon receiving the success item from the currentMaybe.
- Parameters:
unit- the time unit for measurement- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<Timed<T>> timestamp(@NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Combines the success value from the currentMaybewith the current time of its reception, using the givenScheduleras time source, then signals it as aTimedinstance.
If the current
Maybeis empty or fails, the resultingMaybewill pass along the signals to the downstream. To measure the time to termination, usematerialize()and applySingle.timestamp(TimeUnit, Scheduler).- Scheduler:
timestampuses 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- theSchedulerused for providing the current time- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitorschedulerisnull- Since:
- 3.0.0
-
timeout
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Maybe<T> timeout(long timeout, @NonNull @NonNull TimeUnit unit) Returns aMaybethat mirrors the currentMaybebut 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 resultingMaybeterminates and notifiesMaybeObservers of aTimeoutException.
- Scheduler:
- This version of
timeoutoperates by default on thecomputationScheduler.
- Parameters:
timeout- maximum duration between emitted items before a timeout occursunit- the unit of time that applies to thetimeoutargument.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
timeout
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Maybe<T> timeout(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull MaybeSource<? extends @NonNull T> fallback) Returns aMaybethat mirrors the currentMaybebut 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 currentMaybeis disposed and resultingMaybebegins instead to mirror a fallbackMaybeSource.
- Scheduler:
- This version of
timeoutoperates by default on thecomputationScheduler.
- Parameters:
timeout- maximum duration between items before a timeout occursunit- the unit of time that applies to thetimeoutargumentfallback- the fallbackMaybeSourceto use in case of a timeout- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitorfallbackisnull- See Also:
-
timeout
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<T> timeout(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, @NonNull @NonNull MaybeSource<? extends @NonNull T> fallback) Returns aMaybethat mirrors the currentMaybebut 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 currentMaybeis disposed and resultingMaybebegins instead to mirror a fallbackMaybeSource.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timeout- maximum duration between items before a timeout occursunit- the unit of time that applies to thetimeoutargumentscheduler- theSchedulerto run the timeout timers onfallback- theMaybeSourceto use as the fallback in case of a timeout- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- iffallback,unitorschedulerisnull- See Also:
-
timeout
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Maybe<T> timeout(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns aMaybethat mirrors the currentMaybebut 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 resultingMaybeterminates and notifiesMaybeObservers of aTimeoutException.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timeout- maximum duration between items before a timeout occursunit- the unit of time that applies to thetimeoutargumentscheduler- theSchedulerto run the timeout timers on- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
timeout
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<T> timeout(@NonNull @NonNull MaybeSource<@NonNull U> timeoutIndicator) If the currentMaybedidn't signal an event before thetimeoutIndicatorMaybeSourcesignals, aTimeoutExceptionis signaled instead.
- Scheduler:
timeoutdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the value type of the- Parameters:
timeoutIndicator- theMaybeSourcethat indicates the timeout by signalingonSuccessoronComplete.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- iftimeoutIndicatorisnull
-
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 currentMaybedidn't signal an event before thetimeoutIndicatorMaybeSourcesignals, the currentMaybeis disposed and thefallbackMaybeSourcesubscribed to as a continuation.
- Scheduler:
timeoutdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the value type of the- Parameters:
timeoutIndicator- theMaybeSourcethat indicates the timeout by signalingonSuccessoronComplete.fallback- theMaybeSourcethat is subscribed to if the currentMaybetimes out- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- iftimeoutIndicatororfallbackisnull
-
timeout
@BackpressureSupport(UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<T> timeout(@NonNull @NonNull Flow.Publisher<@NonNull U> timeoutIndicator) If the currentMaybesource didn't signal an event before thetimeoutIndicatorFlow.Publishersignals, aTimeoutExceptionis signaled instead.
- Backpressure:
- The
timeoutIndicatorPublisheris consumed in an unbounded manner and is cancelled after its first item. - Scheduler:
timeoutdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the value type of the- Parameters:
timeoutIndicator- thePublisherthat indicates the timeout by signalingonSuccessoronComplete.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- iftimeoutIndicatorisnull
-
timeout
@BackpressureSupport(UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<T> timeout(@NonNull @NonNull Flow.Publisher<@NonNull U> timeoutIndicator, @NonNull @NonNull MaybeSource<? extends @NonNull T> fallback) If the currentMaybedidn't signal an event before thetimeoutIndicatorFlow.Publishersignals, the currentMaybeis disposed and thefallbackMaybeSourcesubscribed to as a continuation.
- Backpressure:
- The
timeoutIndicatorPublisheris consumed in an unbounded manner and is cancelled after its first item. - Scheduler:
timeoutdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the value type of the- Parameters:
timeoutIndicator- theMaybeSourcethat indicates the timeout by signalingonSuccessoronCompletefallback- theMaybeSourcethat is subscribed to if the currentMaybetimes out- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- iftimeoutIndicatororfallbackisnull
-
unsubscribeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Maybe<T> unsubscribeOn(@NonNull @NonNull Scheduler scheduler) Returns aMaybewhich makes sure when aMaybeObserverdisposes theDisposable, that call is propagated up on the specifiedScheduler.
- Scheduler:
unsubscribeOncallsdispose()of the upstream on theScheduleryou specify.
- Parameters:
scheduler- the target scheduler where to execute the disposal- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifschedulerisnull
-
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 otherMaybeSourcesignal a success value then applies the givenBiFunctionto those values and emits theBiFunction's resulting value to downstream.
If either this or the other
MaybeSourceis empty or signals an error, the resultingMaybewill terminate immediately and dispose the other source.- Scheduler:
zipWithdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted by theotherMaybeSourceR- the type of items emitted by the resultingMaybe- Parameters:
other- the otherMaybeSourcezipper- a function that combines the pairs of items from the twoMaybeSources to generate the items to be emitted by the resultingMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifotherorzipperisnull- See Also:
-
test
Creates aTestObserverand subscribes it to thisMaybe.- Scheduler:
testdoes not operate by default on a particularScheduler.
- Returns:
- the new
TestObserverinstance
-
test
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull TestObserver<T> test(boolean dispose) Creates aTestObserveroptionally in cancelled state, then subscribes it to thisMaybe.- Scheduler:
testdoes not operate by default on a particularScheduler.
- Parameters:
dispose- iftrue, theTestObserverwill be disposed before subscribing to thisMaybe.- Returns:
- the new
TestObserverinstance
-
fromOptional
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Maybe<@NonNull T> fromOptional(@NonNull @NonNull Optional<@NonNull T> optional) Converts the existing value of the provided optional into ajust(Object)or an empty optional into anempty()Maybeinstance.
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:
fromOptionaldoes 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
Maybeinstance - Throws:
NullPointerException- ifoptionalisnull- Since:
- 3.0.0
- See Also:
-
fromCompletionStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Maybe<@NonNull T> fromCompletionStage(@NonNull @NonNull 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 theCompletionStageis to be created per consumer upon subscription, usedefer(Supplier)aroundfromCompletionStage:Maybe.defer(() -> Maybe.fromCompletionStage(createCompletionStage()));If the
CompletionStagecompletes withnull, the resultingMaybeis completed viaonComplete.Canceling the flow can't cancel the execution of the
CompletionStagebecauseCompletionStageitself doesn't support cancellation. Instead, the operator detaches from theCompletionStage.- Scheduler:
fromCompletionStagedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the element type of theCompletionStage- Parameters:
stage- theCompletionStageto convert toMaybeand signal its terminal value or error- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifstageisnull- Since:
- 3.0.0
-
mapOptional
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Maybe<R> mapOptional(@NonNull @NonNull Function<? super @NonNull T, @NonNull Optional<? extends @NonNull R>> mapper) Maps the upstream success value into anOptionaland emits the contained item if not empty.
- Scheduler:
mapOptionaldoes not operate by default on a particularScheduler.
- Type Parameters:
R- the non-nulloutput type- Parameters:
mapper- the function that receives the upstream success item and should return a non-emptyOptionalto emit as the success output or an emptyOptionalto complete theMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-
toCompletionStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull CompletionStage<T> toCompletionStage()Signals the upstream success item (or aNoSuchElementExceptionif the upstream is empty) via aCompletionStage.
The upstream can be canceled by converting the resulting
CompletionStageintoCompletableFutureviaCompletionStage.toCompletableFuture()and callingCompletableFuture.cancel(boolean)on it. The upstream will be also cancelled if the resultingCompletionStageis converted to and completed manually byCompletableFuture.complete(Object)orCompletableFuture.completeExceptionally(Throwable).CompletionStages don't have a notion of emptiness and allownulls, therefore, one can either usetoCompletionStage(Object)withnullor turn the upstream into a sequence ofOptionals and default toOptional.empty():CompletionStage<Optional<T>> stage = source.map(Optional::of).toCompletionStage(Optional.empty());- Scheduler:
toCompletionStagedoes not operate by default on a particularScheduler.
- Returns:
- the new
CompletionStageinstance - Since:
- 3.0.0
- See Also:
-
toCompletionStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull 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
CompletionStageintoCompletableFutureviaCompletionStage.toCompletableFuture()and callingCompletableFuture.cancel(boolean)on it. The upstream will be also cancelled if the resultingCompletionStageis converted to and completed manually byCompletableFuture.complete(Object)orCompletableFuture.completeExceptionally(Throwable).CompletionStages don't have a notion of emptiness and allownulls, therefore, one can either use adefaultItemofnullor turn the flow into a sequence ofOptionals and default toOptional.empty():CompletionStage<Optional<T>> stage = source.map(Optional::of).toCompletionStage(Optional.empty());- Scheduler:
toCompletionStagedoes not operate by default on a particularScheduler.
- Parameters:
defaultItem- the item to signal if the upstream is empty- Returns:
- the new
CompletionStageinstance - 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, @NonNull ? extends Stream<? extends @NonNull R>> mapper) Maps the upstream succecss value into a JavaStreamand emits its items to the downstream consumer as aFlowable.
The operator closes the
Streamupon cancellation and when it terminates. The exceptions raised when closing aStreamare routed to the global error handler (RxJavaPlugins.onError(Throwable). If aStreamshould not be closed, turn it into anIterableand 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());Streamdoes 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
Streamon demand (i.e., when requested). - Scheduler:
flattenStreamAsFlowabledoes not operate by default on a particularScheduler.
- Type Parameters:
R- the element type of theStreamand the outputFlowable- Parameters:
mapper- the function that receives the upstream success item and should return aStreamof values to emit.- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-
flattenStreamAsObservable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flattenStreamAsObservable(@NonNull @NonNull Function<? super @NonNull T, @NonNull ? extends Stream<? extends @NonNull R>> mapper) Maps the upstream succecss value into a JavaStreamand emits its items to the downstream consumer as anObservable.
The operator closes the
Streamupon cancellation and when it terminates. The exceptions raised when closing aStreamare routed to the global error handler (RxJavaPlugins.onError(Throwable). If aStreamshould not be closed, turn it into anIterableand 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());Streamdoes not support concurrent usage so creating and/or consuming the same instance multiple times from multiple threads can lead to undefined behavior.- Scheduler:
flattenStreamAsObservabledoes not operate by default on a particularScheduler.
- Type Parameters:
R- the element type of theStreamand the outputObservable- Parameters:
mapper- the function that receives the upstream success item and should return aStreamof values to emit.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-