All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.reactivex.observable.Maybe Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2016-present, RxJava Contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
 * the License for the specific language governing permissions and limitations under the License.
 */

package io.reactivex.observable;

import java.util.NoSuchElementException;
import java.util.concurrent.*;

import io.reactivex.common.*;
import io.reactivex.common.annotations.*;
import io.reactivex.common.exceptions.Exceptions;
import io.reactivex.common.functions.*;
import io.reactivex.common.internal.functions.*;
import io.reactivex.common.internal.utils.ExceptionHelper;
import io.reactivex.observable.extensions.FuseToObservable;
import io.reactivex.observable.internal.observers.BlockingMultiObserver;
import io.reactivex.observable.internal.operators.*;
import io.reactivex.observable.observers.TestObserver;

/**
 * Represents a deferred computation and emission of a maybe value or exception.
 * 

* *

* The main consumer type of Maybe is {@link MaybeObserver} whose methods are called * in a sequential fashion following this protocol:
* {@code onSubscribe (onSuccess | onError | onComplete)?}. *

* @param the value type * @since 2.0 */ public abstract class Maybe implements MaybeSource { /** * Runs multiple Maybe sources and signals the events of the first one that signals (cancelling * the rest). *

*
Scheduler:
*
{@code amb} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources the Iterable sequence of sources. A subscription to each source will * occur in the same order as in the Iterable. * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe amb(final Iterable> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); return RxJavaObservablePlugins.onAssembly(new MaybeAmb(null, sources)); } /** * Runs multiple Maybe sources and signals the events of the first one that signals (cancelling * the rest). *
*
Scheduler:
*
{@code ambArray} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources the array of sources. A subscription to each source will * occur in the same order as in the array. * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Maybe ambArray(final MaybeSource... sources) { if (sources.length == 0) { return empty(); } if (sources.length == 1) { return wrap((MaybeSource)sources[0]); } return RxJavaObservablePlugins.onAssembly(new MaybeAmb(sources, null)); } /** * Concatenate the single values, in a non-overlapping fashion, of the MaybeSource sources provided by * an Iterable sequence. *
*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources the Iterable sequence of MaybeSource instances * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concat(Iterable> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); return RxJavaObservablePlugins.onAssembly(new MaybeConcatIterable(sources)); } /** * Returns an Observable that emits the items emitted by two MaybeSources, one after the other. *

* *

*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common value type * @param source1 * a MaybeSource to be concatenated * @param source2 * a MaybeSource to be concatenated * @return an Observable that emits items emitted by the two source MaybeSources, one after the other. * @see ReactiveX operators documentation: Concat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Observable concat(MaybeSource source1, MaybeSource source2) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); return concatArray(source1, source2); } /** * Returns an Observable that emits the items emitted by three MaybeSources, one after the other. *

* *

*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common value type * @param source1 * a MaybeSource to be concatenated * @param source2 * a MaybeSource to be concatenated * @param source3 * a MaybeSource to be concatenated * @return an Observable that emits items emitted by the three source MaybeSources, one after the other. * @see ReactiveX operators documentation: Concat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Observable concat( MaybeSource source1, MaybeSource source2, MaybeSource source3) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); return concatArray(source1, source2, source3); } /** * Returns an Observable that emits the items emitted by four MaybeSources, one after the other. *

* *

*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common value type * @param source1 * a MaybeSource to be concatenated * @param source2 * a MaybeSource to be concatenated * @param source3 * a MaybeSource to be concatenated * @param source4 * a MaybeSource to be concatenated * @return an Observable that emits items emitted by the four source MaybeSources, one after the other. * @see ReactiveX operators documentation: Concat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Observable concat( MaybeSource source1, MaybeSource source2, MaybeSource source3, MaybeSource source4) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); return concatArray(source1, source2, source3, source4); } /** * Concatenate the single values, in a non-overlapping fashion, of the MaybeSource sources provided by * an ObservableSource sequence. *
*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources the ObservableSource of MaybeSource instances * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concat(ObservableSource> sources) { return concat(sources, 2); } /** * Concatenate the single values, in a non-overlapping fashion, of the MaybeSource sources provided by * an ObservableSource sequence. *
*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources the ObservableSource of MaybeSource instances * @param prefetch the number of MaybeSources to prefetch from the ObservableSource * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings({ "unchecked", "rawtypes" }) public static Observable concat(ObservableSource> sources, int prefetch) { ObjectHelper.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); return RxJavaObservablePlugins.onAssembly(new ObservableConcatMap(sources, MaybeToObservable.instance(), prefetch, ErrorMode.IMMEDIATE)); } /** * Concatenate the single values, in a non-overlapping fashion, of the MaybeSource sources in the array. *
*
Scheduler:
*
{@code concatArray} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources the array of MaybeSource instances * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Observable concatArray(MaybeSource... sources) { ObjectHelper.requireNonNull(sources, "sources is null"); if (sources.length == 0) { return Observable.empty(); } if (sources.length == 1) { return RxJavaObservablePlugins.onAssembly(new MaybeToObservable((MaybeSource)sources[0])); } return RxJavaObservablePlugins.onAssembly(new MaybeConcatArray(sources)); } /** * Concatenates a variable number of MaybeSource sources and delays errors from any of them * till all terminate. *

* *

*
Scheduler:
*
{@code concatArrayDelayError} does not operate by default on a particular {@link Scheduler}.
*
* @param sources the array of sources * @param the common base value type * @return the new Observable instance * @throws NullPointerException if sources is null */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatArrayDelayError(MaybeSource... sources) { if (sources.length == 0) { return Observable.empty(); } else if (sources.length == 1) { return RxJavaObservablePlugins.onAssembly(new MaybeToObservable((MaybeSource)sources[0])); } return RxJavaObservablePlugins.onAssembly(new MaybeConcatArrayDelayError(sources)); } /** * Concatenates a sequence of MaybeSource eagerly into a single stream of values. *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source MaybeSources. The operator buffers the value emitted by these MaybeSources and then drains them * in order, each one after the previous one completes. *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources a sequence of MaybeSources that need to be eagerly concatenated * @return the new Observable instance with the specified concatenation behavior */ @SuppressWarnings({ "rawtypes", "unchecked" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatArrayEager(MaybeSource... sources) { return Observable.fromArray(sources).concatMapEager((Function)MaybeToObservable.instance()); } /** * Concatenates the Iterable sequence of MaybeSources into a single sequence by subscribing to each MaybeSource, * one after the other, one at a time and delays any errors till the all inner MaybeSources terminate. * *
*
Scheduler:
*
{@code concatDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources the Iterable sequence of MaybeSources * @return the new Observable with the concatenating behavior */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatDelayError(Iterable> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); return Observable.fromIterable(sources).concatMapDelayError((Function)MaybeToObservable.instance()); } /** * Concatenates the ObservableSource sequence of ObservableSources into a single sequence by subscribing to each inner ObservableSource, * one after the other, one at a time and delays any errors till the all inner and the outer ObservableSources terminate. * *
*
Scheduler:
*
{@code concatDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources the ObservableSource sequence of ObservableSources * @return the new ObservableSource with the concatenating behavior */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatDelayError(ObservableSource> sources) { return Observable.wrap(sources).concatMapDelayError((Function)MaybeToObservable.instance()); } /** * Concatenates a sequence of MaybeSources eagerly into a single stream of values. *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source MaybeSources. The operator buffers the values emitted by these MaybeSources and then drains them * in order, each one after the previous one completes. *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources a sequence of MaybeSource that need to be eagerly concatenated * @return the new Observable instance with the specified concatenation behavior */ @SuppressWarnings({ "rawtypes", "unchecked" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatEager(Iterable> sources) { return Observable.fromIterable(sources).concatMapEager((Function)MaybeToObservable.instance()); } /** * Concatenates an ObservableSource sequence of ObservableSources eagerly into a single stream of values. *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * emitted source ObservableSources as they are observed. The operator buffers the values emitted by these * ObservableSources and then drains them in order, each one after the previous one completes. *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources a sequence of ObservableSources that need to be eagerly concatenated * @return the new ObservableSource instance with the specified concatenation behavior */ @SuppressWarnings({ "rawtypes", "unchecked" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatEager(ObservableSource> sources) { return Observable.wrap(sources).concatMapEager((Function)MaybeToObservable.instance()); } /** * Provides an API (via a cold Maybe) 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);
     *
     * });
     * 
*

*

*
Scheduler:
*
{@code create} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param onSubscribe the emitter that is called when a MaybeObserver subscribes to the returned {@code Maybe} * @return the new Maybe instance * @see MaybeOnSubscribe * @see Cancellable */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe create(MaybeOnSubscribe onSubscribe) { ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null"); return RxJavaObservablePlugins.onAssembly(new MaybeCreate(onSubscribe)); } /** * Calls a Callable for each individual MaybeObserver to return the actual MaybeSource source to * be subscribed to. *
*
Scheduler:
*
{@code defer} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param maybeSupplier the Callable that is called for each individual MaybeObserver and * returns a MaybeSource instance to subscribe to * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe defer(final Callable> maybeSupplier) { ObjectHelper.requireNonNull(maybeSupplier, "maybeSupplier is null"); return RxJavaObservablePlugins.onAssembly(new MaybeDefer(maybeSupplier)); } /** * Returns a (singleton) Maybe instance that calls {@link MaybeObserver#onComplete onComplete} * immediately. *

* *

*
Scheduler:
*
{@code empty} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Maybe empty() { return RxJavaObservablePlugins.onAssembly((Maybe)MaybeEmpty.INSTANCE); } /** * Returns a Maybe that invokes a subscriber's {@link MaybeObserver#onError onError} method when the * subscriber subscribes to it. *

* *

*
Scheduler:
*
{@code error} does not operate by default on a particular {@link Scheduler}.
*
* * @param exception * the particular Throwable to pass to {@link MaybeObserver#onError onError} * @param * the type of the item (ostensibly) emitted by the Maybe * @return a Maybe that invokes the subscriber's {@link MaybeObserver#onError onError} method when * the subscriber subscribes to it * @see ReactiveX operators documentation: Throw */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe error(Throwable exception) { ObjectHelper.requireNonNull(exception, "exception is null"); return RxJavaObservablePlugins.onAssembly(new MaybeError(exception)); } /** * Returns a Maybe that invokes a {@link MaybeObserver}'s {@link MaybeObserver#onError onError} method when the * MaybeObserver subscribes to it. *

* *

*
Scheduler:
*
{@code error} does not operate by default on a particular {@link Scheduler}.
*
* * @param supplier * a Callable factory to return a Throwable for each individual MaybeObserver * @param * the type of the items (ostensibly) emitted by the Maybe * @return a Maybe that invokes the {@link MaybeObserver}'s {@link MaybeObserver#onError onError} method when * the MaybeObserver subscribes to it * @see ReactiveX operators documentation: Throw */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe error(Callable supplier) { ObjectHelper.requireNonNull(supplier, "errorSupplier is null"); return RxJavaObservablePlugins.onAssembly(new MaybeErrorCallable(supplier)); } /** * Returns a Maybe instance that runs the given Action for each subscriber and * emits either its exception or simply completes. *
*
Scheduler:
*
{@code fromAction} does not operate by default on a particular {@link Scheduler}.
*
* @param the target type * @param run the runnable to run for each subscriber * @return the new Maybe instance * @throws NullPointerException if run is null */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromAction(final Action run) { ObjectHelper.requireNonNull(run, "run is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFromAction(run)); } /** * Wraps a CompletableSource into a Maybe. * *
*
Scheduler:
*
{@code fromCompletable} does not operate by default on a particular {@link Scheduler}.
*
* @param the target type * @param completableSource the CompletableSource to convert from * @return the new Maybe instance * @throws NullPointerException if completable is null */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromCompletable(CompletableSource completableSource) { ObjectHelper.requireNonNull(completableSource, "completableSource is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFromCompletable(completableSource)); } /** * Wraps a SingleSource into a Maybe. * *
*
Scheduler:
*
{@code fromSingle} does not operate by default on a particular {@link Scheduler}.
*
* @param the target type * @param singleSource the SingleSource to convert from * @return the new Maybe instance * @throws NullPointerException if single is null */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromSingle(SingleSource singleSource) { ObjectHelper.requireNonNull(singleSource, "singleSource is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFromSingle(singleSource)); } /** * Returns a {@link Maybe} that invokes passed function and emits its result for each new MaybeObserver that subscribes * while considering {@code null} value from the callable as indication for valueless completion. *

* Allows you to defer execution of passed function until MaybeObserver subscribes to the {@link Maybe}. * It makes passed function "lazy". * Result of the function invocation will be emitted by the {@link Maybe}. *

*
Scheduler:
*
{@code fromCallable} does not operate by default on a particular {@link Scheduler}.
*
* * @param callable * function which execution should be deferred, it will be invoked when MaybeObserver will subscribe to the {@link Maybe}. * @param * the type of the item emitted by the {@link Maybe}. * @return a {@link Maybe} whose {@link MaybeObserver}s' subscriptions trigger an invocation of the given function. */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromCallable(final Callable callable) { ObjectHelper.requireNonNull(callable, "callable is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFromCallable(callable)); } /** * Converts a {@link Future} into a Maybe, treating a null result as an indication of emptiness. *

* *

* You can convert any object that supports the {@link Future} interface into a Maybe that emits the * return value of the {@link Future#get} method of that object, by passing the object into the {@code from} * method. *

* Important note: This Maybe is blocking; you cannot dispose it. *

* Unlike 1.x, cancelling the Maybe won't cancel the future. If necessary, one can use composition to achieve the * cancellation effect: {@code futureMaybe.doOnDispose(() -> future.cancel(true));}. *

*
Scheduler:
*
{@code fromFuture} does not operate by default on a particular {@link Scheduler}.
*
* * @param future * the source {@link Future} * @param * the type of object that the {@link Future} returns, and also the type of item to be emitted by * the resulting Maybe * @return a Maybe that emits the item from the source {@link Future} * @see ReactiveX operators documentation: From */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromFuture(Future future) { ObjectHelper.requireNonNull(future, "future is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFromFuture(future, 0L, null)); } /** * Converts a {@link Future} into a Maybe, with a timeout on the Future. *

* *

* You can convert any object that supports the {@link Future} interface into a Maybe that emits the * return value of the {@link Future#get} method of that object, by passing the object into the {@code fromFuture} * method. *

* Unlike 1.x, cancelling the Maybe won't cancel the future. If necessary, one can use composition to achieve the * cancellation effect: {@code futureMaybe.doOnCancel(() -> future.cancel(true));}. *

* Important note: This Maybe is blocking on the thread it gets subscribed on; you cannot dispose it. *

*
Scheduler:
*
{@code fromFuture} does not operate by default on a particular {@link Scheduler}.
*
* * @param future * the source {@link Future} * @param timeout * the maximum time to wait before calling {@code get} * @param unit * the {@link TimeUnit} of the {@code timeout} argument * @param * the type of object that the {@link Future} returns, and also the type of item to be emitted by * the resulting Maybe * @return a Maybe that emits the item from the source {@link Future} * @see ReactiveX operators documentation: From */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromFuture(Future future, long timeout, TimeUnit unit) { ObjectHelper.requireNonNull(future, "future is null"); ObjectHelper.requireNonNull(unit, "unit is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFromFuture(future, timeout, unit)); } /** * Returns a Maybe instance that runs the given Action for each subscriber and * emits either its exception or simply completes. *
*
Scheduler:
*
{@code fromRunnable} does not operate by default on a particular {@link Scheduler}.
*
* @param the target type * @param run the runnable to run for each subscriber * @return the new Maybe instance * @throws NullPointerException if run is null */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe fromRunnable(final Runnable run) { ObjectHelper.requireNonNull(run, "run is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFromRunnable(run)); } /** * Returns a {@code Maybe} that emits a specified item. *

* *

* To convert any object into a {@code Maybe} that emits that object, pass that object into the * {@code just} method. *

*
Scheduler:
*
{@code just} does not operate by default on a particular {@link Scheduler}.
*
* * @param item * the item to emit * @param * the type of that item * @return a {@code Maybe} that emits {@code item} * @see ReactiveX operators documentation: Just */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe just(T item) { ObjectHelper.requireNonNull(item, "item is null"); return RxJavaObservablePlugins.onAssembly(new MaybeJust(item)); } /** * Merges an Iterable sequence of MaybeSource instances into a single Observable sequence, * running all MaybeSources at once. *
*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
* @param the common and resulting value type * @param sources the Iterable sequence of MaybeSource sources * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable merge(Iterable> sources) { return merge(Observable.fromIterable(sources)); } /** * Merges an Observable sequence of MaybeSource instances into a single Observable sequence, * running all MaybeSources at once. *
*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
* @param the common and resulting value type * @param sources the Observable sequence of MaybeSource sources * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable merge(ObservableSource> sources) { return merge(sources, Integer.MAX_VALUE); } /** * Merges an Observable sequence of MaybeSource instances into a single Observable sequence, * running at most maxConcurrency MaybeSources at once. *
*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
* @param the common and resulting value type * @param sources the Observable sequence of MaybeSource sources * @param maxConcurrency the maximum number of concurrently running MaybeSources * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings({ "unchecked", "rawtypes" }) public static Observable merge(ObservableSource> sources, int maxConcurrency) { ObjectHelper.requireNonNull(sources, "source is null"); ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency"); return RxJavaObservablePlugins.onAssembly(new ObservableFlatMap(sources, MaybeToObservable.instance(), false, maxConcurrency, Observable.bufferSize())); } /** * Flattens a {@code MaybeSource} that emits a {@code MaybeSource} into a single {@code MaybeSource} that emits the item * emitted by the nested {@code MaybeSource}, without any transformation. *

* *

*

*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the sources and the output * @param source * a {@code MaybeSource} that emits a {@code MaybeSource} * @return a {@code Maybe} that emits the item that is the result of flattening the {@code MaybeSource} emitted * by {@code source} * @see ReactiveX operators documentation: Merge */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings({ "unchecked", "rawtypes" }) public static Maybe merge(MaybeSource> source) { ObjectHelper.requireNonNull(source, "source is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFlatten(source, Functions.identity())); } /** * Flattens two MaybeSources into a single Observable, without any transformation. *

* *

* You can combine items emitted by multiple MaybeSources so that they appear as a single Observable, by * using the {@code merge} method. *

*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common value type * @param source1 * a MaybeSource to be merged * @param source2 * a MaybeSource to be merged * @return an Observable that emits all of the items emitted by the source MaybeSources * @see ReactiveX operators documentation: Merge */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Observable merge( MaybeSource source1, MaybeSource source2 ) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); return mergeArray(source1, source2); } /** * Flattens three MaybeSources into a single Observable, without any transformation. *

* *

* You can combine items emitted by multiple MaybeSources so that they appear as a single Observable, by using * the {@code merge} method. *

*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common value type * @param source1 * a MaybeSource to be merged * @param source2 * a MaybeSource to be merged * @param source3 * a MaybeSource to be merged * @return an Observable that emits all of the items emitted by the source MaybeSources * @see ReactiveX operators documentation: Merge */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Observable merge( MaybeSource source1, MaybeSource source2, MaybeSource source3 ) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); return mergeArray(source1, source2, source3); } /** * Flattens four MaybeSources into a single Observable, without any transformation. *

* *

* You can combine items emitted by multiple MaybeSources so that they appear as a single Observable, by using * the {@code merge} method. *

*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common value type * @param source1 * a MaybeSource to be merged * @param source2 * a MaybeSource to be merged * @param source3 * a MaybeSource to be merged * @param source4 * a MaybeSource to be merged * @return an Observable that emits all of the items emitted by the source MaybeSources * @see ReactiveX operators documentation: Merge */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Observable merge( MaybeSource source1, MaybeSource source2, MaybeSource source3, MaybeSource source4 ) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); return mergeArray(source1, source2, source3, source4); } /** * Merges an array sequence of MaybeSource instances into a single Observable sequence, * running all MaybeSources at once. *
*
Scheduler:
*
{@code mergeArray} does not operate by default on a particular {@link Scheduler}.
*
* @param the common and resulting value type * @param sources the array sequence of MaybeSource sources * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Observable mergeArray(MaybeSource... sources) { ObjectHelper.requireNonNull(sources, "sources is null"); if (sources.length == 0) { return Observable.empty(); } if (sources.length == 1) { return RxJavaObservablePlugins.onAssembly(new MaybeToObservable((MaybeSource)sources[0])); } return RxJavaObservablePlugins.onAssembly(new MaybeMergeArray(sources)); } /** * Flattens an array of MaybeSources into one Observable, in a way that allows an Observer to receive all * successfully emitted items from each of the source MaybeSources without being interrupted by an error * notification from one of them. *

* This behaves like {@link #mergeArray(MaybeSource...)} except that if any of the merged MaybeSources notify of an * error via {@link MaybeObserver#onError onError}, {@code mergeDelayError} will refrain from propagating that * error notification until all of the merged MaybeSources have finished emitting items. *

* *

* Even if multiple merged MaybeSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeArrayDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources * the Iterable of MaybeSources * @return an Observable that emits items that are the result of flattening the items emitted by the * MaybeSources in the Iterable * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeArrayDelayError(MaybeSource... sources) { if (sources.length == 0) { return Observable.empty(); } return Observable.fromArray(sources).flatMap((Function)MaybeToObservable.instance(), true, sources.length); } /** * Flattens an Iterable of MaybeSources into one Observable, in a way that allows an Observer to receive all * successfully emitted items from each of the source MaybeSources without being interrupted by an error * notification from one of them. *

* This behaves like {@link #merge(Iterable)} except that if any of the merged MaybeSources notify of an * error via {@link MaybeObserver#onError onError}, {@code mergeDelayError} will refrain from propagating that * error notification until all of the merged MaybeSources have finished emitting items. *

* *

* Even if multiple merged MaybeSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources * the Iterable of MaybeSources * @return an Observable that emits items that are the result of flattening the items emitted by the * MaybeSources in the Iterable * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeDelayError(Iterable> sources) { return Observable.fromIterable(sources).flatMap((Function)MaybeToObservable.instance(), true); } /** * Flattens an ObservableSource that emits MaybeSources into one ObservableSource, in a way that allows an Observer to * receive all successfully emitted items from all of the source ObservableSources without being interrupted by * an error notification from one of them. *

* This behaves like {@link #merge(ObservableSource)} except that if any of the merged ObservableSources notify of an * error via {@link MaybeObserver#onError onError}, {@code mergeDelayError} will refrain from propagating that * error notification until all of the merged ObservableSources have finished emitting items. *

* *

* Even if multiple merged ObservableSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources * an ObservableSource that emits MaybeSources * @return an Observable that emits all of the items emitted by the ObservableSources emitted by the * {@code source} ObservableSource * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeDelayError(ObservableSource> sources) { return Observable.wrap(sources).flatMap((Function)MaybeToObservable.instance(), true); } /** * Flattens two MaybeSources into one Observable, in a way that allows an Observer to receive all * successfully emitted items from each of the source MaybeSources without being interrupted by an error * notification from one of them. *

* This behaves like {@link #merge(MaybeSource, MaybeSource)} except that if any of the merged MaybeSources * notify of an error via {@link MaybeObserver#onError onError}, {@code mergeDelayError} will refrain from * propagating that error notification until all of the merged MaybeSources have finished emitting items. *

* *

* Even if both merged MaybeSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param source1 * a MaybeSource to be merged * @param source2 * a MaybeSource to be merged * @return an Observable that emits all of the items that are emitted by the two source MaybeSources * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeDelayError(MaybeSource source1, MaybeSource source2) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); return mergeArrayDelayError(source1, source2); } /** * Flattens three MaybeSource into one Observable, in a way that allows an Observer to receive all * successfully emitted items from all of the source MaybeSources without being interrupted by an error * notification from one of them. *

* This behaves like {@link #merge(MaybeSource, MaybeSource, MaybeSource)} except that if any of the merged * MaybeSources notify of an error via {@link MaybeObserver#onError onError}, {@code mergeDelayError} will refrain * from propagating that error notification until all of the merged MaybeSources have finished emitting * items. *

* *

* Even if multiple merged MaybeSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param source1 * a MaybeSource to be merged * @param source2 * a MaybeSource to be merged * @param source3 * a MaybeSource to be merged * @return an Observable that emits all of the items that are emitted by the source MaybeSources * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeDelayError(MaybeSource source1, MaybeSource source2, MaybeSource source3) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); return mergeArrayDelayError(source1, source2, source3); } /** * Flattens four MaybeSources into one Observable, in a way that allows an Observer to receive all * successfully emitted items from all of the source MaybeSources without being interrupted by an error * notification from one of them. *

* This behaves like {@link #merge(MaybeSource, MaybeSource, MaybeSource, MaybeSource)} except that if any of * the merged MaybeSources notify of an error via {@link MaybeObserver#onError onError}, {@code mergeDelayError} * will refrain from propagating that error notification until all of the merged MaybeSources have finished * emitting items. *

* *

* Even if multiple merged MaybeSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param source1 * a MaybeSource to be merged * @param source2 * a MaybeSource to be merged * @param source3 * a MaybeSource to be merged * @param source4 * a MaybeSource to be merged * @return an Observable that emits all of the items that are emitted by the source MaybeSources * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeDelayError( MaybeSource source1, MaybeSource source2, MaybeSource source3, MaybeSource source4) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); return mergeArrayDelayError(source1, source2, source3, source4); } /** * Returns a Maybe that never sends any items or notifications to a {@link MaybeObserver}. *

* *

* This Maybe is useful primarily for testing purposes. *

*
Scheduler:
*
{@code never} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items (not) emitted by the Maybe * @return a Maybe that never emits any items or sends any notifications to a {@link MaybeObserver} * @see ReactiveX operators documentation: Never */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Maybe never() { return RxJavaObservablePlugins.onAssembly((Maybe)MaybeNever.INSTANCE); } /** * Returns a Single that emits a Boolean value that indicates whether two MaybeSource sequences are the * same by comparing the items emitted by each MaybeSource pairwise. *

* *

*
Scheduler:
*
{@code sequenceEqual} does not operate by default on a particular {@link Scheduler}.
*
* * @param source1 * the first MaybeSource to compare * @param source2 * the second MaybeSource to compare * @param * the type of items emitted by each MaybeSource * @return a Single that emits a Boolean value that indicates whether the two sequences are the same * @see ReactiveX operators documentation: SequenceEqual */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Single sequenceEqual(MaybeSource source1, MaybeSource source2) { return sequenceEqual(source1, source2, ObjectHelper.equalsPredicate()); } /** * Returns a Single that emits a Boolean value that indicates whether two MaybeSources are the * same by comparing the items emitted by each MaybeSource pairwise based on the results of a specified * equality function. *

* *

*
Scheduler:
*
{@code sequenceEqual} does not operate by default on a particular {@link Scheduler}.
*
* * @param source1 * the first MaybeSource to compare * @param source2 * the second MaybeSource to compare * @param isEqual * a function used to compare items emitted by each MaybeSource * @param * the type of items emitted by each MaybeSource * @return a Single that emits a Boolean value that indicates whether the two MaybeSource sequences * are the same according to the specified function * @see ReactiveX operators documentation: SequenceEqual */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Single sequenceEqual(MaybeSource source1, MaybeSource source2, BiPredicate isEqual) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(isEqual, "isEqual is null"); return RxJavaObservablePlugins.onAssembly(new MaybeEqualSingle(source1, source2, isEqual)); } /** * Returns a Maybe that emits {@code 0L} after a specified delay. *

* *

*
Scheduler:
*
{@code timer} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param delay * the initial delay before emitting a single {@code 0L} * @param unit * time units to use for {@code delay} * @return a Maybe that emits {@code 0L} after a specified delay * @see ReactiveX operators documentation: Timer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public static Maybe timer(long delay, TimeUnit unit) { return timer(delay, unit, Schedulers.computation()); } /** * Returns a Maybe that emits {@code 0L} after a specified delay on a specified Scheduler. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use
*
* * @param delay * the initial delay before emitting a single 0L * @param unit * time units to use for {@code delay} * @param scheduler * the {@link Scheduler} to use for scheduling the item * @return a Maybe that emits {@code 0L} after a specified delay, on a specified Scheduler * @see ReactiveX operators documentation: Timer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public static Maybe timer(long delay, TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaObservablePlugins.onAssembly(new MaybeTimer(Math.max(0L, delay), unit, scheduler)); } /** * Advanced use only: creates a Maybe instance without * any safeguards by using a callback that is called with a MaybeObserver. *
*
Scheduler:
*
{@code unsafeCreate} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param onSubscribe the function that is called with the subscribing MaybeObserver * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe unsafeCreate(MaybeSource onSubscribe) { if (onSubscribe instanceof Maybe) { throw new IllegalArgumentException("unsafeCreate(Maybe) should be upgraded"); } ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null"); return RxJavaObservablePlugins.onAssembly(new MaybeUnsafeCreate(onSubscribe)); } /** * Constructs a Maybe that creates a dependent resource object which is disposed of when the * upstream terminates or the downstream calls dispose(). *

* *

*
Scheduler:
*
{@code using} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the generated MaybeSource * @param the type of the resource associated with the output sequence * @param resourceSupplier * the factory function to create a resource object that depends on the Maybe * @param sourceSupplier * the factory function to create a MaybeSource * @param resourceDisposer * the function that will dispose of the resource * @return the Maybe whose lifetime controls the lifetime of the dependent resource object * @see ReactiveX operators documentation: Using */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe using(Callable resourceSupplier, Function> sourceSupplier, Consumer resourceDisposer) { return using(resourceSupplier, sourceSupplier, resourceDisposer, true); } /** * Constructs a Maybe that creates a dependent resource object which is disposed of just before * termination if you have set {@code disposeEagerly} to {@code true} and a downstream dispose() does not occur * before termination. Otherwise resource disposal will occur on call to dispose(). Eager disposal is * particularly appropriate for a synchronous Maybe that reuses resources. {@code disposeAction} will * only be called once per subscription. *

* *

*
Scheduler:
*
{@code using} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the generated MaybeSource * @param the type of the resource associated with the output sequence * @param resourceSupplier * the factory function to create a resource object that depends on the Maybe * @param sourceSupplier * the factory function to create a MaybeSource * @param resourceDisposer * the function that will dispose of the resource * @param eager * if {@code true} then disposal will happen either on a dispose() call or just before emission of * a terminal event ({@code onComplete} or {@code onError}). * @return the Maybe whose lifetime controls the lifetime of the dependent resource object * @see ReactiveX operators documentation: Using */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe using(Callable resourceSupplier, Function> sourceSupplier, Consumer resourceDisposer, boolean eager) { ObjectHelper.requireNonNull(resourceSupplier, "resourceSupplier is null"); ObjectHelper.requireNonNull(sourceSupplier, "sourceSupplier is null"); ObjectHelper.requireNonNull(resourceDisposer, "disposer is null"); return RxJavaObservablePlugins.onAssembly(new MaybeUsing(resourceSupplier, sourceSupplier, resourceDisposer, eager)); } /** * Wraps a MaybeSource instance into a new Maybe instance if not already a Maybe * instance. *
*
Scheduler:
*
{@code wrap} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param source the source to wrap * @return the Maybe wrapper or the source cast to Maybe (if possible) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe wrap(MaybeSource source) { if (source instanceof Maybe) { return RxJavaObservablePlugins.onAssembly((Maybe)source); } ObjectHelper.requireNonNull(source, "onSubscribe is null"); return RxJavaObservablePlugins.onAssembly(new MaybeUnsafeCreate(source)); } /** * Returns a Maybe that emits the results of a specified combiner function applied to combinations of * items emitted, in sequence, by an Iterable of other MaybeSources. *

* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. * *

* *

This operator terminates eagerly if any of the source MaybeSources signal an onError or onComplete. This * also means it is possible some sources may not get subscribed to at all. *

*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common value type * @param the zipped result type * @param sources * an Iterable of source MaybeSources * @param zipper * a function that, when applied to an item emitted by each of the source MaybeSources, results in * an item that will be emitted by the resulting Maybe * @return a Maybe that emits the zipped results * @see ReactiveX operators documentation: Zip */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip(Iterable> sources, Function zipper) { ObjectHelper.requireNonNull(zipper, "zipper is null"); ObjectHelper.requireNonNull(sources, "sources is null"); return RxJavaObservablePlugins.onAssembly(new MaybeZipIterable(sources, zipper)); } /** * Returns a Maybe that emits the results of a specified combiner function applied to combinations of * two items emitted, in sequence, by two other MaybeSources. *

* *

This operator terminates eagerly if any of the source MaybeSources signal an onError or onComplete. This * also means it is possible some sources may not get subscribed to at all. *

*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the zipped result type * @param source1 * the first source MaybeSource * @param source2 * a second source MaybeSource * @param zipper * a function that, when applied to an item emitted by each of the source MaybeSources, results * in an item that will be emitted by the resulting Maybe * @return a Maybe that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, BiFunction zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); return zipArray(Functions.toFunction(zipper), source1, source2); } /** * Returns a Maybe that emits the results of a specified combiner function applied to combinations of * three items emitted, in sequence, by three other MaybeSources. *

* *

This operator terminates eagerly if any of the source MaybeSources signal an onError or onComplete. This * also means it is possible some sources may not get subscribed to at all. *

*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the zipped result type * @param source1 * the first source MaybeSource * @param source2 * a second source MaybeSource * @param source3 * a third source MaybeSource * @param zipper * a function that, when applied to an item emitted by each of the source MaybeSources, results in * an item that will be emitted by the resulting Maybe * @return a Maybe that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, Function3 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); return zipArray(Functions.toFunction(zipper), source1, source2, source3); } /** * Returns a Maybe that emits the results of a specified combiner function applied to combinations of * four items emitted, in sequence, by four other MaybeSources. *

* *

This operator terminates eagerly if any of the source MaybeSources signal an onError or onComplete. This * also means it is possible some sources may not get subscribed to at all. *

*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the value type of the fourth source * @param the zipped result type * @param source1 * the first source MaybeSource * @param source2 * a second source MaybeSource * @param source3 * a third source MaybeSource * @param source4 * a fourth source MaybeSource * @param zipper * a function that, when applied to an item emitted by each of the source MaybeSources, results in * an item that will be emitted by the resulting Maybe * @return a Maybe that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, MaybeSource source4, Function4 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); return zipArray(Functions.toFunction(zipper), source1, source2, source3, source4); } /** * Returns a Maybe that emits the results of a specified combiner function applied to combinations of * five items emitted, in sequence, by five other MaybeSources. *

* *

This operator terminates eagerly if any of the source MaybeSources signal an onError or onComplete. This * also means it is possible some sources may not get subscribed to at all. *

*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the value type of the fourth source * @param the value type of the fifth source * @param the zipped result type * @param source1 * the first source MaybeSource * @param source2 * a second source MaybeSource * @param source3 * a third source MaybeSource * @param source4 * a fourth source MaybeSource * @param source5 * a fifth source MaybeSource * @param zipper * a function that, when applied to an item emitted by each of the source MaybeSources, results in * an item that will be emitted by the resulting Maybe * @return a Maybe that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, MaybeSource source4, MaybeSource source5, Function5 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); return zipArray(Functions.toFunction(zipper), source1, source2, source3, source4, source5); } /** * Returns a Maybe that emits the results of a specified combiner function applied to combinations of * six items emitted, in sequence, by six other MaybeSources. *

* *

This operator terminates eagerly if any of the source MaybeSources signal an onError or onComplete. This * also means it is possible some sources may not get subscribed to at all. *

*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the value type of the fourth source * @param the value type of the fifth source * @param the value type of the sixth source * @param the zipped result type * @param source1 * the first source MaybeSource * @param source2 * a second source MaybeSource * @param source3 * a third source MaybeSource * @param source4 * a fourth source MaybeSource * @param source5 * a fifth source MaybeSource * @param source6 * a sixth source MaybeSource * @param zipper * a function that, when applied to an item emitted by each of the source MaybeSources, results in * an item that will be emitted by the resulting Maybe * @return a Maybe that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, MaybeSource source4, MaybeSource source5, MaybeSource source6, Function6 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); ObjectHelper.requireNonNull(source6, "source6 is null"); return zipArray(Functions.toFunction(zipper), source1, source2, source3, source4, source5, source6); } /** * Returns a Maybe that emits the results of a specified combiner function applied to combinations of * seven items emitted, in sequence, by seven other MaybeSources. *

* *

This operator terminates eagerly if any of the source MaybeSources signal an onError or onComplete. This * also means it is possible some sources may not get subscribed to at all. *

*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the value type of the fourth source * @param the value type of the fifth source * @param the value type of the sixth source * @param the value type of the seventh source * @param the zipped result type * @param source1 * the first source MaybeSource * @param source2 * a second source MaybeSource * @param source3 * a third source MaybeSource * @param source4 * a fourth source MaybeSource * @param source5 * a fifth source MaybeSource * @param source6 * a sixth source MaybeSource * @param source7 * a seventh source MaybeSource * @param zipper * a function that, when applied to an item emitted by each of the source MaybeSources, results in * an item that will be emitted by the resulting Maybe * @return a Maybe that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, MaybeSource source4, MaybeSource source5, MaybeSource source6, MaybeSource source7, Function7 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); ObjectHelper.requireNonNull(source6, "source6 is null"); ObjectHelper.requireNonNull(source7, "source7 is null"); return zipArray(Functions.toFunction(zipper), source1, source2, source3, source4, source5, source6, source7); } /** * Returns a Maybe that emits the results of a specified combiner function applied to combinations of * eight items emitted, in sequence, by eight other MaybeSources. *

* *

This operator terminates eagerly if any of the source MaybeSources signal an onError or onComplete. This * also means it is possible some sources may not get subscribed to at all. *

*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the value type of the fourth source * @param the value type of the fifth source * @param the value type of the sixth source * @param the value type of the seventh source * @param the value type of the eighth source * @param the zipped result type * @param source1 * the first source MaybeSource * @param source2 * a second source MaybeSource * @param source3 * a third source MaybeSource * @param source4 * a fourth source MaybeSource * @param source5 * a fifth source MaybeSource * @param source6 * a sixth source MaybeSource * @param source7 * a seventh source MaybeSource * @param source8 * an eighth source MaybeSource * @param zipper * a function that, when applied to an item emitted by each of the source MaybeSources, results in * an item that will be emitted by the resulting Maybe * @return a Maybe that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, MaybeSource source4, MaybeSource source5, MaybeSource source6, MaybeSource source7, MaybeSource source8, Function8 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); ObjectHelper.requireNonNull(source6, "source6 is null"); ObjectHelper.requireNonNull(source7, "source7 is null"); ObjectHelper.requireNonNull(source8, "source8 is null"); return zipArray(Functions.toFunction(zipper), source1, source2, source3, source4, source5, source6, source7, source8); } /** * Returns a Maybe that emits the results of a specified combiner function applied to combinations of * nine items emitted, in sequence, by nine other MaybeSources. *

* *

*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
*

This operator terminates eagerly if any of the source MaybeSources signal an onError or onComplete. This * also means it is possible some sources may not get subscribed to at all. * * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the value type of the fourth source * @param the value type of the fifth source * @param the value type of the sixth source * @param the value type of the seventh source * @param the value type of the eighth source * @param the value type of the ninth source * @param the zipped result type * @param source1 * the first source MaybeSource * @param source2 * a second source MaybeSource * @param source3 * a third source MaybeSource * @param source4 * a fourth source MaybeSource * @param source5 * a fifth source MaybeSource * @param source6 * a sixth source MaybeSource * @param source7 * a seventh source MaybeSource * @param source8 * an eighth source MaybeSource * @param source9 * a ninth source MaybeSource * @param zipper * a function that, when applied to an item emitted by each of the source MaybeSources, results in * an item that will be emitted by the resulting MaybeSource * @return a Maybe that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zip( MaybeSource source1, MaybeSource source2, MaybeSource source3, MaybeSource source4, MaybeSource source5, MaybeSource source6, MaybeSource source7, MaybeSource source8, MaybeSource source9, Function9 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); ObjectHelper.requireNonNull(source6, "source6 is null"); ObjectHelper.requireNonNull(source7, "source7 is null"); ObjectHelper.requireNonNull(source8, "source8 is null"); ObjectHelper.requireNonNull(source9, "source9 is null"); return zipArray(Functions.toFunction(zipper), source1, source2, source3, source4, source5, source6, source7, source8, source9); } /** * Returns a Maybe that emits the results of a specified combiner function applied to combinations of * items emitted, in sequence, by an array of other MaybeSources. *

* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. * *

* *

This operator terminates eagerly if any of the source MaybeSources signal an onError or onComplete. This * also means it is possible some sources may not get subscribed to at all. *

*
Scheduler:
*
{@code zipArray} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element type * @param the result type * @param sources * an array of source MaybeSources * @param zipper * a function that, when applied to an item emitted by each of the source MaybeSources, results in * an item that will be emitted by the resulting MaybeSource * @return a Maybe that emits the zipped results * @see ReactiveX operators documentation: Zip */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Maybe zipArray(Function zipper, MaybeSource... sources) { ObjectHelper.requireNonNull(sources, "sources is null"); if (sources.length == 0) { return empty(); } ObjectHelper.requireNonNull(zipper, "zipper is null"); return RxJavaObservablePlugins.onAssembly(new MaybeZipArray(sources, zipper)); } // ------------------------------------------------------------------ // Instance methods // ------------------------------------------------------------------ /** * Mirrors the MaybeSource (current or provided) that first signals an event. *

* *

*
Scheduler:
*
{@code ambWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param other * a MaybeSource competing to react first. A subscription to this provided source will occur after * subscribing to the current source. * @return a Maybe that emits the same sequence as whichever of the source MaybeSources first * signalled * @see ReactiveX operators documentation: Amb */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe ambWith(MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); return ambArray(this, other); } /** * Waits in a blocking fashion until the current Maybe signals a success value (which is returned), * null if completed or an exception (which is propagated). *
*
Scheduler:
*
{@code blockingGet} does not operate by default on a particular {@link Scheduler}.
*
* @return the success value */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final T blockingGet() { BlockingMultiObserver observer = new BlockingMultiObserver(); subscribe(observer); return observer.blockingGet(); } /** * Waits in a blocking fashion until the current Maybe signals a success value (which is returned), * defaultValue if completed or an exception (which is propagated). *
*
Scheduler:
*
{@code blockingGet} does not operate by default on a particular {@link Scheduler}.
*
* @param defaultValue the default item to return if this Maybe is empty * @return the success value */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final T blockingGet(T defaultValue) { ObjectHelper.requireNonNull(defaultValue, "defaultValue is null"); BlockingMultiObserver observer = new BlockingMultiObserver(); subscribe(observer); return observer.blockingGet(defaultValue); } /** * Returns a Maybe that subscribes to this Maybe lazily, caches its event * and replays it, to all the downstream subscribers. *

* *

* The operator subscribes only when the first downstream subscriber subscribes and maintains * a single subscription towards this Maybe. *

* Note: You sacrifice the ability to dispose the origin when you use the {@code cache}. *

*
Scheduler:
*
{@code cache} does not operate by default on a particular {@link Scheduler}.
*
* * @return a Maybe that, when first subscribed to, caches all of its items and notifications for the * benefit of subsequent subscribers * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe cache() { return RxJavaObservablePlugins.onAssembly(new MaybeCache(this)); } /** * Casts the success value of the current Maybe into the target type or signals a * ClassCastException if not compatible. *
*
Scheduler:
*
{@code cast} does not operate by default on a particular {@link Scheduler}.
*
* @param the target type * @param clazz the type token to use for casting the success result from the current Maybe * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe cast(final Class clazz) { ObjectHelper.requireNonNull(clazz, "clazz is null"); return map(Functions.castFunction(clazz)); } /** * Transform a Maybe by applying a particular Transformer function to it. *

* This method operates on the Maybe itself whereas {@link #lift} operates on the Maybe's MaybeObservers. *

* If the operator you are creating is designed to act on the individual item emitted by a Maybe, use * {@link #lift}. If your operator is designed to transform the source Maybe as a whole (for instance, by * applying a particular set of existing RxJava operators to it) use {@code compose}. *

*
Scheduler:
*
{@code compose} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the Maybe returned by the transformer function * @param transformer the transformer function, not null * @return a Maybe, transformed by the transformer function * @see RxJava wiki: Implementing Your Own Operators */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe compose(MaybeTransformer transformer) { return wrap(((MaybeTransformer) ObjectHelper.requireNonNull(transformer, "transformer is null")).apply(this)); } /** * Returns a Maybe that is based on applying a specified function to the item emitted by the source Maybe, * where that function returns a MaybeSource. *

* *

*
Scheduler:
*
{@code concatMap} does not operate by default on a particular {@link Scheduler}.
*
*

Note that flatMap and concatMap for Maybe is the same operation. * @param the result value type * @param mapper * a function that, when applied to the item emitted by the source Maybe, returns a MaybeSource * @return the Maybe returned from {@code func} when applied to the item emitted by the source Maybe * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe concatMap(Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFlatten(this, mapper)); } /** * Returns an Observable that emits the items emitted from the current MaybeSource, then the next, one after * the other, without interleaving them. *

* *

*
Scheduler:
*
{@code concatWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param other * a MaybeSource to be concatenated after the current * @return an Observable that emits items emitted by the two source MaybeSources, one after the other, * without interleaving them * @see ReactiveX operators documentation: Concat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatWith(MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); return concat(this, other); } /** * Returns a Single that emits a Boolean that indicates whether the source Maybe emitted a * specified item. *

* *

*
Scheduler:
*
{@code contains} does not operate by default on a particular {@link Scheduler}.
*
* * @param item * the item to search for in the emissions from the source Maybe, not null * @return a Single that emits {@code true} if the specified item is emitted by the source Maybe, * or {@code false} if the source Maybe completes without emitting that item * @see ReactiveX operators documentation: Contains */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single contains(final Object item) { ObjectHelper.requireNonNull(item, "item is null"); return RxJavaObservablePlugins.onAssembly(new MaybeContains(this, item)); } /** * Returns a Maybe that counts the total number of items emitted (0 or 1) by the source Maybe and emits * this count as a 64-bit Long. *

* *

*
Scheduler:
*
{@code count} does not operate by default on a particular {@link Scheduler}.
*
* * @return a Single that emits a single item: the number of items emitted by the source Maybe as a * 64-bit Long item * @see ReactiveX operators documentation: Count * @see #count() */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single count() { return RxJavaObservablePlugins.onAssembly(new MaybeCount(this)); } /** * Returns a Maybe that emits the item emitted by the source Maybe or a specified default item * if the source Maybe is empty. *

* *

*
Scheduler:
*
{@code defaultIfEmpty} does not operate by default on a particular {@link Scheduler}.
*
* * @param defaultItem * the item to emit if the source Maybe emits no items * @return a Maybe that emits either the specified default item if the source Maybe emits no * items, or the items emitted by the source Maybe * @see ReactiveX operators documentation: DefaultIfEmpty */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe defaultIfEmpty(T defaultItem) { ObjectHelper.requireNonNull(defaultItem, "item is null"); return switchIfEmpty(just(defaultItem)); } /** * Returns a Maybe that signals the events emitted by the source Maybe shifted forward in time by a * specified delay. *

* *

*
Scheduler:
*
This version of {@code delay} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param delay * the delay to shift the source by * @param unit * the {@link TimeUnit} in which {@code period} is defined * @return the new Maybe instance * @see ReactiveX operators documentation: Delay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Maybe delay(long delay, TimeUnit unit) { return delay(delay, unit, Schedulers.computation()); } /** * Returns a Maybe that signals the events emitted by the source Maybe shifted forward in time by a * specified delay running on the specified Scheduler. *

* *

*
Scheduler:
*
you specify which {@link Scheduler} this operator will use
*
* * @param delay * the delay to shift the source by * @param unit * the time unit of {@code delay} * @param scheduler * the {@link Scheduler} to use for delaying * @return the new Maybe instance * @see ReactiveX operators documentation: Delay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Maybe delay(long delay, TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaObservablePlugins.onAssembly(new MaybeDelay(this, Math.max(0L, delay), unit, scheduler)); } /** * Delays the emission of this Maybe until the given ObservableSource signals an item or completes. *

* *

*

*
Scheduler:
*
This version of {@code delay} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the subscription delay value type (ignored) * @param * the item delay value type (ignored) * @param delayIndicator * the ObservableSource that gets subscribed to when this Maybe signals an event and that * signal is emitted when the ObservableSource signals an item or completes * @return the new Maybe instance * @see ReactiveX operators documentation: Delay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe delay(ObservableSource delayIndicator) { ObjectHelper.requireNonNull(delayIndicator, "delayIndicator is null"); return RxJavaObservablePlugins.onAssembly(new MaybeDelayOtherObservable(this, delayIndicator)); } /** * Returns a Maybe that delays the subscription to this Maybe * until the other ObservableSource emits an element or completes normally. *

*

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the other ObservableSource, irrelevant * @param subscriptionIndicator the other ObservableSource that should trigger the subscription * to this ObservableSource. * @return a Maybe that delays the subscription to this Maybe * until the other ObservableSource emits an element or completes normally. */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe delaySubscription(ObservableSource subscriptionIndicator) { ObjectHelper.requireNonNull(subscriptionIndicator, "subscriptionIndicator is null"); return RxJavaObservablePlugins.onAssembly(new MaybeDelaySubscriptionOtherObservable(this, subscriptionIndicator)); } /** * Returns a Maybe that delays the subscription to the source Maybe by a given amount of time. *

* *

*
Scheduler:
*
This version of {@code delaySubscription} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param delay * the time to delay the subscription * @param unit * the time unit of {@code delay} * @return a Maybe that delays the subscription to the source Maybe by the given amount * @see ReactiveX operators documentation: Delay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Maybe delaySubscription(long delay, TimeUnit unit) { return delaySubscription(delay, unit, Schedulers.computation()); } /** * Returns a Maybe that delays the subscription to the source Maybe by a given amount of time, * both waiting and subscribing on a given Scheduler. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use
*
* * @param delay * the time to delay the subscription * @param unit * the time unit of {@code delay} * @param scheduler * the Scheduler on which the waiting and subscription will happen * @return a Maybe that delays the subscription to the source Maybe by a given * amount, waiting and subscribing on the given Scheduler * @see ReactiveX operators documentation: Delay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Maybe delaySubscription(long delay, TimeUnit unit, Scheduler scheduler) { return delaySubscription(Observable.timer(delay, unit, scheduler)); } /** * Calls the specified consumer with the success item after this item has been emitted to the downstream. *

Note that the {@code onAfterNext} action is shared between subscriptions and as such * should be thread-safe. *

*
Scheduler:
*
{@code doAfterSuccess} does not operate by default on a particular {@link Scheduler}.
*
* @param onAfterSuccess the Consumer that will be called after emitting an item from upstream to the downstream * @return the new Maybe instance * @since 2.0.1 - experimental */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @Experimental public final Maybe doAfterSuccess(Consumer onAfterSuccess) { ObjectHelper.requireNonNull(onAfterSuccess, "doAfterSuccess is null"); return RxJavaObservablePlugins.onAssembly(new MaybeDoAfterSuccess(this, onAfterSuccess)); } /** * Registers an {@link Action} to be called when this Maybe invokes either * {@link MaybeObserver#onComplete onSuccess}, * {@link MaybeObserver#onComplete onComplete} or {@link MaybeObserver#onError onError}. *

* *

*
Scheduler:
*
{@code doAfterTerminate} does not operate by default on a particular {@link Scheduler}.
*
* * @param onAfterTerminate * an {@link Action} to be invoked when the source Maybe finishes * @return a Maybe that emits the same items as the source Maybe, then invokes the * {@link Action} * @see ReactiveX operators documentation: Do */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doAfterTerminate(Action onAfterTerminate) { return RxJavaObservablePlugins.onAssembly(new MaybePeek(this, Functions.emptyConsumer(), // onSubscribe Functions.emptyConsumer(), // onSuccess Functions.emptyConsumer(), // onError Functions.EMPTY_ACTION, // onComplete ObjectHelper.requireNonNull(onAfterTerminate, "onAfterTerminate is null"), Functions.EMPTY_ACTION // dispose )); } /** * Calls the specified action after this Maybe signals onSuccess, onError or onComplete or gets disposed by * the downstream. *

In case of a race between a terminal event and a dispose call, the provided {@code onFinally} action * is executed once per subscription. *

Note that the {@code onFinally} action is shared between subscriptions and as such * should be thread-safe. *

*
Scheduler:
*
{@code doFinally} does not operate by default on a particular {@link Scheduler}.
*
* @param onFinally the action called when this Maybe terminates or gets cancelled * @return the new Maybe instance * @since 2.0.1 - experimental */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @Experimental public final Maybe doFinally(Action onFinally) { ObjectHelper.requireNonNull(onFinally, "onFinally is null"); return RxJavaObservablePlugins.onAssembly(new MaybeDoFinally(this, onFinally)); } /** * Calls the shared runnable if a MaybeObserver subscribed to the current Maybe * disposes the common Disposable it received via onSubscribe. *
*
Scheduler:
*
{@code doOnDispose} does not operate by default on a particular {@link Scheduler}.
*
* @param onDispose the runnable called when the subscription is cancelled (disposed) * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doOnDispose(Action onDispose) { return RxJavaObservablePlugins.onAssembly(new MaybePeek(this, Functions.emptyConsumer(), // onSubscribe Functions.emptyConsumer(), // onSuccess Functions.emptyConsumer(), // onError Functions.EMPTY_ACTION, // onComplete Functions.EMPTY_ACTION, // (onSuccess | onError | onComplete) after ObjectHelper.requireNonNull(onDispose, "onDispose is null") )); } /** * Modifies the source Maybe so that it invokes an action when it calls {@code onComplete}. *

* *

*
Scheduler:
*
{@code doOnComplete} does not operate by default on a particular {@link Scheduler}.
*
* * @param onComplete * the action to invoke when the source Maybe calls {@code onComplete} * @return the new Maybe with the side-effecting behavior applied * @see ReactiveX operators documentation: Do */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doOnComplete(Action onComplete) { return RxJavaObservablePlugins.onAssembly(new MaybePeek(this, Functions.emptyConsumer(), // onSubscribe Functions.emptyConsumer(), // onSuccess Functions.emptyConsumer(), // onError ObjectHelper.requireNonNull(onComplete, "onComplete is null"), Functions.EMPTY_ACTION, // (onSuccess | onError | onComplete) Functions.EMPTY_ACTION // dispose )); } /** * Calls the shared consumer with the error sent via onError for each * MaybeObserver that subscribes to the current Maybe. *
*
Scheduler:
*
{@code doOnError} does not operate by default on a particular {@link Scheduler}.
*
* @param onError the consumer called with the success value of onError * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doOnError(Consumer onError) { return RxJavaObservablePlugins.onAssembly(new MaybePeek(this, Functions.emptyConsumer(), // onSubscribe Functions.emptyConsumer(), // onSuccess ObjectHelper.requireNonNull(onError, "onError is null"), Functions.EMPTY_ACTION, // onComplete Functions.EMPTY_ACTION, // (onSuccess | onError | onComplete) Functions.EMPTY_ACTION // dispose )); } /** * Calls the given onEvent callback with the (success value, null) for an onSuccess, (null, throwable) for * an onError or (null, null) for an onComplete signal from this Maybe before delivering said * signal to the downstream. *

* Exceptions thrown from the callback will override the event so the downstream receives the * error instead of the original signal. *

*
Scheduler:
*
{@code doOnEvent} does not operate by default on a particular {@link Scheduler}.
*
* @param onEvent the callback to call with the terminal event tuple * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doOnEvent(BiConsumer onEvent) { ObjectHelper.requireNonNull(onEvent, "onEvent is null"); return RxJavaObservablePlugins.onAssembly(new MaybeDoOnEvent(this, onEvent)); } /** * Calls the shared consumer with the Disposable sent through the onSubscribe for each * MaybeObserver that subscribes to the current Maybe. *
*
Scheduler:
*
{@code doOnSubscribe} does not operate by default on a particular {@link Scheduler}.
*
* @param onSubscribe the consumer called with the Disposable sent via onSubscribe * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doOnSubscribe(Consumer onSubscribe) { return RxJavaObservablePlugins.onAssembly(new MaybePeek(this, ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null"), Functions.emptyConsumer(), // onSuccess Functions.emptyConsumer(), // onError Functions.EMPTY_ACTION, // onComplete Functions.EMPTY_ACTION, // (onSuccess | onError | onComplete) Functions.EMPTY_ACTION // dispose )); } /** * Calls the shared consumer with the success value sent via onSuccess for each * MaybeObserver that subscribes to the current Maybe. *
*
Scheduler:
*
{@code doOnSuccess} does not operate by default on a particular {@link Scheduler}.
*
* @param onSuccess the consumer called with the success value of onSuccess * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe doOnSuccess(Consumer onSuccess) { return RxJavaObservablePlugins.onAssembly(new MaybePeek(this, Functions.emptyConsumer(), // onSubscribe ObjectHelper.requireNonNull(onSuccess, "onSubscribe is null"), Functions.emptyConsumer(), // onError Functions.EMPTY_ACTION, // onComplete Functions.EMPTY_ACTION, // (onSuccess | onError | onComplete) Functions.EMPTY_ACTION // dispose )); } /** * Filters the success item of the Maybe via a predicate function and emitting it if the predicate * returns true, completing otherwise. *

* *

*
Scheduler:
*
{@code filter} does not operate by default on a particular {@link Scheduler}.
*
* * @param predicate * a function that evaluates the item emitted by the source Maybe, returning {@code true} * if it passes the filter * @return a Maybe that emit the item emitted by the source Maybe that the filter * evaluates as {@code true} * @see ReactiveX operators documentation: Filter */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe filter(Predicate predicate) { ObjectHelper.requireNonNull(predicate, "predicate is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFilter(this, predicate)); } /** * Returns a Maybe that is based on applying a specified function to the item emitted by the source Maybe, * where that function returns a MaybeSource. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
*

Note that flatMap and concatMap for Maybe is the same operation. * * @param the result value type * @param mapper * a function that, when applied to the item emitted by the source Maybe, returns a MaybeSource * @return the Maybe returned from {@code func} when applied to the item emitted by the source Maybe * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe flatMap(Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFlatten(this, mapper)); } /** * Maps the onSuccess, onError or onComplete signals of this Maybe into MaybeSource and emits that * MaybeSource's signals *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the result type * @param onSuccessMapper * a function that returns a MaybeSource to merge for the onSuccess item emitted by this Maybe * @param onErrorMapper * a function that returns a MaybeSource to merge for an onError notification from this Maybe * @param onCompleteSupplier * a function that returns a MaybeSource to merge for an onComplete notification this Maybe * @return the new Maybe instance * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe flatMap( Function> onSuccessMapper, Function> onErrorMapper, Callable> onCompleteSupplier) { ObjectHelper.requireNonNull(onSuccessMapper, "onSuccessMapper is null"); ObjectHelper.requireNonNull(onErrorMapper, "onErrorMapper is null"); ObjectHelper.requireNonNull(onCompleteSupplier, "onCompleteSupplier is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFlatMapNotification(this, onSuccessMapper, onErrorMapper, onCompleteSupplier)); } /** * Returns a Maybe that emits the results of a specified function to the pair of values emitted by the * source Maybe and a specified mapped MaybeSource. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items emitted by the MaybeSource returned by the {@code mapper} function * @param * the type of items emitted by the resulting Maybe * @param mapper * a function that returns a MaybeSource for the item emitted by the source Maybe * @param resultSelector * a function that combines one item emitted by each of the source and collection MaybeSource and * returns an item to be emitted by the resulting MaybeSource * @return the new Maybe instance * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe flatMap(Function> mapper, BiFunction resultSelector) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.requireNonNull(resultSelector, "resultSelector is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFlatMapBiSelector(this, mapper, resultSelector)); } /** * Returns an Observable that maps a success value into an Iterable and emits its items. *

* *

*
Scheduler:
*
{@code flattenAsObservable} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of item emitted by the resulting Iterable * @param mapper * a function that returns an Iterable sequence of values for when given an item emitted by the * source Maybe * @return the new Observable instance * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flattenAsObservable(final Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFlatMapIterableObservable(this, mapper)); } /** * Returns an Observable that is based on applying a specified function to the item emitted by the source Maybe, * where that function returns an ObservableSource. *

* *

*
Scheduler:
*
{@code flatMapObservable} does not operate by default on a particular {@link Scheduler}.
*
* * @param the result value type * @param mapper * a function that, when applied to the item emitted by the source Maybe, returns an ObservableSource * @return the Observable returned from {@code func} when applied to the item emitted by the source Maybe * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMapObservable(Function> mapper) { return toObservable().flatMap(mapper); } /** * Returns a {@link Single} based on applying a specified function to the item emitted by the * source {@link Maybe}, where that function returns a {@link Single}. * When this Maybe completes a {@link NoSuchElementException} will be thrown. *

* *

*
Scheduler:
*
{@code flatMapSingle} does not operate by default on a particular {@link Scheduler}.
*
* * @param the result value type * @param mapper * a function that, when applied to the item emitted by the source Maybe, returns a * Single * @return the Single returned from {@code mapper} when applied to the item emitted by the source Maybe * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single flatMapSingle(final Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFlatMapSingle(this, mapper)); } /** * Returns a {@link Maybe} based on applying a specified function to the item emitted by the * source {@link Maybe}, where that function returns a {@link Single}. * When this Maybe just completes the resulting {@code Maybe} completes as well. *

* *

*
Scheduler:
*
{@code flatMapSingleElement} does not operate by default on a particular {@link Scheduler}.
*
* * @param the result value type * @param mapper * a function that, when applied to the item emitted by the source Maybe, returns a * Single * @return the new Maybe instance * @see ReactiveX operators documentation: FlatMap * @since 2.0.2 - experimental */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @Experimental public final Maybe flatMapSingleElement(final Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFlatMapSingleElement(this, mapper)); } /** * Returns a {@link Completable} that completes based on applying a specified function to the item emitted by the * source {@link Maybe}, where that function returns a {@link Completable}. *

* *

*
Scheduler:
*
{@code flatMapCompletable} does not operate by default on a particular {@link Scheduler}.
*
* * @param mapper * a function that, when applied to the item emitted by the source Maybe, returns a * Completable * @return the Completable returned from {@code mapper} when applied to the item emitted by the source Maybe * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable flatMapCompletable(final Function mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaObservablePlugins.onAssembly(new MaybeFlatMapCompletable(this, mapper)); } /** * Hides the identity of this Maybe and its Disposable. *

Allows preventing certain identity-based * optimizations (fusion). *

*
Scheduler:
*
{@code hide} does not operate by default on a particular {@link Scheduler}.
*
* @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe hide() { return RxJavaObservablePlugins.onAssembly(new MaybeHide(this)); } /** * Ignores the item emitted by the source Maybe and only calls {@code onComplete} or {@code onError}. *

* *

*
Scheduler:
*
{@code ignoreElement} does not operate by default on a particular {@link Scheduler}.
*
* * @return an empty Completable that only calls {@code onComplete} or {@code onError}, based on which one is * called by the source Maybe * @see ReactiveX operators documentation: IgnoreElements */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable ignoreElement() { return RxJavaObservablePlugins.onAssembly(new MaybeIgnoreElementCompletable(this)); } /** * Returns a Single that emits {@code true} if the source Maybe is empty, otherwise {@code false}. *

* *

*
Scheduler:
*
{@code isEmpty} does not operate by default on a particular {@link Scheduler}.
*
* * @return a Single that emits a Boolean * @see ReactiveX operators documentation: Contains */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single isEmpty() { return RxJavaObservablePlugins.onAssembly(new MaybeIsEmptySingle(this)); } /** * Lifts a function to the current Maybe and returns a new Maybe that when subscribed to will pass the * values of the current Maybe through the MaybeOperator function. *

* In other words, this allows chaining TaskExecutors together on a Maybe for acting on the values within * the Maybe. *

* {@code task.map(...).filter(...).lift(new OperatorA()).lift(new OperatorB(...)).subscribe() } *

* If the operator you are creating is designed to act on the item emitted by a source Maybe, use * {@code lift}. If your operator is designed to transform the source Maybe as a whole (for instance, by * applying a particular set of existing RxJava operators to it) use {@link #compose}. *

*
Scheduler:
*
{@code lift} does not operate by default on a particular {@link Scheduler}.
*
* * @param the downstream's value type (output) * @param lift * the MaybeOperator that implements the Maybe-operating function to be applied to the source Maybe * @return a Maybe that is the result of applying the lifted Operator to the source Maybe * @see RxJava wiki: Implementing Your Own Operators */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe lift(final MaybeOperator lift) { ObjectHelper.requireNonNull(lift, "onLift is null"); return RxJavaObservablePlugins.onAssembly(new MaybeLift(this, lift)); } /** * Returns a Maybe that applies a specified function to the item emitted by the source Maybe and * emits the result of this function application. *

* *

*
Scheduler:
*
{@code map} does not operate by default on a particular {@link Scheduler}.
*
* * @param the result value type * @param mapper * a function to apply to the item emitted by the Maybe * @return a Maybe that emits the item from the source Maybe, transformed by the specified function * @see ReactiveX operators documentation: Map */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe map(Function mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaObservablePlugins.onAssembly(new MaybeMap(this, mapper)); } /** * Flattens this and another Maybe into a single Observable, without any transformation. *

* *

* You can combine items emitted by multiple Maybes so that they appear as a single Observable, by * using the {@code mergeWith} method. *

*
Scheduler:
*
{@code mergeWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param other * a MaybeSource to be merged * @return a new Observable instance * @see ReactiveX operators documentation: Merge */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable mergeWith(MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); return merge(this, other); } /** * Wraps a Maybe to emit its item (or notify of its error) on a specified {@link Scheduler}, * asynchronously. *

* *

*
Scheduler:
*
you specify which {@link Scheduler} this operator will use
*
* * @param scheduler * the {@link Scheduler} to notify subscribers on * @return the new Maybe instance that its subscribers are notified on the specified * {@link Scheduler} * @see ReactiveX operators documentation: ObserveOn * @see RxJava Threading Examples * @see #subscribeOn */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Maybe observeOn(final Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaObservablePlugins.onAssembly(new MaybeObserveOn(this, scheduler)); } /** * Filters the items emitted by a Maybe, only emitting its success value if that * is an instance of the supplied Class. *

* *

*
Scheduler:
*
{@code ofType} does not operate by default on a particular {@link Scheduler}.
*
* * @param the output type * @param clazz * the class type to filter the items emitted by the source Maybe * @return the new Maybe instance * @see ReactiveX operators documentation: Filter */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe ofType(final Class clazz) { ObjectHelper.requireNonNull(clazz, "clazz is null"); return filter(Functions.isInstanceOf(clazz)).cast(clazz); } /** * Calls the specified converter function with the current Maybe instance * during assembly time and returns its result. *
*
Scheduler:
*
{@code to} does not operate by default on a particular {@link Scheduler}.
*
* @param the result type * @param convert the function that is called with the current Maybe instance during * assembly time that should return some value to be the result * * @return the value returned by the convert function */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final R to(Function, R> convert) { try { return ObjectHelper.requireNonNull(convert, "convert is null").apply(this); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); throw ExceptionHelper.wrapOrThrow(ex); } } /** * Converts this Maybe into an Observable instance composing cancellation * through. *
*
Scheduler:
*
{@code toObservable} does not operate by default on a particular {@link Scheduler}.
*
* @return the new Observable instance */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable toObservable() { if (this instanceof FuseToObservable) { return ((FuseToObservable)this).fuseToObservable(); } return RxJavaObservablePlugins.onAssembly(new MaybeToObservable(this)); } /** * Converts this Maybe into a Single instance composing cancellation * through and turning an empty Maybe into a signal of NoSuchElementException. *
*
Scheduler:
*
{@code toSingle} does not operate by default on a particular {@link Scheduler}.
*
* @param defaultValue the default item to signal in Single if this Maybe is empty * @return the new Single instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single toSingle(T defaultValue) { ObjectHelper.requireNonNull(defaultValue, "defaultValue is null"); return RxJavaObservablePlugins.onAssembly(new MaybeToSingle(this, defaultValue)); } /** * Converts this Maybe into a Single instance composing cancellation * through and turning an empty Maybe into a signal of NoSuchElementException. *
*
Scheduler:
*
{@code toSingle} does not operate by default on a particular {@link Scheduler}.
*
* @return the new Single instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single toSingle() { return RxJavaObservablePlugins.onAssembly(new MaybeToSingle(this, null)); } /** * Returns a Maybe instance that if this Maybe emits an error, it will emit an onComplete * and swallow the throwable. *
*
Scheduler:
*
{@code onErrorComplete} does not operate by default on a particular {@link Scheduler}.
*
* @return the new Completable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onErrorComplete() { return onErrorComplete(Functions.alwaysTrue()); } /** * Returns a Maybe instance that if this Maybe emits an error and the predicate returns * true, it will emit an onComplete and swallow the throwable. *
*
Scheduler:
*
{@code onErrorComplete} does not operate by default on a particular {@link Scheduler}.
*
* @param predicate the predicate to call when an Throwable is emitted which should return true * if the Throwable should be swallowed and replaced with an onComplete. * @return the new Completable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onErrorComplete(final Predicate predicate) { ObjectHelper.requireNonNull(predicate, "predicate is null"); return RxJavaObservablePlugins.onAssembly(new MaybeOnErrorComplete(this, predicate)); } /** * Instructs a Maybe to pass control to another MaybeSource rather than invoking * {@link MaybeObserver#onError onError} if it encounters an error. *

* *

* You can use this to prevent errors from propagating or to supply fallback data should errors be * encountered. *

*
Scheduler:
*
{@code onErrorResumeNext} does not operate by default on a particular {@link Scheduler}.
*
* * @param next * the next Maybe source that will take over if the source Maybe encounters * an error * @return the new Maybe instance * @see ReactiveX operators documentation: Catch */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onErrorResumeNext(final MaybeSource next) { ObjectHelper.requireNonNull(next, "next is null"); return onErrorResumeNext(Functions.justFunction(next)); } /** * Instructs a Maybe to pass control to another Maybe rather than invoking * {@link MaybeObserver#onError onError} if it encounters an error. *

* *

* You can use this to prevent errors from propagating or to supply fallback data should errors be * encountered. *

*
Scheduler:
*
{@code onErrorResumeNext} does not operate by default on a particular {@link Scheduler}.
*
* * @param resumeFunction * a function that returns a MaybeSource that will take over if the source Maybe encounters * an error * @return the new Maybe instance * @see ReactiveX operators documentation: Catch */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onErrorResumeNext(Function> resumeFunction) { ObjectHelper.requireNonNull(resumeFunction, "resumeFunction is null"); return RxJavaObservablePlugins.onAssembly(new MaybeOnErrorNext(this, resumeFunction, true)); } /** * Instructs a Maybe to emit an item (returned by a specified function) rather than invoking * {@link MaybeObserver#onError onError} if it encounters an error. *

* *

* You can use this to prevent errors from propagating or to supply fallback data should errors be * encountered. *

*
Scheduler:
*
{@code onErrorReturn} does not operate by default on a particular {@link Scheduler}.
*
* * @param valueSupplier * a function that returns a single value that will be emitted as success value * the current Maybe signals an onError event * @return the new Maybe instance * @see ReactiveX operators documentation: Catch */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onErrorReturn(Function valueSupplier) { ObjectHelper.requireNonNull(valueSupplier, "valueSupplier is null"); return RxJavaObservablePlugins.onAssembly(new MaybeOnErrorReturn(this, valueSupplier)); } /** * Instructs a Maybe to emit an item (returned by a specified function) rather than invoking * {@link MaybeObserver#onError onError} if it encounters an error. *

* *

* You can use this to prevent errors from propagating or to supply fallback data should errors be * encountered. *

*
Scheduler:
*
{@code onErrorReturnItem} does not operate by default on a particular {@link Scheduler}.
*
* * @param item * the value that is emitted as onSuccess in case this Maybe signals an onError * @return the new Maybe instance * @see ReactiveX operators documentation: Catch */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onErrorReturnItem(final T item) { ObjectHelper.requireNonNull(item, "item is null"); return onErrorReturn(Functions.justFunction(item)); } /** * Instructs a Maybe to pass control to another MaybeSource rather than invoking * {@link MaybeObserver#onError onError} if it encounters an {@link java.lang.Exception}. *

* This differs from {@link #onErrorResumeNext} in that this one does not handle {@link java.lang.Throwable} * or {@link java.lang.Error} but lets those continue through. *

* *

* You can use this to prevent exceptions from propagating or to supply fallback data should exceptions be * encountered. *

*
Scheduler:
*
{@code onExceptionResumeNext} does not operate by default on a particular {@link Scheduler}.
*
* * @param next * the next MaybeSource that will take over if the source Maybe encounters * an exception * @return the new Maybe instance * @see ReactiveX operators documentation: Catch */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onExceptionResumeNext(final MaybeSource next) { ObjectHelper.requireNonNull(next, "next is null"); return RxJavaObservablePlugins.onAssembly(new MaybeOnErrorNext(this, Functions.justFunction(next), false)); } /** * Nulls out references to the upstream producer and downstream MaybeObserver if * the sequence is terminated or downstream calls dispose(). *
*
Scheduler:
*
{@code onTerminateDetach} does not operate by default on a particular {@link Scheduler}.
*
* @return a Maybe which out references to the upstream producer and downstream MaybeObserver if * the sequence is terminated or downstream calls dispose() */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe onTerminateDetach() { return RxJavaObservablePlugins.onAssembly(new MaybeDetach(this)); } /** * Returns an Observable that repeats the sequence of items emitted by the source Maybe indefinitely. *

* *

*
Scheduler:
*
{@code repeat} does not operate by default on a particular {@link Scheduler}.
*
* * @return an Observable that emits the items emitted by the source Maybe repeatedly and in sequence * @see ReactiveX operators documentation: Repeat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable repeat() { return repeat(Long.MAX_VALUE); } /** * Returns an Observable that repeats the sequence of items emitted by the source Maybe at most * {@code count} times. *

* *

*
Scheduler:
*
{@code repeat} does not operate by default on a particular {@link Scheduler}.
*
* * @param times * the number of times the source Maybe items are repeated, a count of 0 will yield an empty * sequence * @return an Observable that repeats the sequence of items emitted by the source Maybe at most * {@code count} times * @throws IllegalArgumentException * if {@code count} is less than zero * @see ReactiveX operators documentation: Repeat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable repeat(long times) { return toObservable().repeat(times); } /** * Returns an Observable that repeats the sequence of items emitted by the source Maybe until * the provided stop function returns true. *

* *

*
Scheduler:
*
{@code repeatUntil} does not operate by default on a particular {@link Scheduler}.
*
* * @param stop * a boolean supplier that is called when the current Observable completes and unless it returns * false, the current Observable is resubscribed * @return the new Observable instance * @throws NullPointerException * if {@code stop} is null * @see ReactiveX operators documentation: Repeat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable repeatUntil(BooleanSupplier stop) { return toObservable().repeatUntil(stop); } /** * Returns an Observable that emits the same values as the source ObservableSource with the exception of an * {@code onComplete}. An {@code onComplete} notification from the source will result in the emission of * a {@code void} item to the ObservableSource provided as an argument to the {@code notificationHandler} * function. If that ObservableSource calls {@code onComplete} or {@code onError} then {@code repeatWhen} will * call {@code onComplete} or {@code onError} on the child subscription. Otherwise, this ObservableSource will * resubscribe to the source ObservableSource. *

* *

*
Scheduler:
*
{@code repeatWhen} does not operate by default on a particular {@link Scheduler}.
*
* * @param handler * receives an ObservableSource of notifications with which a user can complete or error, aborting the repeat. * @return the source ObservableSource modified with repeat logic * @see ReactiveX operators documentation: Repeat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable repeatWhen(final Function, ? extends ObservableSource> handler) { return toObservable().repeatWhen(handler); } /** * Returns a Maybe that mirrors the source Maybe, resubscribing to it if it calls {@code onError} * (infinite retry count). *

* *

* If the source Maybe calls {@link MaybeObserver#onError}, this method will resubscribe to the source * Maybe rather than propagating the {@code onError} call. *

*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
*
* * @return the nww Maybe instance * @see ReactiveX operators documentation: Retry */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe retry() { return retry(Long.MAX_VALUE, Functions.alwaysTrue()); } /** * Returns a Maybe that mirrors the source Maybe, resubscribing to it if it calls {@code onError} * and the predicate returns true for that specific exception and retry count. *

* *

*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
*
* * @param predicate * the predicate that determines if a resubscription may happen in case of a specific exception * and retry count * @return the nww Maybe instance * @see #retry() * @see ReactiveX operators documentation: Retry */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe retry(BiPredicate predicate) { return toObservable().retry(predicate).singleElement(); } /** * Returns a Maybe that mirrors the source Maybe, resubscribing to it if it calls {@code onError} * up to a specified number of retries. *

* *

* If the source Maybe calls {@link MaybeObserver#onError}, this method will resubscribe to the source * Maybe for a maximum of {@code count} resubscriptions rather than propagating the * {@code onError} call. *

*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
*
* * @param count * number of retry attempts before failing * @return the new Maybe instance * @see ReactiveX operators documentation: Retry */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe retry(long count) { return retry(count, Functions.alwaysTrue()); } /** * Retries at most times or until the predicate returns false, whichever happens first. * *
*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
*
* @param times the number of times to repeat * @param predicate the predicate called with the failure Throwable and should return true to trigger a retry. * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe retry(long times, Predicate predicate) { return toObservable().retry(times, predicate).singleElement(); } /** * Retries the current Maybe if it fails and the predicate returns true. *
*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
*
* * @param predicate the predicate that receives the failure Throwable and should return true to trigger a retry. * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe retry(Predicate predicate) { return retry(Long.MAX_VALUE, predicate); } /** * Retries until the given stop function returns true. *
*
Scheduler:
*
{@code retryUntil} does not operate by default on a particular {@link Scheduler}.
*
* @param stop the function that should return true to stop retrying * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe retryUntil(final BooleanSupplier stop) { ObjectHelper.requireNonNull(stop, "stop is null"); return retry(Long.MAX_VALUE, Functions.predicateReverseFor(stop)); } /** * Returns a Maybe that emits the same values as the source Maybe with the exception of an * {@code onError}. An {@code onError} notification from the source will result in the emission of a * {@link Throwable} item to the ObservableSource provided as an argument to the {@code notificationHandler} * function. If that ObservableSource calls {@code onComplete} or {@code onError} then {@code retry} will call * {@code onComplete} or {@code onError} on the child subscription. Otherwise, this ObservableSource will * resubscribe to the source ObservableSource. *

* * * Example: * * This retries 3 times, each time incrementing the number of seconds it waits. * *


     *  ObservableSource.create((Observer s) -> {
     *      System.out.println("subscribing");
     *      s.onError(new RuntimeException("always fails"));
     *  }).retryWhen(attempts -> {
     *      return attempts.zipWith(ObservableSource.range(1, 3), (n, i) -> i).flatMap(i -> {
     *          System.out.println("delay retry by " + i + " second(s)");
     *          return ObservableSource.timer(i, TimeUnit.SECONDS);
     *      });
     *  }).blockingForEach(System.out::println);
     * 
* * Output is: * *
 {@code
     * subscribing
     * delay retry by 1 second(s)
     * subscribing
     * delay retry by 2 second(s)
     * subscribing
     * delay retry by 3 second(s)
     * subscribing
     * } 
*
*
Scheduler:
*
{@code retryWhen} does not operate by default on a particular {@link Scheduler}.
*
* * @param handler * receives an ObservableSource of notifications with which a user can complete or error, aborting the * retry * @return the new Maybe instance * @see ReactiveX operators documentation: Retry */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe retryWhen( final Function, ? extends ObservableSource> handler) { return toObservable().retryWhen(handler).singleElement(); } /** * Subscribes to a Maybe and ignores {@code onSuccess} and {@code onComplete} emissions. *

* If the Maybe emits an error, it is wrapped into an * {@link io.reactivex.common.exceptions.OnErrorNotImplementedException OnErrorNotImplementedException} * and routed to the RxJavaCommonPlugins.onError handler. *

*
Scheduler:
*
{@code subscribe} does not operate by default on a particular {@link Scheduler}.
*
* * @return a {@link Disposable} reference with which the caller can stop receiving items before * the Maybe has finished sending them * @see ReactiveX operators documentation: Subscribe */ @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe() { return subscribe(Functions.emptyConsumer(), Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION); } /** * Subscribes to a Maybe and provides a callback to handle the items it emits. *

* If the Maybe emits an error, it is wrapped into an * {@link io.reactivex.common.exceptions.OnErrorNotImplementedException OnErrorNotImplementedException} * and routed to the RxJavaCommonPlugins.onError handler. *

*
Scheduler:
*
{@code subscribe} does not operate by default on a particular {@link Scheduler}.
*
* * @param onSuccess * the {@code Consumer} you have designed to accept a success value from the Maybe * @return a {@link Disposable} reference with which the caller can stop receiving items before * the Maybe has finished sending them * @throws NullPointerException * if {@code onSuccess} is null * @see ReactiveX operators documentation: Subscribe */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe(Consumer onSuccess) { return subscribe(onSuccess, Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION); } /** * Subscribes to a Maybe and provides callbacks to handle the items it emits and any error * notification it issues. *
*
Scheduler:
*
{@code subscribe} does not operate by default on a particular {@link Scheduler}.
*
* * @param onSuccess * the {@code Consumer} you have designed to accept a success value from the Maybe * @param onError * the {@code Consumer} you have designed to accept any error notification from the * Maybe * @return a {@link Disposable} reference with which the caller can stop receiving items before * the Maybe has finished sending them * @see ReactiveX operators documentation: Subscribe * @throws NullPointerException * if {@code onSuccess} is null, or * if {@code onError} is null */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe(Consumer onSuccess, Consumer onError) { return subscribe(onSuccess, onError, Functions.EMPTY_ACTION); } /** * Subscribes to a Maybe and provides callbacks to handle the items it emits and any error or * completion notification it issues. *
*
Scheduler:
*
{@code subscribe} does not operate by default on a particular {@link Scheduler}.
*
* * @param onSuccess * the {@code Consumer} you have designed to accept a success value from the Maybe * @param onError * the {@code Consumer} you have designed to accept any error notification from the * Maybe * @param onComplete * the {@code Action} you have designed to accept a completion notification from the * Maybe * @return a {@link Disposable} reference with which the caller can stop receiving items before * the Maybe has finished sending them * @throws NullPointerException * if {@code onSuccess} is null, or * if {@code onError} is null, or * if {@code onComplete} is null * @see ReactiveX operators documentation: Subscribe */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe(Consumer onSuccess, Consumer onError, Action onComplete) { ObjectHelper.requireNonNull(onSuccess, "onSuccess is null"); ObjectHelper.requireNonNull(onError, "onError is null"); ObjectHelper.requireNonNull(onComplete, "onComplete is null"); return subscribeWith(new MaybeCallbackObserver(onSuccess, onError, onComplete)); } @SchedulerSupport(SchedulerSupport.NONE) @Override public final void subscribe(MaybeObserver observer) { ObjectHelper.requireNonNull(observer, "observer is null"); observer = RxJavaObservablePlugins.onSubscribe(this, observer); ObjectHelper.requireNonNull(observer, "observer returned by the RxJavaObservablePlugins hook is null"); try { subscribeActual(observer); } catch (NullPointerException ex) { throw ex; } catch (Throwable ex) { Exceptions.throwIfFatal(ex); NullPointerException npe = new NullPointerException("subscribeActual failed"); npe.initCause(ex); throw npe; } } /** * Override this method in subclasses to handle the incoming MaybeObservers. * @param observer the MaybeObserver to handle, not null */ protected abstract void subscribeActual(MaybeObserver observer); /** * Asynchronously subscribes subscribers to this Maybe on the specified {@link Scheduler}. *

* *

*
Scheduler:
*
you specify which {@link Scheduler} this operator will use
*
* * @param scheduler * the {@link Scheduler} to perform subscription actions on * @return the new Maybe instance that its subscriptions happen on the specified {@link Scheduler} * @see ReactiveX operators documentation: SubscribeOn * @see RxJava Threading Examples * @see #observeOn */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Maybe subscribeOn(Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaObservablePlugins.onAssembly(new MaybeSubscribeOn(this, scheduler)); } /** * Subscribes a given MaybeObserver (subclass) to this Maybe and returns the given * MaybeObserver as is. *

Usage example: *


     * Maybe<Integer> source = Maybe.just(1);
     * CompositeDisposable composite = new CompositeDisposable();
     *
     * MaybeObserver<Integer> ms = new MaybeObserver<>() {
     *     // ...
     * };
     *
     * composite.add(source.subscribeWith(ms));
     * 
*
*
Scheduler:
*
{@code subscribeWith} does not operate by default on a particular {@link Scheduler}.
*
* @param the type of the MaybeObserver to use and return * @param observer the MaybeObserver (subclass) to use and return, not null * @return the input {@code subscriber} * @throws NullPointerException if {@code subscriber} is null */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final > E subscribeWith(E observer) { subscribe(observer); return observer; } /** * Returns a Maybe that emits the items emitted by the source Maybe or the items of an alternate * MaybeSource if the current Maybe is empty. *

* *

*

*
Scheduler:
*
{@code switchIfEmpty} does not operate by default on a particular {@link Scheduler}.
*
* * @param other * the alternate MaybeSource to subscribe to if the main does not emit any items * @return a Maybe that emits the items emitted by the source Maybe or the items of an * alternate MaybeSource if the source Maybe is empty. */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe switchIfEmpty(MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaObservablePlugins.onAssembly(new MaybeSwitchIfEmpty(this, other)); } /** * Returns a Maybe that emits the items emitted by the source Maybe until a second MaybeSource * emits an item. *

* *

*
Scheduler:
*
{@code takeUntil} does not operate by default on a particular {@link Scheduler}.
*
* * @param other * the MaybeSource whose first emitted item will cause {@code takeUntil} to stop emitting items * from the source Maybe * @param * the type of items emitted by {@code other} * @return a Maybe that emits the items emitted by the source Maybe until such time as {@code other} emits its first item * @see ReactiveX operators documentation: TakeUntil */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe takeUntil(MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaObservablePlugins.onAssembly(new MaybeTakeUntilMaybe(this, other)); } /** * Returns a Maybe that emits the item emitted by the source Maybe until a second ObservableSource * emits an item. *

* *

*
Scheduler:
*
{@code takeUntil} does not operate by default on a particular {@link Scheduler}.
*
* * @param other * the ObservableSource whose first emitted item will cause {@code takeUntil} to stop emitting items * from the source ObservableSource * @param * the type of items emitted by {@code other} * @return a Maybe that emits the items emitted by the source Maybe until such time as {@code other} emits its first item * @see ReactiveX operators documentation: TakeUntil */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe takeUntil(ObservableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaObservablePlugins.onAssembly(new MaybeTakeUntilObservable(this, other)); } /** * Returns a Maybe that mirrors the source Maybe but applies a timeout policy for each emitted * item. If the next item isn't emitted within the specified timeout duration starting from its predecessor, * the resulting Maybe terminates and notifies MaybeObservers of a {@code TimeoutException}. *

* *

*
Scheduler:
*
This version of {@code timeout} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param timeout * maximum duration between emitted items before a timeout occurs * @param timeUnit * the unit of time that applies to the {@code timeout} argument. * @return the new Maybe instance * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Maybe timeout(long timeout, TimeUnit timeUnit) { return timeout(timeout, timeUnit, Schedulers.computation()); } /** * Returns a Maybe that mirrors the source Maybe but applies a timeout policy for each emitted * item. If the next item isn't emitted within the specified timeout duration starting from its predecessor, * the resulting Maybe begins instead to mirror a fallback MaybeSource. *

* *

*
Scheduler:
*
This version of {@code timeout} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param timeout * maximum duration between items before a timeout occurs * @param timeUnit * the unit of time that applies to the {@code timeout} argument * @param fallback * the fallback MaybeSource to use in case of a timeout * @return the new Maybe instance * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Maybe timeout(long timeout, TimeUnit timeUnit, MaybeSource fallback) { ObjectHelper.requireNonNull(fallback, "other is null"); return timeout(timeout, timeUnit, Schedulers.computation(), fallback); } /** * Returns a Maybe that mirrors the source Maybe but applies a timeout policy for each emitted * item using a specified Scheduler. If the next item isn't emitted within the specified timeout duration * starting from its predecessor, the resulting Maybe begins instead to mirror a fallback MaybeSource. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use
*
* * @param timeout * maximum duration between items before a timeout occurs * @param timeUnit * the unit of time that applies to the {@code timeout} argument * @param fallback * the MaybeSource to use as the fallback in case of a timeout * @param scheduler * the {@link Scheduler} to run the timeout timers on * @return the new Maybe instance * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Maybe timeout(long timeout, TimeUnit timeUnit, Scheduler scheduler, MaybeSource fallback) { ObjectHelper.requireNonNull(fallback, "fallback is null"); return timeout(timer(timeout, timeUnit, scheduler), fallback); } /** * Returns a Maybe that mirrors the source Maybe but applies a timeout policy for each emitted * item, where this policy is governed on a specified Scheduler. If the next item isn't emitted within the * specified timeout duration starting from its predecessor, the resulting Maybe terminates and * notifies MaybeObservers of a {@code TimeoutException}. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use
*
* * @param timeout * maximum duration between items before a timeout occurs * @param timeUnit * the unit of time that applies to the {@code timeout} argument * @param scheduler * the Scheduler to run the timeout timers on * @return the new Maybe instance * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Maybe timeout(long timeout, TimeUnit timeUnit, Scheduler scheduler) { return timeout(timer(timeout, timeUnit, scheduler)); } /** * If this Maybe source didn't signal an event before the timeoutIndicator MaybeSource signals, a * TimeoutException is signalled instead. *
*
Scheduler:
*
{@code timeout} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type of the * @param timeoutIndicator the MaybeSource that indicates the timeout by signalling onSuccess * or onComplete. * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe timeout(MaybeSource timeoutIndicator) { ObjectHelper.requireNonNull(timeoutIndicator, "timeoutIndicator is null"); return RxJavaObservablePlugins.onAssembly(new MaybeTimeoutMaybe(this, timeoutIndicator, null)); } /** * If the current Maybe source didn't signal an event before the timeoutIndicator MaybeSource signals, * the current Maybe is cancelled and the {@code fallback} MaybeSource subscribed to * as a continuation. *
*
Scheduler:
*
{@code timeout} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type of the * @param timeoutIndicator the MaybeSource that indicates the timeout by signalling onSuccess * or onComplete. * @param fallback the MaybeSource that is subscribed to if the current Maybe times out * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe timeout(MaybeSource timeoutIndicator, MaybeSource fallback) { ObjectHelper.requireNonNull(timeoutIndicator, "timeoutIndicator is null"); ObjectHelper.requireNonNull(fallback, "fallback is null"); return RxJavaObservablePlugins.onAssembly(new MaybeTimeoutMaybe(this, timeoutIndicator, fallback)); } /** * If this Maybe source didn't signal an event before the timeoutIndicator ObservableSource signals, a * TimeoutException is signalled instead. *
*
Scheduler:
*
{@code timeout} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type of the * @param timeoutIndicator the MaybeSource that indicates the timeout by signalling onSuccess * or onComplete. * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe timeout(ObservableSource timeoutIndicator) { ObjectHelper.requireNonNull(timeoutIndicator, "timeoutIndicator is null"); return RxJavaObservablePlugins.onAssembly(new MaybeTimeoutObservable(this, timeoutIndicator, null)); } /** * If the current Maybe source didn't signal an event before the timeoutIndicator ObservableSource signals, * the current Maybe is cancelled and the {@code fallback} MaybeSource subscribed to * as a continuation. *
*
Scheduler:
*
{@code timeout} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type of the * @param timeoutIndicator the MaybeSource that indicates the timeout by signalling onSuccess * or onComplete * @param fallback the MaybeSource that is subscribed to if the current Maybe times out * @return the new Maybe instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe timeout(ObservableSource timeoutIndicator, MaybeSource fallback) { ObjectHelper.requireNonNull(timeoutIndicator, "timeoutIndicator is null"); ObjectHelper.requireNonNull(fallback, "fallback is null"); return RxJavaObservablePlugins.onAssembly(new MaybeTimeoutObservable(this, timeoutIndicator, fallback)); } /** * Returns a Maybe which makes sure when a MaybeObserver disposes the Disposable, * that call is propagated up on the specified scheduler *
*
Scheduler:
*
{@code unsubscribeOn} calls dispose() of the upstream on the {@link Scheduler} you specify.
*
* @param scheduler the target scheduler where to execute the cancellation * @return the new Maybe instance * @throws NullPointerException if scheduler is null */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Maybe unsubscribeOn(final Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaObservablePlugins.onAssembly(new MaybeUnsubscribeOn(this, scheduler)); } /** * Waits until this and the other MaybeSource signal a success value then applies the given BiFunction * to those values and emits the BiFunction's resulting value to downstream. * * * *

If either this or the other MaybeSource is empty or signals an error, the resulting Maybe will * terminate immediately and dispose the other source. * *

*
Scheduler:
*
{@code zipWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items emitted by the {@code other} MaybeSource * @param * the type of items emitted by the resulting Maybe * @param other * the other MaybeSource * @param zipper * a function that combines the pairs of items from the two MaybeSources to generate the items to * be emitted by the resulting Maybe * @return the new Maybe instance * @see ReactiveX operators documentation: Zip */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe zipWith(MaybeSource other, BiFunction zipper) { ObjectHelper.requireNonNull(other, "other is null"); return zip(this, other, zipper); } // ------------------------------------------------------------------ // Test helper // ------------------------------------------------------------------ /** * Creates a TestObserver and subscribes * it to this Maybe. *
*
Scheduler:
*
{@code test} does not operate by default on a particular {@link Scheduler}.
*
* @return the new TestObserver instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final TestObserver test() { TestObserver ts = new TestObserver(); subscribe(ts); return ts; } /** * Creates a TestObserver optionally in cancelled state, then subscribes it to this Maybe. *
*
Scheduler:
*
{@code test} does not operate by default on a particular {@link Scheduler}.
*
* @param cancelled if true, the TestObserver will be cancelled before subscribing to this * Maybe. * @return the new TestObserver instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final TestObserver test(boolean cancelled) { TestObserver ts = new TestObserver(); if (cancelled) { ts.cancel(); } subscribe(ts); return ts; } }