io.reactivex.observable.Maybe Maven / Gradle / Ivy
Show all versions of rxjava3-observable Show documentation
/**
* 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 extends MaybeSource extends T>> 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 extends T>... 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 extends MaybeSource extends T>> 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 extends T> source1, MaybeSource extends T> 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 extends T> source1, MaybeSource extends T> source2, MaybeSource extends T> 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 extends T> source1, MaybeSource extends T> source2, MaybeSource extends T> source3, MaybeSource extends T> 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 extends MaybeSource extends T>> 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 extends MaybeSource extends T>> 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 extends T>... 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 extends T>... 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 extends T>... 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 extends MaybeSource extends T>> 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 extends MaybeSource extends T>> 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 extends MaybeSource extends T>> 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 extends MaybeSource extends T>> 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 extends MaybeSource extends T>> 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 extends Throwable> 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 extends T> 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 extends T> 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 extends T> 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 extends MaybeSource extends T>> 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 extends MaybeSource extends T>> 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 extends MaybeSource extends T>> 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 extends MaybeSource extends T>> 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 extends T> source1, MaybeSource extends T> 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 extends T> source1, MaybeSource extends T> source2,
MaybeSource extends T> 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 extends T> source1, MaybeSource extends T> source2,
MaybeSource extends T> source3, MaybeSource extends T> 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 extends T>... 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 extends T>... 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 extends MaybeSource extends T>> 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 extends MaybeSource extends T>> 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 extends T> source1, MaybeSource extends T> 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 extends T> source1,
MaybeSource extends T> source2, MaybeSource extends T> 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 extends T> source1, MaybeSource extends T> source2,
MaybeSource extends T> source3, MaybeSource extends T> 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 extends T> source1, MaybeSource extends T> 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 extends T> source1, MaybeSource extends T> source2,
BiPredicate super T, ? super T> 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 extends D> resourceSupplier,
Function super D, ? extends MaybeSource extends T>> sourceSupplier,
Consumer super D> 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 extends D> resourceSupplier,
Function super D, ? extends MaybeSource extends T>> sourceSupplier,
Consumer super D> 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 extends MaybeSource extends T>> sources, Function super Object[], ? extends R> 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 extends T1> source1, MaybeSource extends T2> source2,
BiFunction super T1, ? super T2, ? extends R> 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 extends T1> source1, MaybeSource extends T2> source2, MaybeSource extends T3> source3,
Function3 super T1, ? super T2, ? super T3, ? extends R> 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 extends T1> source1, MaybeSource extends T2> source2, MaybeSource extends T3> source3,
MaybeSource extends T4> source4,
Function4 super T1, ? super T2, ? super T3, ? super T4, ? extends R> 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 extends T1> source1, MaybeSource extends T2> source2, MaybeSource extends T3> source3,
MaybeSource extends T4> source4, MaybeSource extends T5> source5,
Function5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> 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 extends T1> source1, MaybeSource extends T2> source2, MaybeSource extends T3> source3,
MaybeSource extends T4> source4, MaybeSource extends T5> source5, MaybeSource extends T6> source6,
Function6 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> 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 extends T1> source1, MaybeSource extends T2> source2, MaybeSource extends T3> source3,
MaybeSource extends T4> source4, MaybeSource extends T5> source5, MaybeSource extends T6> source6,
MaybeSource extends T7> source7,
Function7 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> 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