io.reactivex.Observable 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.*;
import java.util.concurrent.*;
import org.reactivestreams.Publisher;
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.ScalarCallable;
import io.reactivex.internal.observers.*;
import io.reactivex.internal.operators.flowable.*;
import io.reactivex.internal.operators.mixed.*;
import io.reactivex.internal.operators.observable.*;
import io.reactivex.internal.util.*;
import io.reactivex.observables.*;
import io.reactivex.observers.*;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.*;
/**
* The Observable class is the non-backpressured, optionally multi-valued base reactive class that
* offers factory methods, intermediate operators and the ability to consume synchronous
* and/or asynchronous reactive dataflows.
*
* Many operators in the class accept {@code ObservableSource}(s), the base reactive interface
* for such non-backpressured flows, which {@code Observable} itself implements as well.
*
* The Observable's operators, by default, run with a buffer size of 128 elements (see {@link Flowable#bufferSize()}),
* that can be overridden globally via the system parameter {@code rx2.buffer-size}. Most operators, however, have
* overloads that allow setting their internal buffer size explicitly.
*
* The documentation for this class makes use of marble diagrams. The following legend explains these diagrams:
*
*
*
* The design of this class was derived from the
* Reactive Streams design and specification
* by removing any backpressure-related infrastructure and implementation detail, replacing the
* {@code org.reactivestreams.Subscription} with {@link Disposable} as the primary means to dispose of
* a flow.
*
* The {@code Observable} follows the protocol
*
* onSubscribe onNext* (onError | onComplete)?
*
* where
* the stream can be disposed through the {@code Disposable} instance provided to consumers through
* {@code Observer.onSubscribe}.
*
* Unlike the {@code Observable} of version 1.x, {@link #subscribe(Observer)} does not allow external disposal
* of a subscription and the {@code Observer} instance is expected to expose such capability.
*
Example:
*
* Disposable d = Observable.just("Hello world!")
* .delay(1, TimeUnit.SECONDS)
* .subscribeWith(new DisposableObserver<String>() {
* @Override public void onStart() {
* System.out.println("Start!");
* }
* @Override public void onNext(String t) {
* System.out.println(t);
* }
* @Override public void onError(Throwable t) {
* t.printStackTrace();
* }
* @Override public void onComplete() {
* System.out.println("Done!");
* }
* });
*
* Thread.sleep(500);
* // the sequence can now be disposed via dispose()
* d.dispose();
*
*
* @param
* the type of the items emitted by the Observable
* @see Flowable
* @see io.reactivex.observers.DisposableObserver
*/
public abstract class Observable implements ObservableSource {
/**
* Mirrors the one ObservableSource in an Iterable of several ObservableSources that first either emits an item or sends
* a termination notification.
*
*
*
* - Scheduler:
* - {@code amb} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element type
* @param sources
* an Iterable of ObservableSource sources competing to react first. A subscription to each source will
* occur in the same order as in the Iterable.
* @return an Observable that emits the same sequence as whichever of the source ObservableSources first
* emitted an item or sent a termination notification
* @see ReactiveX operators documentation: Amb
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable amb(Iterable extends ObservableSource extends T>> sources) {
ObjectHelper.requireNonNull(sources, "sources is null");
return RxJavaPlugins.onAssembly(new ObservableAmb(null, sources));
}
/**
* Mirrors the one ObservableSource in an array of several ObservableSources that first either emits an item or sends
* a termination notification.
*
*
*
* - Scheduler:
* - {@code ambArray} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element type
* @param sources
* an array of ObservableSource sources competing to react first. A subscription to each source will
* occur in the same order as in the array.
* @return an Observable that emits the same sequence as whichever of the source ObservableSources first
* emitted an item or sent a termination notification
* @see ReactiveX operators documentation: Amb
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable ambArray(ObservableSource extends T>... sources) {
ObjectHelper.requireNonNull(sources, "sources is null");
int len = sources.length;
if (len == 0) {
return empty();
}
if (len == 1) {
return (Observable)wrap(sources[0]);
}
return RxJavaPlugins.onAssembly(new ObservableAmb(sources, null));
}
/**
* Returns the default 'island' size or capacity-increment hint for unbounded buffers.
* Delegates to {@link Flowable#bufferSize} but is public for convenience.
*
The value can be overridden via system parameter {@code rx2.buffer-size}
* before the {@link Flowable} class is loaded.
* @return the default 'island' size or capacity-increment hint
*/
public static int bufferSize() {
return Flowable.bufferSize();
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* 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}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
* If there are no ObservableSources provided, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @param bufferSize
* the internal buffer size and prefetch amount applied to every source Observable
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(Function super Object[], ? extends R> combiner, int bufferSize, ObservableSource extends T>... sources) {
return combineLatest(sources, combiner, bufferSize);
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* 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}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
* If the provided iterable of ObservableSources is empty, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(Iterable extends ObservableSource extends T>> sources,
Function super Object[], ? extends R> combiner) {
return combineLatest(sources, combiner, bufferSize());
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* 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}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
* If the provided iterable of ObservableSources is empty, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @param bufferSize
* the internal buffer size and prefetch amount applied to every source Observable
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(Iterable extends ObservableSource extends T>> sources,
Function super Object[], ? extends R> combiner, int bufferSize) {
ObjectHelper.requireNonNull(sources, "sources is null");
ObjectHelper.requireNonNull(combiner, "combiner is null");
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
// the queue holds a pair of values so we need to double the capacity
int s = bufferSize << 1;
return RxJavaPlugins.onAssembly(new ObservableCombineLatest(null, sources, combiner, s, false));
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* 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}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
* If the provided array of ObservableSources is empty, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(ObservableSource extends T>[] sources,
Function super Object[], ? extends R> combiner) {
return combineLatest(sources, combiner, bufferSize());
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* 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}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
* If the provided array of ObservableSources is empty, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @param bufferSize
* the internal buffer size and prefetch amount applied to every source Observable
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(ObservableSource extends T>[] sources,
Function super Object[], ? extends R> combiner, int bufferSize) {
ObjectHelper.requireNonNull(sources, "sources is null");
if (sources.length == 0) {
return empty();
}
ObjectHelper.requireNonNull(combiner, "combiner is null");
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
// the queue holds a pair of values so we need to double the capacity
int s = bufferSize << 1;
return RxJavaPlugins.onAssembly(new ObservableCombineLatest(sources, null, combiner, s, false));
}
/**
* Combines two source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from either of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
BiFunction super T1, ? super T2, ? extends R> combiner) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2);
}
/**
* Combines three source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3,
Function3 super T1, ? super T2, ? super T3, ? extends R> combiner) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3);
}
/**
* Combines four source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the element type of the fourth source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param source4
* the fourth source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3, ObservableSource extends T4> source4,
Function4 super T1, ? super T2, ? super T3, ? super T4, ? extends R> combiner) {
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 combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4);
}
/**
* Combines five source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the element type of the fourth source
* @param the element type of the fifth source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param source4
* the fourth source ObservableSource
* @param source5
* the fifth source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3, ObservableSource extends T4> source4,
ObservableSource extends T5> source5,
Function5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> combiner) {
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 combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5);
}
/**
* Combines six source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the element type of the fourth source
* @param the element type of the fifth source
* @param the element type of the sixth source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param source4
* the fourth source ObservableSource
* @param source5
* the fifth source ObservableSource
* @param source6
* the sixth source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3, ObservableSource extends T4> source4,
ObservableSource extends T5> source5, ObservableSource extends T6> source6,
Function6 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> combiner) {
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 combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5, source6);
}
/**
* Combines seven source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the element type of the fourth source
* @param the element type of the fifth source
* @param the element type of the sixth source
* @param the element type of the seventh source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param source4
* the fourth source ObservableSource
* @param source5
* the fifth source ObservableSource
* @param source6
* the sixth source ObservableSource
* @param source7
* the seventh source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3, ObservableSource extends T4> source4,
ObservableSource extends T5> source5, ObservableSource extends T6> source6,
ObservableSource extends T7> source7,
Function7 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> combiner) {
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 combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5, source6, source7);
}
/**
* Combines eight source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the element type of the fourth source
* @param the element type of the fifth source
* @param the element type of the sixth source
* @param the element type of the seventh source
* @param the element type of the eighth source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param source4
* the fourth source ObservableSource
* @param source5
* the fifth source ObservableSource
* @param source6
* the sixth source ObservableSource
* @param source7
* the seventh source ObservableSource
* @param source8
* the eighth source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3, ObservableSource extends T4> source4,
ObservableSource extends T5> source5, ObservableSource extends T6> source6,
ObservableSource extends T7> source7, ObservableSource extends T8> source8,
Function8 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> combiner) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
ObjectHelper.requireNonNull(source4, "source4 is null");
ObjectHelper.requireNonNull(source5, "source5 is null");
ObjectHelper.requireNonNull(source6, "source6 is null");
ObjectHelper.requireNonNull(source7, "source7 is null");
ObjectHelper.requireNonNull(source8, "source8 is null");
return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5, source6, source7, source8);
}
/**
* Combines nine source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the element type of the fourth source
* @param the element type of the fifth source
* @param the element type of the sixth source
* @param the element type of the seventh source
* @param the element type of the eighth source
* @param the element type of the ninth source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param source4
* the fourth source ObservableSource
* @param source5
* the fifth source ObservableSource
* @param source6
* the sixth source ObservableSource
* @param source7
* the seventh source ObservableSource
* @param source8
* the eighth source ObservableSource
* @param source9
* the ninth source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3, ObservableSource extends T4> source4,
ObservableSource extends T5> source5, ObservableSource extends T6> source6,
ObservableSource extends T7> source7, ObservableSource extends T8> source8,
ObservableSource extends T9> source9,
Function9 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9, ? extends R> combiner) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
ObjectHelper.requireNonNull(source4, "source4 is null");
ObjectHelper.requireNonNull(source5, "source5 is null");
ObjectHelper.requireNonNull(source6, "source6 is null");
ObjectHelper.requireNonNull(source7, "source7 is null");
ObjectHelper.requireNonNull(source8, "source8 is null");
ObjectHelper.requireNonNull(source9, "source9 is null");
return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5, source6, source7, source8, source9);
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
*
*
* 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}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
* If the provided array of ObservableSources is empty, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
* - Scheduler:
* - {@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatestDelayError(ObservableSource extends T>[] sources,
Function super Object[], ? extends R> combiner) {
return combineLatestDelayError(sources, combiner, bufferSize());
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function and delays any error from the sources until
* all source ObservableSources terminate.
*
*
*
* 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}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
* If there are no ObservableSources provided, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
* - Scheduler:
* - {@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @param bufferSize
* the internal buffer size and prefetch amount applied to every source Observable
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatestDelayError(Function super Object[], ? extends R> combiner,
int bufferSize, ObservableSource extends T>... sources) {
return combineLatestDelayError(sources, combiner, bufferSize);
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function and delays any error from the sources until
* all source ObservableSources terminate.
*
* 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}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
* If the provided array of ObservableSources is empty, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
*
*
* - Scheduler:
* - {@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @param bufferSize
* the internal buffer size and prefetch amount applied to every source Observable
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatestDelayError(ObservableSource extends T>[] sources,
Function super Object[], ? extends R> combiner, int bufferSize) {
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
ObjectHelper.requireNonNull(combiner, "combiner is null");
if (sources.length == 0) {
return empty();
}
// the queue holds a pair of values so we need to double the capacity
int s = bufferSize << 1;
return RxJavaPlugins.onAssembly(new ObservableCombineLatest(sources, null, combiner, s, true));
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function and delays any error from the sources until
* all source ObservableSources terminate.
*
* 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}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
* If the provided iterable of ObservableSources is empty, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
*
*
* - Scheduler:
* - {@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatestDelayError(Iterable extends ObservableSource extends T>> sources,
Function super Object[], ? extends R> combiner) {
return combineLatestDelayError(sources, combiner, bufferSize());
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function and delays any error from the sources until
* all source ObservableSources terminate.
*
* 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}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
* If the provided iterable of ObservableSources is empty, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
*
*
* - Scheduler:
* - {@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @param bufferSize
* the internal buffer size and prefetch amount applied to every source Observable
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatestDelayError(Iterable extends ObservableSource extends T>> sources,
Function super Object[], ? extends R> combiner, int bufferSize) {
ObjectHelper.requireNonNull(sources, "sources is null");
ObjectHelper.requireNonNull(combiner, "combiner is null");
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
// the queue holds a pair of values so we need to double the capacity
int s = bufferSize << 1;
return RxJavaPlugins.onAssembly(new ObservableCombineLatest(null, sources, combiner, s, true));
}
/**
* Concatenates elements of each ObservableSource provided via an Iterable sequence into a single sequence
* of elements without interleaving them.
*
*
*
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
* @param the common value type of the sources
* @param sources the Iterable sequence of ObservableSources
* @return the new Observable instance
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(Iterable extends ObservableSource extends T>> sources) {
ObjectHelper.requireNonNull(sources, "sources is null");
return fromIterable(sources).concatMapDelayError((Function)Functions.identity(), bufferSize(), false);
}
/**
* Returns an Observable that emits the items emitted by each of the ObservableSources emitted by the source
* ObservableSource, one after the other, without interleaving them.
*
*
*
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param sources
* an ObservableSource that emits ObservableSources
* @return an Observable that emits items all of the items emitted by the ObservableSources emitted by
* {@code ObservableSources}, one after the other, without interleaving them
* @see ReactiveX operators documentation: Concat
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(ObservableSource extends ObservableSource extends T>> sources) {
return concat(sources, bufferSize());
}
/**
* Returns an Observable that emits the items emitted by each of the ObservableSources emitted by the source
* ObservableSource, one after the other, without interleaving them.
*
*
*
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param sources
* an ObservableSource that emits ObservableSources
* @param prefetch
* the number of ObservableSources to prefetch from the sources sequence.
* @return an Observable that emits items all of the items emitted by the ObservableSources emitted by
* {@code ObservableSources}, one after the other, without interleaving them
* @see ReactiveX operators documentation: Concat
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(ObservableSource extends ObservableSource extends T>> sources, int prefetch) {
ObjectHelper.requireNonNull(sources, "sources is null");
ObjectHelper.verifyPositive(prefetch, "prefetch");
return RxJavaPlugins.onAssembly(new ObservableConcatMap(sources, Functions.identity(), prefetch, ErrorMode.IMMEDIATE));
}
/**
* Returns an Observable that emits the items emitted by two ObservableSources, one after the other, without
* interleaving them.
*
*
*
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param source1
* an ObservableSource to be concatenated
* @param source2
* an ObservableSource to be concatenated
* @return an Observable that emits items emitted by the two source ObservableSources, one after the other,
* without interleaving them
* @see ReactiveX operators documentation: Concat
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(ObservableSource extends T> source1, ObservableSource 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 ObservableSources, one after the other, without
* interleaving them.
*
*
*
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param source1
* an ObservableSource to be concatenated
* @param source2
* an ObservableSource to be concatenated
* @param source3
* an ObservableSource to be concatenated
* @return an Observable that emits items emitted by the three source ObservableSources, one after the other,
* without interleaving them
* @see ReactiveX operators documentation: Concat
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(
ObservableSource extends T> source1, ObservableSource extends T> source2,
ObservableSource 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 ObservableSources, one after the other, without
* interleaving them.
*
*
*
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param source1
* an ObservableSource to be concatenated
* @param source2
* an ObservableSource to be concatenated
* @param source3
* an ObservableSource to be concatenated
* @param source4
* an ObservableSource to be concatenated
* @return an Observable that emits items emitted by the four source ObservableSources, one after the other,
* without interleaving them
* @see ReactiveX operators documentation: Concat
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(
ObservableSource extends T> source1, ObservableSource extends T> source2,
ObservableSource extends T> source3, ObservableSource 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);
}
/**
* Concatenates a variable number of ObservableSource sources.
*
* Note: named this way because of overload conflict with concat(ObservableSource<ObservableSource>)
*
*
*
* - Scheduler:
* - {@code concatArray} 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", "rawtypes" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatArray(ObservableSource extends T>... sources) {
if (sources.length == 0) {
return empty();
}
if (sources.length == 1) {
return wrap((ObservableSource)sources[0]);
}
return RxJavaPlugins.onAssembly(new ObservableConcatMap(fromArray(sources), Functions.identity(), bufferSize(), ErrorMode.BOUNDARY));
}
/**
* Concatenates a variable number of ObservableSource 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(ObservableSource extends T>... sources) {
if (sources.length == 0) {
return empty();
}
if (sources.length == 1) {
return (Observable)wrap(sources[0]);
}
return concatDelayError(fromArray(sources));
}
/**
* Concatenates an array of ObservableSources eagerly into a single stream of values.
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* source ObservableSources. 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 an array of ObservableSources that need to be eagerly concatenated
* @return the new ObservableSource instance with the specified concatenation behavior
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatArrayEager(ObservableSource extends T>... sources) {
return concatArrayEager(bufferSize(), bufferSize(), sources);
}
/**
* Concatenates an array of ObservableSources eagerly into a single stream of values.
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* source ObservableSources. 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 an array of ObservableSources that need to be eagerly concatenated
* @param maxConcurrency the maximum number of concurrent subscriptions at a time, Integer.MAX_VALUE
* is interpreted as indication to subscribe to all sources at once
* @param prefetch the number of elements to prefetch from each ObservableSource source
* @return the new ObservableSource instance with the specified concatenation behavior
* @since 2.0
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatArrayEager(int maxConcurrency, int prefetch, ObservableSource extends T>... sources) {
return fromArray(sources).concatMapEagerDelayError((Function)Functions.identity(), maxConcurrency, prefetch, false);
}
/**
* Concatenates an array of {@link ObservableSource}s eagerly into a single stream of values
* and delaying any errors until all sources terminate.
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* source {@code ObservableSource}s. The operator buffers the values emitted by these {@code ObservableSource}s
* 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 an array of {@code ObservableSource}s that need to be eagerly concatenated
* @return the new Observable instance with the specified concatenation behavior
* @since 2.2.1 - experimental
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatArrayEagerDelayError(ObservableSource extends T>... sources) {
return concatArrayEagerDelayError(bufferSize(), bufferSize(), sources);
}
/**
* Concatenates an array of {@link ObservableSource}s eagerly into a single stream of values
* and delaying any errors until all sources terminate.
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* source {@code ObservableSource}s. The operator buffers the values emitted by these {@code ObservableSource}s
* 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 an array of {@code ObservableSource}s that need to be eagerly concatenated
* @param maxConcurrency the maximum number of concurrent subscriptions at a time, Integer.MAX_VALUE
* is interpreted as indication to subscribe to all sources at once
* @param prefetch the number of elements to prefetch from each {@code ObservableSource} source
* @return the new Observable instance with the specified concatenation behavior
* @since 2.2.1 - experimental
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatArrayEagerDelayError(int maxConcurrency, int prefetch, ObservableSource extends T>... sources) {
return fromArray(sources).concatMapEagerDelayError((Function)Functions.identity(), maxConcurrency, prefetch, true);
}
/**
* Concatenates the Iterable sequence of ObservableSources into a single sequence by subscribing to each ObservableSource,
* one after the other, one at a time and delays any errors till the all inner ObservableSources 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 ObservableSources
* @return the new ObservableSource with the concatenating behavior
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatDelayError(Iterable extends ObservableSource extends T>> sources) {
ObjectHelper.requireNonNull(sources, "sources is null");
return concatDelayError(fromIterable(sources));
}
/**
* 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
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatDelayError(ObservableSource extends ObservableSource extends T>> sources) {
return concatDelayError(sources, bufferSize(), true);
}
/**
* 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
* @param prefetch the number of elements to prefetch from the outer ObservableSource
* @param tillTheEnd if true exceptions from the outer and all inner ObservableSources are delayed to the end
* if false, exception from the outer ObservableSource is delayed till the current ObservableSource terminates
* @return the new ObservableSource with the concatenating behavior
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatDelayError(ObservableSource extends ObservableSource extends T>> sources, int prefetch, boolean tillTheEnd) {
ObjectHelper.requireNonNull(sources, "sources is null");
ObjectHelper.verifyPositive(prefetch, "prefetch is null");
return RxJavaPlugins.onAssembly(new ObservableConcatMap(sources, Functions.identity(), prefetch, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY));
}
/**
* 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
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatEager(ObservableSource extends ObservableSource extends T>> sources) {
return concatEager(sources, bufferSize(), bufferSize());
}
/**
* 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
* @param maxConcurrency the maximum number of concurrently running inner ObservableSources; Integer.MAX_VALUE
* is interpreted as all inner ObservableSources can be active at the same time
* @param prefetch the number of elements to prefetch from each inner ObservableSource source
* @return the new ObservableSource instance with the specified concatenation behavior
* @since 2.0
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatEager(ObservableSource extends ObservableSource extends T>> sources, int maxConcurrency, int prefetch) {
return wrap(sources).concatMapEager((Function)Functions.identity(), maxConcurrency, prefetch);
}
/**
* Concatenates a 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
* source ObservableSources. 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
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatEager(Iterable extends ObservableSource extends T>> sources) {
return concatEager(sources, bufferSize(), bufferSize());
}
/**
* Concatenates a 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
* source ObservableSources. 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
* @param maxConcurrency the maximum number of concurrently running inner ObservableSources; Integer.MAX_VALUE
* is interpreted as all inner ObservableSources can be active at the same time
* @param prefetch the number of elements to prefetch from each inner ObservableSource source
* @return the new ObservableSource instance with the specified concatenation behavior
* @since 2.0
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatEager(Iterable extends ObservableSource extends T>> sources, int maxConcurrency, int prefetch) {
return fromIterable(sources).concatMapEagerDelayError((Function)Functions.identity(), maxConcurrency, prefetch, false);
}
/**
* Provides an API (via a cold Observable) that bridges the reactive world with the callback-style world.
*
* Example:
*
* Observable.<Event>create(emitter -> {
* Callback listener = new Callback() {
* @Override
* public void onEvent(Event e) {
* emitter.onNext(e);
* if (e.isLast()) {
* emitter.onComplete();
* }
* }
*
* @Override
* public void onFailure(Exception e) {
* emitter.onError(e);
* }
* };
*
* AutoCloseable c = api.someMethod(listener);
*
* emitter.setCancellable(c::close);
*
* });
*
*
*
*
* You should call the ObservableEmitter's onNext, onError and onComplete methods in a serialized fashion. The
* rest of its methods are thread-safe.
*
* - Scheduler:
* - {@code create} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type
* @param source the emitter that is called when an Observer subscribes to the returned {@code Observable}
* @return the new Observable instance
* @see ObservableOnSubscribe
* @see ObservableEmitter
* @see Cancellable
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable create(ObservableOnSubscribe source) {
ObjectHelper.requireNonNull(source, "source is null");
return RxJavaPlugins.onAssembly(new ObservableCreate(source));
}
/**
* Returns an Observable that calls an ObservableSource factory to create an ObservableSource for each new Observer
* that subscribes. That is, for each subscriber, the actual ObservableSource that subscriber observes is
* determined by the factory function.
*
*
*
* The defer Observer allows you to defer or delay emitting items from an ObservableSource until such time as an
* Observer subscribes to the ObservableSource. This allows an {@link Observer} to easily obtain updates or a
* refreshed version of the sequence.
*
* - Scheduler:
* - {@code defer} does not operate by default on a particular {@link Scheduler}.
*
*
* @param supplier
* the ObservableSource factory function to invoke for each {@link Observer} that subscribes to the
* resulting ObservableSource
* @param
* the type of the items emitted by the ObservableSource
* @return an Observable whose {@link Observer}s' subscriptions trigger an invocation of the given
* ObservableSource factory function
* @see ReactiveX operators documentation: Defer
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable defer(Callable extends ObservableSource extends T>> supplier) {
ObjectHelper.requireNonNull(supplier, "supplier is null");
return RxJavaPlugins.onAssembly(new ObservableDefer(supplier));
}
/**
* Returns an Observable that emits no items to the {@link Observer} and immediately invokes its
* {@link Observer#onComplete onComplete} method.
*
*
*
* - Scheduler:
* - {@code empty} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the type of the items (ostensibly) emitted by the ObservableSource
* @return an Observable that emits no items to the {@link Observer} but immediately invokes the
* {@link Observer}'s {@link Observer#onComplete() onComplete} method
* @see ReactiveX operators documentation: Empty
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public static Observable empty() {
return RxJavaPlugins.onAssembly((Observable) ObservableEmpty.INSTANCE);
}
/**
* Returns an Observable that invokes an {@link Observer}'s {@link Observer#onError onError} method when the
* Observer subscribes to it.
*
*
*
* - Scheduler:
* - {@code error} does not operate by default on a particular {@link Scheduler}.
*
*
* @param errorSupplier
* a Callable factory to return a Throwable for each individual Observer
* @param
* the type of the items (ostensibly) emitted by the ObservableSource
* @return an Observable that invokes the {@link Observer}'s {@link Observer#onError onError} method when
* the Observer subscribes to it
* @see ReactiveX operators documentation: Throw
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable error(Callable extends Throwable> errorSupplier) {
ObjectHelper.requireNonNull(errorSupplier, "errorSupplier is null");
return RxJavaPlugins.onAssembly(new ObservableError(errorSupplier));
}
/**
* Returns an Observable that invokes an {@link Observer}'s {@link Observer#onError onError} method when the
* Observer 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 Observer#onError onError}
* @param
* the type of the items (ostensibly) emitted by the ObservableSource
* @return an Observable that invokes the {@link Observer}'s {@link Observer#onError onError} method when
* the Observer subscribes to it
* @see ReactiveX operators documentation: Throw
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable error(final Throwable exception) {
ObjectHelper.requireNonNull(exception, "exception is null");
return error(Functions.justCallable(exception));
}
/**
* Converts an Array into an ObservableSource that emits the items in the Array.
*
*
*
* - Scheduler:
* - {@code fromArray} does not operate by default on a particular {@link Scheduler}.
*
*
* @param items
* the array of elements
* @param
* the type of items in the Array and the type of items to be emitted by the resulting ObservableSource
* @return an Observable that emits each item in the source Array
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable fromArray(T... items) {
ObjectHelper.requireNonNull(items, "items is null");
if (items.length == 0) {
return empty();
}
if (items.length == 1) {
return just(items[0]);
}
return RxJavaPlugins.onAssembly(new ObservableFromArray(items));
}
/**
* Returns an Observable that, when an observer subscribes to it, invokes a function you specify and then
* emits the value returned from that function.
*
*
*
* This allows you to defer the execution of the function you specify until an observer subscribes to the
* ObservableSource. That is to say, it makes the function "lazy."
*
* - Scheduler:
* - {@code fromCallable} does not operate by default on a particular {@link Scheduler}.
* - Error handling:
* - If the {@link Callable} throws an exception, the respective {@link Throwable} is
* delivered to the downstream via {@link Observer#onError(Throwable)},
* except when the downstream has disposed this {@code Observable} 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 supplier
* a function, the execution of which should be deferred; {@code fromCallable} will invoke this
* function only when an observer subscribes to the ObservableSource that {@code fromCallable} returns
* @param
* the type of the item emitted by the ObservableSource
* @return an Observable whose {@link Observer}s' subscriptions trigger an invocation of the given function
* @see #defer(Callable)
* @since 2.0
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromCallable(Callable extends T> supplier) {
ObjectHelper.requireNonNull(supplier, "supplier is null");
return RxJavaPlugins.onAssembly(new ObservableFromCallable(supplier));
}
/**
* Converts a {@link Future} into an ObservableSource.
*
*
*
* You can convert any object that supports the {@link Future} interface into an ObservableSource 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 ObservableSource is blocking; you cannot dispose it.
*
* Unlike 1.x, disposing the Observable won't cancel the future. If necessary, one can use composition to achieve the
* cancellation effect: {@code futureObservableSource.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 ObservableSource
* @return an Observable that emits the item from the source {@link Future}
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromFuture(Future extends T> future) {
ObjectHelper.requireNonNull(future, "future is null");
return RxJavaPlugins.onAssembly(new ObservableFromFuture(future, 0L, null));
}
/**
* Converts a {@link Future} into an ObservableSource, with a timeout on the Future.
*
*
*
* You can convert any object that supports the {@link Future} interface into an ObservableSource that emits the
* return value of the {@link Future#get} method of that object, by passing the object into the {@code from}
* method.
*
* Unlike 1.x, disposing the Observable won't cancel the future. If necessary, one can use composition to achieve the
* cancellation effect: {@code futureObservableSource.doOnDispose(() -> future.cancel(true));}.
*
* Important note: This ObservableSource is blocking; 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 ObservableSource
* @return an Observable that emits the item from the source {@link Future}
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable 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 ObservableFromFuture(future, timeout, unit));
}
/**
* Converts a {@link Future} into an ObservableSource, with a timeout on the Future.
*
*
*
* You can convert any object that supports the {@link Future} interface into an ObservableSource that emits the
* return value of the {@link Future#get} method of that object, by passing the object into the {@code from}
* method.
*
* Unlike 1.x, disposing the Observable won't cancel the future. If necessary, one can use composition to achieve the
* cancellation effect: {@code futureObservableSource.doOnDispose(() -> future.cancel(true));}.
*
* Important note: This ObservableSource is blocking; 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 scheduler
* the {@link Scheduler} to wait for the Future on. Use a Scheduler such as
* {@link Schedulers#io()} that can block and wait on the Future
* @param
* the type of object that the {@link Future} returns, and also the type of item to be emitted by
* the resulting ObservableSource
* @return an Observable that emits the item from the source {@link Future}
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.CUSTOM)
public static Observable fromFuture(Future extends T> future, long timeout, TimeUnit unit, Scheduler scheduler) {
ObjectHelper.requireNonNull(scheduler, "scheduler is null");
Observable o = fromFuture(future, timeout, unit);
return o.subscribeOn(scheduler);
}
/**
* Converts a {@link Future}, operating on a specified {@link Scheduler}, into an ObservableSource.
*
*
*
* You can convert any object that supports the {@link Future} interface into an ObservableSource that emits the
* return value of the {@link Future#get} method of that object, by passing the object into the {@code from}
* method.
*
* Unlike 1.x, disposing the Observable won't cancel the future. If necessary, one can use composition to achieve the
* cancellation effect: {@code futureObservableSource.doOnDispose(() -> future.cancel(true));}.
*
* - Scheduler:
* - You specify which {@link Scheduler} this operator will use.
*
*
* @param future
* the source {@link Future}
* @param scheduler
* the {@link Scheduler} to wait for the Future on. Use a Scheduler such as
* {@link Schedulers#io()} that can block and wait on the Future
* @param
* the type of object that the {@link Future} returns, and also the type of item to be emitted by
* the resulting ObservableSource
* @return an Observable that emits the item from the source {@link Future}
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.CUSTOM)
public static Observable fromFuture(Future extends T> future, Scheduler scheduler) {
ObjectHelper.requireNonNull(scheduler, "scheduler is null");
Observable o = fromFuture(future);
return o.subscribeOn(scheduler);
}
/**
* Converts an {@link Iterable} sequence into an ObservableSource that emits the items in the sequence.
*
*
*
* - Scheduler:
* - {@code fromIterable} does not operate by default on a particular {@link Scheduler}.
*
*
* @param source
* the source {@link Iterable} sequence
* @param
* the type of items in the {@link Iterable} sequence and the type of items to be emitted by the
* resulting ObservableSource
* @return an Observable that emits each item in the source {@link Iterable} sequence
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromIterable(Iterable extends T> source) {
ObjectHelper.requireNonNull(source, "source is null");
return RxJavaPlugins.onAssembly(new ObservableFromIterable(source));
}
/**
* Converts an arbitrary Reactive Streams Publisher into an Observable.
*