io.reactivex.Maybe Maven / Gradle / Ivy
Show all versions of rxjava 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;
import java.util.NoSuchElementException;
import java.util.concurrent.*;
import org.reactivestreams.*;
import io.reactivex.annotations.*;
import io.reactivex.disposables.Disposable;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.functions.*;
import io.reactivex.internal.functions.*;
import io.reactivex.internal.fuseable.*;
import io.reactivex.internal.observers.BlockingMultiObserver;
import io.reactivex.internal.operators.flowable.*;
import io.reactivex.internal.operators.maybe.*;
import io.reactivex.internal.operators.mixed.*;
import io.reactivex.internal.util.*;
import io.reactivex.observers.TestObserver;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.Schedulers;
/**
* The {@code Maybe} class represents a deferred computation and emission of a single value, no value at all or an exception.
*
* The {@code Maybe} class implements the {@link MaybeSource} base interface and the default consumer
* type it interacts with is the {@link MaybeObserver} via the {@link #subscribe(MaybeObserver)} method.
*
* The {@code Maybe} operates with the following sequential protocol:
*
* onSubscribe (onSuccess | onError | onComplete)?
*
*
* Note that {@code onSuccess}, {@code onError} and {@code onComplete} are mutually exclusive events; unlike {@code Observable},
* {@code onSuccess} is never followed by {@code onError} or {@code onComplete}.
*
* Like {@link Observable}, a running {@code Maybe} can be stopped through the {@link Disposable} instance
* provided to consumers through {@link MaybeObserver#onSubscribe}.
*
* Like an {@code Observable}, a {@code Maybe} is lazy, can be either "hot" or "cold", synchronous or
* asynchronous. {@code Maybe} instances returned by the methods of this class are cold
* and there is a standard hot implementation in the form of a subject:
* {@link io.reactivex.subjects.MaybeSubject MaybeSubject}.
*
* The documentation for this class makes use of marble diagrams. The following legend explains these diagrams:
*
*
*
* See {@link Flowable} or {@link Observable} for the
* implementation of the Reactive Pattern for a stream or vector of values.
*
* Example:
*
* Disposable d = Maybe.just("Hello World")
* .delay(10, TimeUnit.SECONDS, Schedulers.io())
* .subscribeWith(new DisposableMaybeObserver<String>() {
* @Override
* public void onStart() {
* System.out.println("Started");
* }
*
* @Override
* public void onSuccess(String value) {
* System.out.println("Success: " + value);
* }
*
* @Override
* public void onError(Throwable error) {
* error.printStackTrace();
* }
*
* @Override
* public void onComplete() {
* System.out.println("Done!");
* }
* });
*
* Thread.sleep(5000);
*
* d.dispose();
*
*
* Note that by design, subscriptions via {@link #subscribe(MaybeObserver)} can't be disposed
* from the outside (hence the
* {@code void} return of the {@link #subscribe(MaybeObserver)} method) and it is the
* responsibility of the implementor of the {@code MaybeObserver} to allow this to happen.
* RxJava supports such usage with the standard
* {@link io.reactivex.observers.DisposableMaybeObserver DisposableMaybeObserver} instance.
* For convenience, the {@link #subscribeWith(MaybeObserver)} method is provided as well to
* allow working with a {@code MaybeObserver} (or subclass) instance to be applied with in
* a fluent manner (such as in the example above).
*
* @param the value type
* @since 2.0
* @see io.reactivex.observers.DisposableMaybeObserver
*/
public abstract class Maybe implements MaybeSource {
/**
* Runs multiple MaybeSources and signals the events of the first one that signals (disposing
* 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
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Maybe amb(final Iterable extends MaybeSource extends T>> sources) {
ObjectHelper.requireNonNull(sources, "sources is null");
return RxJavaPlugins.onAssembly(new MaybeAmb(null, sources));
}
/**
* Runs multiple MaybeSources and signals the events of the first one that signals (disposing
* 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 RxJavaPlugins.onAssembly(new MaybeAmb(sources, null));
}
/**
* Concatenate the single values, in a non-overlapping fashion, of the MaybeSource sources provided by
* an Iterable sequence.
*
*
*
* - Backpressure:
* - The returned {@code Flowable} honors the backpressure of the downstream consumer.
* - 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 Flowable instance
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable concat(Iterable extends MaybeSource extends T>> sources) {
ObjectHelper.requireNonNull(sources, "sources is null");
return RxJavaPlugins.onAssembly(new MaybeConcatIterable(sources));
}
/**
* Returns a Flowable that emits the items emitted by two MaybeSources, one after the other.
*
*
*
* - Backpressure:
* - The returned {@code Flowable} honors the backpressure of the downstream consumer.
* - 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 a Flowable that emits items emitted by the two source MaybeSources, one after the other.
* @see ReactiveX operators documentation: Concat
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public static Flowable 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 a Flowable that emits the items emitted by three MaybeSources, one after the other.
*
*
*
* - Backpressure:
* - The returned {@code Flowable} honors the backpressure of the downstream consumer.
* - 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 a Flowable that emits items emitted by the three source MaybeSources, one after the other.
* @see ReactiveX operators documentation: Concat
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public static Flowable 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 a Flowable that emits the items emitted by four MaybeSources, one after the other.
*
*
*
* - Backpressure:
* - The returned {@code Flowable} honors the backpressure of the downstream consumer.
* - 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 a Flowable that emits items emitted by the four source MaybeSources, one after the other.
* @see ReactiveX operators documentation: Concat
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public static Flowable 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
* a Publisher sequence.
*
*
*
* - Backpressure:
* - The returned {@code Flowable} honors the backpressure of the downstream consumer and
* expects the {@code Publisher} to honor backpressure as well. If the sources {@code Publisher}
* violates this, a {@link io.reactivex.exceptions.MissingBackpressureException} is signalled.
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type
* @param sources the Publisher of MaybeSource instances
* @return the new Flowable instance
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable concat(Publisher extends MaybeSource extends T>> sources) {
return concat(sources, 2);
}
/**
* Concatenate the single values, in a non-overlapping fashion, of the MaybeSource sources provided by
* a Publisher sequence.
*
*
*
* - Backpressure:
* - The returned {@code Flowable} honors the backpressure of the downstream consumer and
* expects the {@code Publisher} to honor backpressure as well. If the sources {@code Publisher}
* violates this, a {@link io.reactivex.exceptions.MissingBackpressureException} is signalled.
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type
* @param sources the Publisher of MaybeSource instances
* @param prefetch the number of MaybeSources to prefetch from the Publisher
* @return the new Flowable instance
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Flowable concat(Publisher extends MaybeSource extends T>> sources, int prefetch) {
ObjectHelper.requireNonNull(sources, "sources is null");
ObjectHelper.verifyPositive(prefetch, "prefetch");
return RxJavaPlugins.onAssembly(new FlowableConcatMapPublisher(sources, MaybeToPublisher.instance(), prefetch, ErrorMode.IMMEDIATE));
}
/**
* Concatenate the single values, in a non-overlapping fashion, of the MaybeSource sources in the array.
*
*
*
* - Backpressure:
* - The returned {@code Flowable} honors the backpressure of the downstream consumer.
* - 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 Flowable instance
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public static Flowable concatArray(MaybeSource extends T>... sources) {
ObjectHelper.requireNonNull(sources, "sources is null");
if (sources.length == 0) {
return Flowable.empty();
}
if (sources.length == 1) {
return RxJavaPlugins.onAssembly(new MaybeToFlowable((MaybeSource)sources[0]));
}
return RxJavaPlugins.onAssembly(new MaybeConcatArray(sources));
}
/**
* Concatenates a variable number of MaybeSource sources and delays errors from any of them
* till all terminate.
*
*
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - 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 Flowable instance
* @throws NullPointerException if sources is null
*/
@SuppressWarnings("unchecked")
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable concatArrayDelayError(MaybeSource extends T>... sources) {
if (sources.length == 0) {
return Flowable.empty();
} else
if (sources.length == 1) {
return RxJavaPlugins.onAssembly(new MaybeToFlowable((MaybeSource)sources[0]));
}
return RxJavaPlugins.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.
*
*
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - 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 Flowable instance with the specified concatenation behavior
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable concatArrayEager(MaybeSource extends T>... sources) {
return Flowable.fromArray(sources).concatMapEager((Function)MaybeToPublisher.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.
*
*
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - 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 Flowable with the concatenating behavior
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable concatDelayError(Iterable extends MaybeSource extends T>> sources) {
ObjectHelper.requireNonNull(sources, "sources is null");
return Flowable.fromIterable(sources).concatMapDelayError((Function)MaybeToPublisher.instance());
}
/**
* Concatenates the Publisher sequence of Publishers into a single sequence by subscribing to each inner Publisher,
* one after the other, one at a time and delays any errors till the all inner and the outer Publishers terminate.
*
*
*
* - Backpressure:
* - {@code concatDelayError} fully supports backpressure.
* - Scheduler:
* - {@code concatDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param sources the Publisher sequence of Publishers
* @return the new Publisher with the concatenating behavior
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable concatDelayError(Publisher extends MaybeSource extends T>> sources) {
return Flowable.fromPublisher(sources).concatMapDelayError((Function)MaybeToPublisher.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.
*
*
*
* - Backpressure:
* - Backpressure is honored towards the downstream.
* - 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 Flowable instance with the specified concatenation behavior
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable concatEager(Iterable extends MaybeSource extends T>> sources) {
return Flowable.fromIterable(sources).concatMapEager((Function)MaybeToPublisher.instance());
}
/**
* Concatenates a Publisher 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
* emitted source Publishers as they are observed. The operator buffers the values emitted by these
* Publishers and then drains them in order, each one after the previous one completes.
*
*
*
* - Backpressure:
* - Backpressure is honored towards the downstream and the outer Publisher is
* expected to support backpressure. Violating this assumption, the operator will
* signal {@link io.reactivex.exceptions.MissingBackpressureException}.
* - Scheduler:
* - This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type
* @param sources a sequence of Publishers that need to be eagerly concatenated
* @return the new Publisher instance with the specified concatenation behavior
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable concatEager(Publisher extends MaybeSource extends T>> sources) {
return Flowable.fromPublisher(sources).concatMapEager((Function)MaybeToPublisher.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
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Maybe create(MaybeOnSubscribe onSubscribe) {
ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null");
return RxJavaPlugins.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
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Maybe defer(final Callable extends MaybeSource extends T>> maybeSupplier) {
ObjectHelper.requireNonNull(maybeSupplier, "maybeSupplier is null");
return RxJavaPlugins.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 RxJavaPlugins.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
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Maybe error(Throwable exception) {
ObjectHelper.requireNonNull(exception, "exception is null");
return RxJavaPlugins.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
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Maybe error(Callable extends Throwable> supplier) {
ObjectHelper.requireNonNull(supplier, "errorSupplier is null");
return RxJavaPlugins.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}.
* - Error handling:
* - If the {@link Action} throws an exception, the respective {@link Throwable} is
* delivered to the downstream via {@link MaybeObserver#onError(Throwable)},
* except when the downstream has disposed this {@code Maybe} source.
* In this latter case, the {@code Throwable} is delivered to the global error handler via
* {@link RxJavaPlugins#onError(Throwable)} as an {@link io.reactivex.exceptions.UndeliverableException UndeliverableException}.
*
*
* @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
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Maybe fromAction(final Action run) {
ObjectHelper.requireNonNull(run, "run is null");
return RxJavaPlugins.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
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Maybe fromCompletable(CompletableSource completableSource) {
ObjectHelper.requireNonNull(completableSource, "completableSource is null");
return RxJavaPlugins.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
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Maybe fromSingle(SingleSource singleSource) {
ObjectHelper.requireNonNull(singleSource, "singleSource is null");
return RxJavaPlugins.onAssembly(new MaybeFromSingle(singleSource));
}
/**
* Returns a {@link Maybe} that invokes the given {@link Callable} for each individual {@link MaybeObserver} that
* subscribes and emits the resulting non-null item via {@code onSuccess} while
* considering a {@code null} result from the {@code Callable} as indication for valueless completion
* via {@code onComplete}.
*
* This operator allows you to defer the execution of the given {@code Callable} until a {@code MaybeObserver}
* subscribes to the returned {@link Maybe}. In other terms, this source operator evaluates the given
* {@code Callable} "lazily".
*
* Note that the {@code null} handling of this operator differs from the similar source operators in the other
* {@link io.reactivex base reactive classes}. Those operators signal a {@code NullPointerException} if the value returned by their
* {@code Callable} is {@code null} while this {@code fromCallable} considers it to indicate the
* returned {@code Maybe} is empty.
*
* - Scheduler:
* - {@code fromCallable} does not operate by default on a particular {@link Scheduler}.
* - Error handling:
* - Any non-fatal exception thrown by {@link Callable#call()} will be forwarded to {@code onError},
* except if the {@code MaybeObserver} disposed the subscription in the meantime. In this latter case,
* the exception is forwarded to the global error handler via
* {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)} wrapped into a
* {@link io.reactivex.exceptions.UndeliverableException UndeliverableException}.
* Fatal exceptions are rethrown and usually will end up in the executing thread's
* {@link java.lang.Thread.UncaughtExceptionHandler#uncaughtException(Thread, Throwable)} handler.
*
*
* @param callable
* a {@link Callable} instance whose execution should be deferred and performed for each individual
* {@code MaybeObserver} that subscribes to the returned {@link Maybe}.
* @param
* the type of the item emitted by the {@link Maybe}.
* @return a new Maybe instance
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Maybe fromCallable(@NonNull final Callable extends T> callable) {
ObjectHelper.requireNonNull(callable, "callable is null");
return RxJavaPlugins.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, disposing 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
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Maybe fromFuture(Future extends T> future) {
ObjectHelper.requireNonNull(future, "future is null");
return RxJavaPlugins.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, disposing 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
@NonNull
@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 RxJavaPlugins.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
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Maybe fromRunnable(final Runnable run) {
ObjectHelper.requireNonNull(run, "run is null");
return RxJavaPlugins.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
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Maybe just(T item) {
ObjectHelper.requireNonNull(item, "item is null");
return RxJavaPlugins.onAssembly(new MaybeJust(item));
}
/**
* Merges an Iterable sequence of MaybeSource instances into a single Flowable sequence,
* running all MaybeSources at once.
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - Scheduler:
* - {@code merge} does not operate by default on a particular {@link Scheduler}.
* - Error handling:
* - If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting
* {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed.
* If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the
* first one's error or, depending on the concurrency of the sources, may terminate with a
* {@code CompositeException} containing two or more of the various error signals.
* {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via
* {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s
* signaled by source(s) after the returned {@code Flowable} has been cancelled or terminated with a
* (composite) error will be sent to the same global error handler.
* Use {@link #mergeDelayError(Iterable)} to merge sources and terminate only when all source {@code MaybeSource}s
* have completed or failed with an error.
*
*
* @param the common and resulting value type
* @param sources the Iterable sequence of MaybeSource sources
* @return the new Flowable instance
* @see #mergeDelayError(Iterable)
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable merge(Iterable extends MaybeSource extends T>> sources) {
return merge(Flowable.fromIterable(sources));
}
/**
* Merges a Flowable sequence of MaybeSource instances into a single Flowable sequence,
* running all MaybeSources at once.
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - Scheduler:
* - {@code merge} does not operate by default on a particular {@link Scheduler}.
* - Error handling:
* - If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting
* {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed.
* If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the
* first one's error or, depending on the concurrency of the sources, may terminate with a
* {@code CompositeException} containing two or more of the various error signals.
* {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via
* {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s
* signaled by source(s) after the returned {@code Flowable} has been cancelled or terminated with a
* (composite) error will be sent to the same global error handler.
* Use {@link #mergeDelayError(Publisher)} to merge sources and terminate only when all source {@code MaybeSource}s
* have completed or failed with an error.
*
*
* @param the common and resulting value type
* @param sources the Flowable sequence of MaybeSource sources
* @return the new Flowable instance
* @see #mergeDelayError(Publisher)
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable merge(Publisher extends MaybeSource extends T>> sources) {
return merge(sources, Integer.MAX_VALUE);
}
/**
* Merges a Flowable sequence of MaybeSource instances into a single Flowable sequence,
* running at most maxConcurrency MaybeSources at once.
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - Scheduler:
* - {@code merge} does not operate by default on a particular {@link Scheduler}.
* - Error handling:
* - If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting
* {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed.
* If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the
* first one's error or, depending on the concurrency of the sources, may terminate with a
* {@code CompositeException} containing two or more of the various error signals.
* {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via
* {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s
* signaled by source(s) after the returned {@code Flowable} has been cancelled or terminated with a
* (composite) error will be sent to the same global error handler.
* Use {@link #mergeDelayError(Publisher, int)} to merge sources and terminate only when all source {@code MaybeSource}s
* have completed or failed with an error.
*
*
* @param the common and resulting value type
* @param sources the Flowable sequence of MaybeSource sources
* @param maxConcurrency the maximum number of concurrently running MaybeSources
* @return the new Flowable instance
* @see #mergeDelayError(Publisher, int)
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Flowable merge(Publisher extends MaybeSource extends T>> sources, int maxConcurrency) {
ObjectHelper.requireNonNull(sources, "source is null");
ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency");
return RxJavaPlugins.onAssembly(new FlowableFlatMapPublisher(sources, MaybeToPublisher.instance(), false, maxConcurrency, 1));
}
/**
* 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}.
* - Error handling:
* - The resulting {@code Maybe} emits the outer source's or the inner {@code MaybeSource}'s {@code Throwable} as is.
* Unlike the other {@code merge()} operators, this operator won't and can't produce a {@code CompositeException} because there is
* only one possibility for the outer or the inner {@code MaybeSource} to emit an {@code onError} signal.
* Therefore, there is no need for a {@code mergeDelayError(MaybeSource
>)} operator.
*
*
*
* @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
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Maybe merge(MaybeSource extends MaybeSource extends T>> source) {
ObjectHelper.requireNonNull(source, "source is null");
return RxJavaPlugins.onAssembly(new MaybeFlatten(source, Functions.identity()));
}
/**
* Flattens two MaybeSources into a single Flowable, without any transformation.
*
*
*
* You can combine items emitted by multiple MaybeSources so that they appear as a single Flowable, by
* using the {@code merge} method.
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - Scheduler:
* - {@code merge} does not operate by default on a particular {@link Scheduler}.
* - Error handling:
* - If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting
* {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed.
* If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the
* first one's error or, depending on the concurrency of the sources, may terminate with a
* {@code CompositeException} containing two or more of the various error signals.
* {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via
* {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s
* signaled by source(s) after the returned {@code Flowable} has been cancelled or terminated with a
* (composite) error will be sent to the same global error handler.
* Use {@link #mergeDelayError(MaybeSource, MaybeSource)} to merge sources and terminate only when all source {@code MaybeSource}s
* have completed or failed with an error.
*
*
*
* @param the common value type
* @param source1
* a MaybeSource to be merged
* @param source2
* a MaybeSource to be merged
* @return a Flowable that emits all of the items emitted by the source MaybeSources
* @see ReactiveX operators documentation: Merge
* @see #mergeDelayError(MaybeSource, MaybeSource)
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public static Flowable 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 Flowable, without any transformation.
*
*
*
* You can combine items emitted by multiple MaybeSources so that they appear as a single Flowable, by using
* the {@code merge} method.
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - Scheduler:
* - {@code merge} does not operate by default on a particular {@link Scheduler}.
* - Error handling:
* - If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting
* {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed.
* If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the
* first one's error or, depending on the concurrency of the sources, may terminate with a
* {@code CompositeException} containing two or more of the various error signals.
* {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via
* {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s
* signaled by source(s) after the returned {@code Flowable} has been cancelled or terminated with a
* (composite) error will be sent to the same global error handler.
* Use {@link #mergeDelayError(MaybeSource, MaybeSource, MaybeSource)} to merge sources and terminate only when all source {@code MaybeSource}s
* have completed or failed with an error.
*
*
*
* @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 a Flowable that emits all of the items emitted by the source MaybeSources
* @see ReactiveX operators documentation: Merge
* @see #mergeDelayError(MaybeSource, MaybeSource, MaybeSource)
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public static Flowable 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 Flowable, without any transformation.
*
*
*
* You can combine items emitted by multiple MaybeSources so that they appear as a single Flowable, by using
* the {@code merge} method.
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - Scheduler:
* - {@code merge} does not operate by default on a particular {@link Scheduler}.
* - Error handling:
* - If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting
* {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed.
* If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the
* first one's error or, depending on the concurrency of the sources, may terminate with a
* {@code CompositeException} containing two or more of the various error signals.
* {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via
* {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s
* signaled by source(s) after the returned {@code Flowable} has been cancelled or terminated with a
* (composite) error will be sent to the same global error handler.
* Use {@link #mergeDelayError(MaybeSource, MaybeSource, MaybeSource, MaybeSource)} to merge sources and terminate only when all source {@code MaybeSource}s
* have completed or failed with an error.
*
*
*
* @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 a Flowable that emits all of the items emitted by the source MaybeSources
* @see ReactiveX operators documentation: Merge
* @see #mergeDelayError(MaybeSource, MaybeSource, MaybeSource, MaybeSource)
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public static Flowable 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 Flowable sequence,
* running all MaybeSources at once.
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - Scheduler:
* - {@code mergeArray} does not operate by default on a particular {@link Scheduler}.
* - Error handling:
* - If any of the source {@code MaybeSource}s signal a {@code Throwable} via {@code onError}, the resulting
* {@code Flowable} terminates with that {@code Throwable} and all other source {@code MaybeSource}s are disposed.
* If more than one {@code MaybeSource} signals an error, the resulting {@code Flowable} may terminate with the
* first one's error or, depending on the concurrency of the sources, may terminate with a
* {@code CompositeException} containing two or more of the various error signals.
* {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via
* {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s
* signaled by source(s) after the returned {@code Flowable} has been cancelled or terminated with a
* (composite) error will be sent to the same global error handler.
* Use {@link #mergeArrayDelayError(MaybeSource...)} to merge sources and terminate only when all source {@code MaybeSource}s
* have completed or failed with an error.
*
*
* @param the common and resulting value type
* @param sources the array sequence of MaybeSource sources
* @return the new Flowable instance
* @see #mergeArrayDelayError(MaybeSource...)
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public static Flowable mergeArray(MaybeSource extends T>... sources) {
ObjectHelper.requireNonNull(sources, "sources is null");
if (sources.length == 0) {
return Flowable.empty();
}
if (sources.length == 1) {
return RxJavaPlugins.onAssembly(new MaybeToFlowable((MaybeSource)sources[0]));
}
return RxJavaPlugins.onAssembly(new MaybeMergeArray(sources));
}
/**
* Flattens an array of MaybeSources into one Flowable, in a way that allows a Subscriber 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(Publisher)} except that if any of the merged MaybeSources notify of an
* error via {@link Subscriber#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 Subscribers once.
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - 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 a Flowable 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" })
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable mergeArrayDelayError(MaybeSource extends T>... sources) {
if (sources.length == 0) {
return Flowable.empty();
}
return Flowable.fromArray(sources).flatMap((Function)MaybeToPublisher.instance(), true, sources.length);
}
/**
* Flattens an Iterable of MaybeSources into one Flowable, in a way that allows a Subscriber 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(Publisher)} except that if any of the merged MaybeSources notify of an
* error via {@link Subscriber#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 Subscribers once.
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - 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 a Flowable 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" })
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable mergeDelayError(Iterable extends MaybeSource extends T>> sources) {
return Flowable.fromIterable(sources).flatMap((Function)MaybeToPublisher.instance(), true);
}
/**
* Flattens a Publisher that emits MaybeSources into one Publisher, in a way that allows a Subscriber to
* receive all successfully emitted items from all of the source MaybeSources without being interrupted by
* an error notification from one of them or even the main Publisher.
*
* This behaves like {@link #merge(Publisher)} except that if any of the merged MaybeSources notify of an
* error via {@link Subscriber#onError onError}, {@code mergeDelayError} will refrain from propagating that
* error notification until all of the merged MaybeSources and the main Publisher have finished emitting items.
*
*
*
* Even if multiple merged Publishers send {@code onError} notifications, {@code mergeDelayError} will only
* invoke the {@code onError} method of its Subscribers once.
*
* - Backpressure:
* - The operator honors backpressure from downstream. The outer {@code Publisher} is consumed
* in unbounded mode (i.e., no backpressure is applied to it).
* - Scheduler:
* - {@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param sources
* a Publisher that emits MaybeSources
* @return a Flowable that emits all of the items emitted by the Publishers emitted by the
* {@code source} Publisher
* @see ReactiveX operators documentation: Merge
*/
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable mergeDelayError(Publisher extends MaybeSource extends T>> sources) {
return mergeDelayError(sources, Integer.MAX_VALUE);
}
/**
* Flattens a Publisher that emits MaybeSources into one Publisher, in a way that allows a Subscriber to
* receive all successfully emitted items from all of the source MaybeSources without being interrupted by
* an error notification from one of them or even the main Publisher as well as limiting the total number of active MaybeSources.
*
* This behaves like {@link #merge(Publisher, int)} except that if any of the merged MaybeSources notify of an
* error via {@link Subscriber#onError onError}, {@code mergeDelayError} will refrain from propagating that
* error notification until all of the merged MaybeSources and the main Publisher have finished emitting items.
*
*
*
* Even if multiple merged Publishers send {@code onError} notifications, {@code mergeDelayError} will only
* invoke the {@code onError} method of its Subscribers once.
*
* - Backpressure:
* - The operator honors backpressure from downstream. The outer {@code Publisher} is consumed
* in unbounded mode (i.e., no backpressure is applied to it).
* - Scheduler:
* - {@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* History: 2.1.9 - experimental
* @param the common element base type
* @param sources
* a Publisher that emits MaybeSources
* @param maxConcurrency the maximum number of active inner MaybeSources to be merged at a time
* @return a Flowable that emits all of the items emitted by the Publishers emitted by the
* {@code source} Publisher
* @see ReactiveX operators documentation: Merge
* @since 2.2
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable mergeDelayError(Publisher extends MaybeSource extends T>> sources, int maxConcurrency) {
ObjectHelper.requireNonNull(sources, "source is null");
ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency");
return RxJavaPlugins.onAssembly(new FlowableFlatMapPublisher(sources, MaybeToPublisher.instance(), true, maxConcurrency, 1));
}
/**
* Flattens two MaybeSources into one Flowable, in a way that allows a Subscriber 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 Subscriber#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 Subscribers once.
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - 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 a Flowable that emits all of the items that are emitted by the two source MaybeSources
* @see ReactiveX operators documentation: Merge
*/
@SuppressWarnings({ "unchecked" })
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable 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 Flowable, in a way that allows a Subscriber 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 Subscriber#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 Subscribers once.
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - 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 a Flowable that emits all of the items that are emitted by the source MaybeSources
* @see ReactiveX operators documentation: Merge
*/
@SuppressWarnings({ "unchecked" })
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable 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 Flowable, in a way that allows a Subscriber 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 Subscriber#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 Subscribers once.
*
* - Backpressure:
* - The operator honors backpressure from downstream.
* - 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 a Flowable that emits all of the items that are emitted by the source MaybeSources
* @see ReactiveX operators documentation: Merge
*/
@SuppressWarnings({ "unchecked" })
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable 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 RxJavaPlugins.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
@NonNull
@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 RxJavaPlugins.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
@NonNull
@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 RxJavaPlugins.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
@NonNull
@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 RxJavaPlugins.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
@NonNull
@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 RxJavaPlugins.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
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Maybe wrap(MaybeSource source) {
if (source instanceof Maybe) {
return RxJavaPlugins.onAssembly((Maybe)source);
}
ObjectHelper.requireNonNull(source, "onSubscribe is null");
return RxJavaPlugins.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
@NonNull
@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 RxJavaPlugins.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
@NonNull
@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
@NonNull
@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
@NonNull
@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
@NonNull
@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
@NonNull
@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
@NonNull
@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