io.reactivex.rxjava3.core.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.rxjava3.core;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.*;
import org.reactivestreams.Publisher;
import io.reactivex.rxjava3.annotations.*;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.exceptions.*;
import io.reactivex.rxjava3.functions.*;
import io.reactivex.rxjava3.internal.functions.*;
import io.reactivex.rxjava3.internal.fuseable.ScalarSupplier;
import io.reactivex.rxjava3.internal.jdk8.*;
import io.reactivex.rxjava3.internal.observers.*;
import io.reactivex.rxjava3.internal.operators.flowable.*;
import io.reactivex.rxjava3.internal.operators.maybe.MaybeToObservable;
import io.reactivex.rxjava3.internal.operators.mixed.*;
import io.reactivex.rxjava3.internal.operators.observable.*;
import io.reactivex.rxjava3.internal.operators.single.SingleToObservable;
import io.reactivex.rxjava3.internal.util.*;
import io.reactivex.rxjava3.observables.*;
import io.reactivex.rxjava3.observers.*;
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
import io.reactivex.rxjava3.schedulers.*;
/**
* The {@code 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 {@link ObservableSource}(s), the base reactive interface
* for such non-backpressured flows, which {@code Observable} itself implements as well.
*
* The {@code 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 rx3.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 {@link 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 {@code Observable}
* @see Flowable
* @see io.reactivex.rxjava3.observers.DisposableObserver
*/
public abstract class Observable<@NonNull T> implements ObservableSource {
/**
* Mirrors the one {@link ObservableSource} in an {@link Iterable} of several {@code ObservableSource}s 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 {@code Iterable} of {@code ObservableSource} sources competing to react first. A subscription to each source will
* occur in the same order as in the {@code Iterable}.
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code sources} is {@code null}
* @see ReactiveX operators documentation: Amb
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable amb(@NonNull Iterable<@NonNull ? extends ObservableSource extends T>> sources) {
Objects.requireNonNull(sources, "sources is null");
return RxJavaPlugins.onAssembly(new ObservableAmb<>(null, sources));
}
/**
* Mirrors the one {@link ObservableSource} in an array of several {@code ObservableSource}s 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 {@code ObservableSource} sources competing to react first. A subscription to each source will
* occur in the same order as in the array.
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code sources} is {@code null}
* @see ReactiveX operators documentation: Amb
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
@SafeVarargs
public static Observable ambArray(@NonNull ObservableSource extends T>... sources) {
Objects.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 rx3.buffer-size}
* before the {@link Flowable} class is loaded.
* @return the default 'island' size or capacity-increment hint
*/
@CheckReturnValue
public static int bufferSize() {
return Flowable.bufferSize();
}
/**
* Combines a collection of source {@link ObservableSource}s by emitting an item that aggregates the latest values of each of
* the returned {@code ObservableSource}s each time an item is received from any of the returned {@code ObservableSource}s, 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 {@link 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 {@code ObservableSource}s 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 {@code ObservableSource}s
* @param combiner
* the aggregation function used to combine the items emitted by the returned {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code sources} or {@code combiner} is {@code null}
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable combineLatest(
@NonNull Iterable<@NonNull ? extends ObservableSource extends T>> sources,
@NonNull Function super Object[], ? extends R> combiner) {
return combineLatest(sources, combiner, bufferSize());
}
/**
* Combines an {@link Iterable} of source {@link ObservableSource}s by emitting an item that aggregates the latest values of each of
* the returned {@code ObservableSource}s each time an item is received from any of the returned {@code ObservableSource}s, 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 {@link 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 {@code Iterable} of {@code ObservableSource}s 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 {@code ObservableSource}s
* @param combiner
* the aggregation function used to combine the items emitted by the returned {@code ObservableSource}s
* @param bufferSize
* the expected number of row combination items to be buffered internally
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code sources} or {@code combiner} is {@code null}
* @throws IllegalArgumentException if {@code bufferSize} is non-positive
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
@NonNull Iterable<@NonNull ? extends ObservableSource extends T>> sources,
@NonNull Function super Object[], ? extends R> combiner, int bufferSize) {
Objects.requireNonNull(sources, "sources is null");
Objects.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 an array of source {@link ObservableSource}s by emitting an item that aggregates the latest values of each of
* the {@code ObservableSource}s each time an item is received from any of the returned {@code ObservableSource}s, 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 {@link 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 {@code ObservableSource}s is empty, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
*
*
* - Scheduler:
* - {@code combineLatestArray} 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 {@code ObservableSource}s
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code sources} or {@code combiner} is {@code null}
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable combineLatestArray(
@NonNull ObservableSource extends T>[] sources,
@NonNull Function super Object[], ? extends R> combiner) {
return combineLatestArray(sources, combiner, bufferSize());
}
/**
* Combines an array of source {@link ObservableSource}s by emitting an item that aggregates the latest values of each of
* the {@code ObservableSource}s each time an item is received from any of the {@code ObservableSource}s, 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 {@link 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 {@code ObservableSource}s is empty, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
*
*
* - Scheduler:
* - {@code combineLatestArray} 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 {@code ObservableSource}s
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @param bufferSize
* the expected number of row combination items to be buffered internally
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code sources} or {@code combiner} is {@code null}
* @throws IllegalArgumentException if {@code bufferSize} is non-positive
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatestArray(
@NonNull ObservableSource extends T>[] sources,
@NonNull Function super Object[], ? extends R> combiner, int bufferSize) {
Objects.requireNonNull(sources, "sources is null");
if (sources.length == 0) {
return empty();
}
Objects.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 {@link ObservableSource}s by emitting an item that aggregates the latest values of each of the
* {@code ObservableSource}s each time an item is received from either of the {@code ObservableSource}s, 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 {@code ObservableSource}
* @param source2
* the second source {@code ObservableSource}
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source1}, {@code source2} or {@code combiner} is {@code null}
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
@NonNull ObservableSource extends T1> source1, @NonNull ObservableSource extends T2> source2,
@NonNull BiFunction super T1, ? super T2, ? extends R> combiner) {
Objects.requireNonNull(source1, "source1 is null");
Objects.requireNonNull(source2, "source2 is null");
Objects.requireNonNull(combiner, "combiner is null");
return combineLatestArray(new ObservableSource[] { source1, source2 }, Functions.toFunction(combiner), bufferSize());
}
/**
* Combines three source {@link ObservableSource}s by emitting an item that aggregates the latest values of each of the
* {@code ObservableSource}s each time an item is received from any of the {@code ObservableSource}s, 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 {@code ObservableSource}
* @param source2
* the second source {@code ObservableSource}
* @param source3
* the third source {@code ObservableSource}
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source1}, {@code source2}, {@code source3} or {@code combiner} is {@code null}
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
@NonNull ObservableSource extends T1> source1, @NonNull ObservableSource extends T2> source2,
@NonNull ObservableSource extends T3> source3,
@NonNull Function3 super T1, ? super T2, ? super T3, ? extends R> combiner) {
Objects.requireNonNull(source1, "source1 is null");
Objects.requireNonNull(source2, "source2 is null");
Objects.requireNonNull(source3, "source3 is null");
Objects.requireNonNull(combiner, "combiner is null");
return combineLatestArray(new ObservableSource[] { source1, source2, source3 }, Functions.toFunction(combiner), bufferSize());
}
/**
* Combines four source {@link ObservableSource}s by emitting an item that aggregates the latest values of each of the
* {@code ObservableSource}s each time an item is received from any of the {@code ObservableSource}s, 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 {@code ObservableSource}
* @param source2
* the second source {@code ObservableSource}
* @param source3
* the third source {@code ObservableSource}
* @param source4
* the fourth source {@code ObservableSource}
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source1}, {@code source2}, {@code source3},
* {@code source4} or {@code combiner} is {@code null}
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
@NonNull ObservableSource extends T1> source1, @NonNull ObservableSource extends T2> source2,
@NonNull ObservableSource extends T3> source3, @NonNull ObservableSource extends T4> source4,
@NonNull Function4 super T1, ? super T2, ? super T3, ? super T4, ? extends R> combiner) {
Objects.requireNonNull(source1, "source1 is null");
Objects.requireNonNull(source2, "source2 is null");
Objects.requireNonNull(source3, "source3 is null");
Objects.requireNonNull(source4, "source4 is null");
Objects.requireNonNull(combiner, "combiner is null");
return combineLatestArray(new ObservableSource[] { source1, source2, source3, source4 }, Functions.toFunction(combiner), bufferSize());
}
/**
* Combines five source {@link ObservableSource}s by emitting an item that aggregates the latest values of each of the
* {@code ObservableSource}s each time an item is received from any of the {@code ObservableSource}s, 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 {@code ObservableSource}
* @param source2
* the second source {@code ObservableSource}
* @param source3
* the third source {@code ObservableSource}
* @param source4
* the fourth source {@code ObservableSource}
* @param source5
* the fifth source {@code ObservableSource}
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source1}, {@code source2}, {@code source3},
* {@code source4}, {@code source5} or {@code combiner} is {@code null}
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
@NonNull ObservableSource extends T1> source1, @NonNull ObservableSource extends T2> source2,
@NonNull ObservableSource extends T3> source3, @NonNull ObservableSource extends T4> source4,
@NonNull ObservableSource extends T5> source5,
@NonNull Function5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> combiner) {
Objects.requireNonNull(source1, "source1 is null");
Objects.requireNonNull(source2, "source2 is null");
Objects.requireNonNull(source3, "source3 is null");
Objects.requireNonNull(source4, "source4 is null");
Objects.requireNonNull(source5, "source5 is null");
Objects.requireNonNull(combiner, "combiner is null");
return combineLatestArray(new ObservableSource[] { source1, source2, source3, source4, source5 }, Functions.toFunction(combiner), bufferSize());
}
/**
* Combines six source {@link ObservableSource}s by emitting an item that aggregates the latest values of each of the
* {@code ObservableSource}s each time an item is received from any of the {@code ObservableSource}s, 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 {@code ObservableSource}
* @param source2
* the second source {@code ObservableSource}
* @param source3
* the third source {@code ObservableSource}
* @param source4
* the fourth source {@code ObservableSource}
* @param source5
* the fifth source {@code ObservableSource}
* @param source6
* the sixth source {@code ObservableSource}
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source1}, {@code source2}, {@code source3},
* {@code source4}, {@code source5}, {@code source6} or {@code combiner} is {@code null}
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
@NonNull ObservableSource extends T1> source1, @NonNull ObservableSource extends T2> source2,
@NonNull ObservableSource extends T3> source3, @NonNull ObservableSource extends T4> source4,
@NonNull ObservableSource extends T5> source5, @NonNull ObservableSource extends T6> source6,
@NonNull Function6 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> combiner) {
Objects.requireNonNull(source1, "source1 is null");
Objects.requireNonNull(source2, "source2 is null");
Objects.requireNonNull(source3, "source3 is null");
Objects.requireNonNull(source4, "source4 is null");
Objects.requireNonNull(source5, "source5 is null");
Objects.requireNonNull(source6, "source6 is null");
Objects.requireNonNull(combiner, "combiner is null");
return combineLatestArray(new ObservableSource[] { source1, source2, source3, source4, source5, source6 }, Functions.toFunction(combiner), bufferSize());
}
/**
* Combines seven source {@link ObservableSource}s by emitting an item that aggregates the latest values of each of the
* {@code ObservableSource}s each time an item is received from any of the {@code ObservableSource}s, 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 {@code ObservableSource}
* @param source2
* the second source {@code ObservableSource}
* @param source3
* the third source {@code ObservableSource}
* @param source4
* the fourth source {@code ObservableSource}
* @param source5
* the fifth source {@code ObservableSource}
* @param source6
* the sixth source {@code ObservableSource}
* @param source7
* the seventh source {@code ObservableSource}
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source1}, {@code source2}, {@code source3},
* {@code source4}, {@code source5}, {@code source6},
* {@code source7} or {@code combiner} is {@code null}
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
@NonNull ObservableSource extends T1> source1, @NonNull ObservableSource extends T2> source2,
@NonNull ObservableSource extends T3> source3, @NonNull ObservableSource extends T4> source4,
@NonNull ObservableSource extends T5> source5, @NonNull ObservableSource extends T6> source6,
@NonNull ObservableSource extends T7> source7,
@NonNull Function7 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> combiner) {
Objects.requireNonNull(source1, "source1 is null");
Objects.requireNonNull(source2, "source2 is null");
Objects.requireNonNull(source3, "source3 is null");
Objects.requireNonNull(source4, "source4 is null");
Objects.requireNonNull(source5, "source5 is null");
Objects.requireNonNull(source6, "source6 is null");
Objects.requireNonNull(source7, "source7 is null");
Objects.requireNonNull(combiner, "combiner is null");
return combineLatestArray(new ObservableSource[] { source1, source2, source3, source4, source5, source6, source7 }, Functions.toFunction(combiner), bufferSize());
}
/**
* Combines eight source {@link ObservableSource}s by emitting an item that aggregates the latest values of each of the
* {@code ObservableSource}s each time an item is received from any of the {@code ObservableSource}s, 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 {@code ObservableSource}
* @param source2
* the second source {@code ObservableSource}
* @param source3
* the third source {@code ObservableSource}
* @param source4
* the fourth source {@code ObservableSource}
* @param source5
* the fifth source {@code ObservableSource}
* @param source6
* the sixth source {@code ObservableSource}
* @param source7
* the seventh source {@code ObservableSource}
* @param source8
* the eighth source {@code ObservableSource}
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source1}, {@code source2}, {@code source3},
* {@code source4}, {@code source5}, {@code source6},
* {@code source7}, {@code source8} or {@code combiner} is {@code null}
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
@NonNull ObservableSource extends T1> source1, @NonNull ObservableSource extends T2> source2,
@NonNull ObservableSource extends T3> source3, @NonNull ObservableSource extends T4> source4,
@NonNull ObservableSource extends T5> source5, @NonNull ObservableSource extends T6> source6,
@NonNull ObservableSource extends T7> source7, @NonNull ObservableSource extends T8> source8,
@NonNull Function8 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> combiner) {
Objects.requireNonNull(source1, "source1 is null");
Objects.requireNonNull(source2, "source2 is null");
Objects.requireNonNull(source3, "source3 is null");
Objects.requireNonNull(source4, "source4 is null");
Objects.requireNonNull(source5, "source5 is null");
Objects.requireNonNull(source6, "source6 is null");
Objects.requireNonNull(source7, "source7 is null");
Objects.requireNonNull(source8, "source8 is null");
Objects.requireNonNull(combiner, "combiner is null");
return combineLatestArray(new ObservableSource[] { source1, source2, source3, source4, source5, source6, source7, source8 }, Functions.toFunction(combiner), bufferSize());
}
/**
* Combines nine source {@link ObservableSource}s by emitting an item that aggregates the latest values of each of the
* {@code ObservableSource}s each time an item is received from any of the {@code ObservableSource}s, 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 {@code ObservableSource}
* @param source2
* the second source {@code ObservableSource}
* @param source3
* the third source {@code ObservableSource}
* @param source4
* the fourth source {@code ObservableSource}
* @param source5
* the fifth source {@code ObservableSource}
* @param source6
* the sixth source {@code ObservableSource}
* @param source7
* the seventh source {@code ObservableSource}
* @param source8
* the eighth source {@code ObservableSource}
* @param source9
* the ninth source {@code ObservableSource}
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source1}, {@code source2}, {@code source3},
* {@code source4}, {@code source5}, {@code source6},
* {@code source7}, {@code source8}, {@code source9} or {@code combiner} is {@code null}
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
@NonNull ObservableSource extends T1> source1, @NonNull ObservableSource extends T2> source2,
@NonNull ObservableSource extends T3> source3, @NonNull ObservableSource extends T4> source4,
@NonNull ObservableSource extends T5> source5, @NonNull ObservableSource extends T6> source6,
@NonNull ObservableSource extends T7> source7, @NonNull ObservableSource extends T8> source8,
@NonNull ObservableSource extends T9> source9,
@NonNull Function9 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9, ? extends R> combiner) {
Objects.requireNonNull(source1, "source1 is null");
Objects.requireNonNull(source2, "source2 is null");
Objects.requireNonNull(source3, "source3 is null");
Objects.requireNonNull(source4, "source4 is null");
Objects.requireNonNull(source5, "source5 is null");
Objects.requireNonNull(source6, "source6 is null");
Objects.requireNonNull(source7, "source7 is null");
Objects.requireNonNull(source8, "source8 is null");
Objects.requireNonNull(source9, "source9 is null");
Objects.requireNonNull(combiner, "combiner is null");
return combineLatestArray(new ObservableSource[] { source1, source2, source3, source4, source5, source6, source7, source8, source9 }, Functions.toFunction(combiner), bufferSize());
}
/**
* Combines an array of {@link ObservableSource}s by emitting an item that aggregates the latest values of each of
* the {@code ObservableSource}s each time an item is received from any of the {@code ObservableSource}s, 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 {@link 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 {@code ObservableSource}s is empty, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
* - Scheduler:
* - {@code combineLatestArrayDelayError} 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 {@code ObservableSource}s
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code sources} or {@code combiner} is {@code null}
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable combineLatestArrayDelayError(
@NonNull ObservableSource extends T>[] sources,
@NonNull Function super Object[], ? extends R> combiner) {
return combineLatestArrayDelayError(sources, combiner, bufferSize());
}
/**
* Combines an array of {@link ObservableSource}s by emitting an item that aggregates the latest values of each of
* the {@code ObservableSource}s each time an item is received from any of the {@code ObservableSource}s, where this
* aggregation is defined by a specified function and delays any error from the sources until
* all source {@code ObservableSource}s 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 {@link 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 {@code ObservableSource}s is empty, the resulting sequence completes immediately without emitting
* any items and without any calls to the combiner function.
*
*
*
*
* - Scheduler:
* - {@code combineLatestArrayDelayError} 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 {@code ObservableSource}s
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @param bufferSize
* the expected number of row combination items to be buffered internally
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code sources} or {@code combiner} is {@code null}
* @throws IllegalArgumentException if {@code bufferSize} is non-positive
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatestArrayDelayError(@NonNull ObservableSource extends T>[] sources,
@NonNull Function super Object[], ? extends R> combiner, int bufferSize) {
Objects.requireNonNull(sources, "sources is null");
Objects.requireNonNull(combiner, "combiner is null");
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
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 an {@link Iterable} of {@link ObservableSource}s by emitting an item that aggregates the latest values of each of
* the {@code ObservableSource}s each time an item is received from any of the {@code ObservableSource}s, where this
* aggregation is defined by a specified function and delays any error from the sources until
* all source {@code ObservableSource}s 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 {@link 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 {@code ObservableSource}s 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 {@code Iterable} of source {@code ObservableSource}s
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code sources} or {@code combiner} is {@code null}
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable combineLatestDelayError(@NonNull Iterable<@NonNull ? extends ObservableSource extends T>> sources,
@NonNull Function super Object[], ? extends R> combiner) {
return combineLatestDelayError(sources, combiner, bufferSize());
}
/**
* Combines an {@link Iterable} of {@link ObservableSource}s by emitting an item that aggregates the latest values of each of
* the {@code ObservableSource}s each time an item is received from any of the {@code ObservableSource}s, where this
* aggregation is defined by a specified function and delays any error from the sources until
* all source {@code ObservableSource}s 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 {@link 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 {@code ObservableSource}s 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 {@code ObservableSource}s
* @param combiner
* the aggregation function used to combine the items emitted by the {@code ObservableSource}s
* @param bufferSize
* the expected number of row combination items to be buffered internally
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code sources} or {@code combiner} is {@code null}
* @throws IllegalArgumentException if {@code bufferSize} is non-positive
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatestDelayError(@NonNull Iterable<@NonNull ? extends ObservableSource extends T>> sources,
@NonNull Function super Object[], ? extends R> combiner, int bufferSize) {
Objects.requireNonNull(sources, "sources is null");
Objects.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 {@link ObservableSource} provided via an {@link 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 {@code Iterable} sequence of {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code sources} is {@code null}
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(@NonNull Iterable<@NonNull ? extends ObservableSource extends T>> sources) {
Objects.requireNonNull(sources, "sources is null");
return fromIterable(sources).concatMapDelayError((Function)Functions.identity(), false, bufferSize());
}
/**
* Returns an {@code Observable} that emits the items emitted by each of the {@link ObservableSource}s emitted by the
* {@code 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 {@code ObservableSource} that emits {@code ObservableSource}s
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code sources} is {@code null}
* @see ReactiveX operators documentation: Concat
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable concat(@NonNull ObservableSource extends ObservableSource extends T>> sources) {
return concat(sources, bufferSize());
}
/**
* Returns an {@code Observable} that emits the items emitted by each of the {@link ObservableSource}s emitted by the outer
* {@code 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 {@code ObservableSource} that emits {@code ObservableSource}s
* @param bufferSize
* the number of inner {@code ObservableSource}s expected to be buffered.
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code sources} is {@code null}
* @throws IllegalArgumentException if {@code bufferSize} is non-positive
* @see ReactiveX operators documentation: Concat
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(@NonNull ObservableSource extends ObservableSource extends T>> sources, int bufferSize) {
Objects.requireNonNull(sources, "sources is null");
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
return RxJavaPlugins.onAssembly(new ObservableConcatMap(sources, Functions.identity(), bufferSize, ErrorMode.IMMEDIATE));
}
/**
* Returns an {@code Observable} that emits the items emitted by two {@link ObservableSource}s, 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 {@code ObservableSource} to be concatenated
* @param source2
* an {@code ObservableSource} to be concatenated
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source1} or {@code source2} is {@code null}
* @see ReactiveX operators documentation: Concat
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(@NonNull ObservableSource extends T> source1, ObservableSource extends T> source2) {
Objects.requireNonNull(source1, "source1 is null");
Objects.requireNonNull(source2, "source2 is null");
return concatArray(source1, source2);
}
/**
* Returns an {@code Observable} that emits the items emitted by three {@link ObservableSource}s, 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 {@code ObservableSource} to be concatenated
* @param source2
* an {@code ObservableSource} to be concatenated
* @param source3
* an {@code ObservableSource} to be concatenated
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source1}, {@code source2} or {@code source3} is {@code null}
* @see ReactiveX operators documentation: Concat
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(
@NonNull ObservableSource extends T> source1, @NonNull ObservableSource extends T> source2,
@NonNull ObservableSource extends T> source3) {
Objects.requireNonNull(source1, "source1 is null");
Objects.requireNonNull(source2, "source2 is null");
Objects.requireNonNull(source3, "source3 is null");
return concatArray(source1, source2, source3);
}
/**
* Returns an {@code Observable} that emits the items emitted by four {@link ObservableSource}s, 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 {@code ObservableSource} to be concatenated
* @param source2
* an {@code ObservableSource} to be concatenated
* @param source3
* an {@code ObservableSource} to be concatenated
* @param source4
* an {@code ObservableSource} to be concatenated
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source1}, {@code source2}, {@code source3} or {@code source4} is {@code null}
* @see ReactiveX operators documentation: Concat
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(
@NonNull ObservableSource extends T> source1, @NonNull ObservableSource extends T> source2,
@NonNull ObservableSource extends T> source3, @NonNull ObservableSource extends T> source4) {
Objects.requireNonNull(source1, "source1 is null");
Objects.requireNonNull(source2, "source2 is null");
Objects.requireNonNull(source3, "source3 is null");
Objects.requireNonNull(source4, "source4 is null");
return concatArray(source1, source2, source3, source4);
}
/**
* Concatenates a variable number of {@link ObservableSource} sources.
*
* Note: named this way because of overload conflict with {@code concat(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 {@code Observable} instance
* @throws NullPointerException if {@code sources} is {@code null}
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
@SafeVarargs
public static Observable concatArray(@NonNull ObservableSource extends T>... sources) {
Objects.requireNonNull(sources, "sources is null");
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 {@link 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 {@code Observable} instance
* @throws NullPointerException if {@code sources} is {@code null}
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
@SafeVarargs
public static Observable concatArrayDelayError(@NonNull ObservableSource extends T>... sources) {
Objects.requireNonNull(sources, "sources is null");
if (sources.length == 0) {
return empty();
}
if (sources.length == 1) {
@SuppressWarnings("unchecked")
Observable source = (Observable)wrap(sources[0]);
return source;
}
return concatDelayError(fromArray(sources));
}
/**
* Concatenates an array of {@link ObservableSource}s eagerly into a single stream of values.
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* {@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 {@code Observable} instance with the specified concatenation behavior
* @throws NullPointerException if {@code sources} is {@code null}
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@SafeVarargs
@NonNull
public static Observable concatArrayEager(@NonNull ObservableSource extends T>... sources) {
return concatArrayEager(bufferSize(), bufferSize(), sources);
}
/**
* Concatenates an array of {@link ObservableSource}s eagerly into a single stream of values.
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* {@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, {@link Integer#MAX_VALUE}
* is interpreted as indication to subscribe to all sources at once
* @param bufferSize the number of elements expected from each {@code ObservableSource} to be buffered
* @return the new {@code Observable} instance with the specified concatenation behavior
* @throws NullPointerException if {@code sources} is {@code null}
* @throws IllegalArgumentException if {@code maxConcurrency} or {@code bufferSize} is non-positive
* @since 2.0
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
@SafeVarargs
public static Observable concatArrayEager(int maxConcurrency, int bufferSize, @NonNull ObservableSource extends T>... sources) {
return fromArray(sources).concatMapEagerDelayError((Function)Functions.identity(), false, maxConcurrency, bufferSize);
}
/**
* 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
* {@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 {@code Observable} instance with the specified concatenation behavior
* @throws NullPointerException if {@code sources} is {@code null}
* @since 2.2.1 - experimental
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@SafeVarargs
@NonNull
public static Observable concatArrayEagerDelayError(@NonNull 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
* {@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, {@link Integer#MAX_VALUE}
* is interpreted as indication to subscribe to all sources at once
* @param bufferSize the number of elements expected from each {@code ObservableSource} to be buffered
* @return the new {@code Observable} instance with the specified concatenation behavior
* @throws NullPointerException if {@code sources} is {@code null}
* @throws IllegalArgumentException if {@code maxConcurrency} or {@code bufferSize} is non-positive
* @since 2.2.1 - experimental
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
@SafeVarargs
public static Observable concatArrayEagerDelayError(int maxConcurrency, int bufferSize, @NonNull ObservableSource extends T>... sources) {
return fromArray(sources).concatMapEagerDelayError((Function)Functions.identity(), true, maxConcurrency, bufferSize);
}
/**
* Concatenates the {@link Iterable} sequence of {@link ObservableSource}s into a single {@code Observable} sequence
* by subscribing to each {@code ObservableSource}, one after the other, one at a time and delays any errors till
* the all inner {@code ObservableSource}s terminate.
*
*
*
* - Scheduler:
* - {@code concatDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param sources the {@code Iterable} sequence of {@code ObservableSource}s
* @return the new {@code Observable} with the concatenating behavior
* @throws NullPointerException if {@code sources} is {@code null}
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatDelayError(@NonNull Iterable<@NonNull ? extends ObservableSource extends T>> sources) {
Objects.requireNonNull(sources, "sources is null");
return concatDelayError(fromIterable(sources));
}
/**
* Concatenates the {@link ObservableSource} sequence of {@code ObservableSource}s into a single {@code Observable} sequence
* by subscribing to each inner {@code ObservableSource}, one after the other, one at a time and delays any errors till the
* all inner and the outer {@code ObservableSource}s terminate.
*
*
*
* - Scheduler:
* - {@code concatDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param sources the {@code ObservableSource} sequence of {@code ObservableSource}s
* @return the new {@code Observable} with the concatenating behavior
* @throws NullPointerException if {@code sources} is {@code null}
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable concatDelayError(@NonNull ObservableSource extends ObservableSource extends T>> sources) {
return concatDelayError(sources, bufferSize(), true);
}
/**
* Concatenates the {@link ObservableSource} sequence of {@code ObservableSource}s into a single sequence by subscribing to each inner {@code ObservableSource},
* one after the other, one at a time and delays any errors till the all inner and the outer {@code ObservableSource}s terminate.
*
*
*
* - Scheduler:
* - {@code concatDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param sources the {@code ObservableSource} sequence of {@code ObservableSource}s
* @param bufferSize the number of inner {@code ObservableSource}s expected to be buffered
* @param tillTheEnd if {@code true}, exceptions from the outer and all inner {@code ObservableSource}s are delayed to the end
* if {@code false}, exception from the outer {@code ObservableSource} is delayed till the active {@code ObservableSource} terminates
* @return the new {@code Observable} with the concatenating behavior
* @throws NullPointerException if {@code sources} is {@code null}
* @throws IllegalArgumentException if {@code bufferSize} is non-positive
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatDelayError(@NonNull ObservableSource extends ObservableSource extends T>> sources, int bufferSize, boolean tillTheEnd) {
Objects.requireNonNull(sources, "sources is null");
ObjectHelper.verifyPositive(bufferSize, "bufferSize is null");
return RxJavaPlugins.onAssembly(new ObservableConcatMap(sources, Functions.identity(), bufferSize, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY));
}
/**
* Concatenates a sequence of {@link ObservableSource}s eagerly into a single stream of values.
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* {@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 a sequence of {@code ObservableSource}s that need to be eagerly concatenated
* @return the new {@code Observable} instance with the specified concatenation behavior
* @throws NullPointerException if {@code sources} is {@code null}
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable concatEager(@NonNull Iterable<@NonNull ? extends ObservableSource extends T>> sources) {
return concatEager(sources, bufferSize(), bufferSize());
}
/**
* Concatenates a sequence of {@link ObservableSource}s eagerly into a single stream of values and
* runs a limited number of inner sequences at once.
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* {@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 a sequence of {@code ObservableSource}s that need to be eagerly concatenated
* @param maxConcurrency the maximum number of concurrently running inner {@code ObservableSource}s; {@link Integer#MAX_VALUE}
* is interpreted as all inner {@code ObservableSource}s can be active at the same time
* @param bufferSize the number of elements expected from each inner {@code ObservableSource} to be buffered
* @return the new {@code Observable} instance with the specified concatenation behavior
* @throws NullPointerException if {@code sources} is {@code null}
* @throws IllegalArgumentException if {@code maxConcurrency} or {@code bufferSize} is non-positive
* @since 2.0
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable concatEager(@NonNull Iterable<@NonNull ? extends ObservableSource extends T>> sources, int maxConcurrency, int bufferSize) {
return fromIterable(sources).concatMapEagerDelayError((Function)Functions.identity(), false, maxConcurrency, bufferSize);
}
/**
* Concatenates an {@link ObservableSource} sequence of {@code ObservableSource}s eagerly into a single stream of values.
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* emitted source {@code ObservableSource}s as they are observed. 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 a sequence of {@code ObservableSource}s that need to be eagerly concatenated
* @return the new {@code Observable} instance with the specified concatenation behavior
* @throws NullPointerException if {@code sources} is {@code null}
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable concatEager(@NonNull ObservableSource extends ObservableSource extends T>> sources) {
return concatEager(sources, bufferSize(), bufferSize());
}
/**
* Concatenates an {@link ObservableSource} sequence of {@code ObservableSource}s eagerly into a single stream of values
* and runs a limited number of inner sequences at once.
*
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* emitted source {@code ObservableSource}s as they are observed. 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 a sequence of {@code ObservableSource}s that need to be eagerly concatenated
* @param maxConcurrency the maximum number of concurrently running inner {@code ObservableSource}s; {@link Integer#MAX_VALUE}
* is interpreted as all inner {@code ObservableSource}s can be active at the same time
* @param bufferSize the number of inner {@code ObservableSource} expected to be buffered
* @return the new {@code Observable} instance with the specified concatenation behavior
* @throws NullPointerException if {@code sources} is {@code null}
* @throws IllegalArgumentException if {@code maxConcurrency} or {@code bufferSize} is non-positive
* @since 2.0
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable concatEager(@NonNull ObservableSource extends ObservableSource extends T>> sources, int maxConcurrency, int bufferSize) {
return wrap(sources).concatMapEager((Function)Functions.identity(), maxConcurrency, bufferSize);
}
/**
* Concatenates a sequence of {@link ObservableSource}s eagerly into a single stream of values,
* delaying errors until all the inner sequences terminate.
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* {@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 a sequence of {@code ObservableSource}s that need to be eagerly concatenated
* @return the new {@code Observable} instance with the specified concatenation behavior
* @throws NullPointerException if {@code sources} is {@code null}
* @since 3.0.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable concatEagerDelayError(@NonNull Iterable<@NonNull ? extends ObservableSource extends T>> sources) {
return concatEagerDelayError(sources, bufferSize(), bufferSize());
}
/**
* Concatenates a sequence of {@link ObservableSource}s eagerly into a single stream of values,
* delaying errors until all the inner sequences terminate and runs a limited number of inner
* sequences at once.
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* {@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 a sequence of {@code ObservableSource}s that need to be eagerly concatenated
* @param maxConcurrency the maximum number of concurrently running inner {@code ObservableSource}s; {@link Integer#MAX_VALUE}
* is interpreted as all inner {@code ObservableSource}s can be active at the same time
* @param bufferSize the number of elements expected from each inner {@code ObservableSource} to be buffered
* @return the new {@code Observable} instance with the specified concatenation behavior
* @throws NullPointerException if {@code sources} is {@code null}
* @throws IllegalArgumentException if {@code maxConcurrency} or {@code bufferSize} is non-positive
* @since 3.0.0
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable concatEagerDelayError(@NonNull Iterable<@NonNull ? extends ObservableSource extends T>> sources, int maxConcurrency, int bufferSize) {
return fromIterable(sources).concatMapEagerDelayError((Function)Functions.identity(), true, maxConcurrency, bufferSize);
}
/**
* Concatenates an {@link ObservableSource} sequence of {@code ObservableSource}s eagerly into a single stream of values,
* delaying errors until all the inner and the outer sequence terminate.
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* emitted source {@code ObservableSource}s as they are observed. 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 a sequence of {@code ObservableSource}s that need to be eagerly concatenated
* @return the new {@code Observable} instance with the specified concatenation behavior
* @throws NullPointerException if {@code sources} is {@code null}
* @since 3.0.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable concatEagerDelayError(@NonNull ObservableSource extends ObservableSource extends T>> sources) {
return concatEagerDelayError(sources, bufferSize(), bufferSize());
}
/**
* Concatenates an {@link ObservableSource} sequence of {@code ObservableSource}s eagerly into a single stream of values,
* delaying errors until all the inner and the outer sequence terminate and runs a limited number of inner sequences at once.
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* emitted source {@code ObservableSource}s as they are observed. 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 a sequence of {@code ObservableSource}s that need to be eagerly concatenated
* @param maxConcurrency the maximum number of concurrently running inner {@code ObservableSource}s; {@link Integer#MAX_VALUE}
* is interpreted as all inner {@code ObservableSource}s can be active at the same time
* @param bufferSize the number of inner {@code ObservableSource} expected to be buffered
* @return the new {@code Observable} instance with the specified concatenation behavior
* @throws NullPointerException if {@code sources} is {@code null}
* @throws IllegalArgumentException if {@code maxConcurrency} or {@code bufferSize} is non-positive
* @since 3.0.0
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
public static Observable concatEagerDelayError(@NonNull ObservableSource extends ObservableSource extends T>> sources, int maxConcurrency, int bufferSize) {
return wrap(sources).concatMapEagerDelayError((Function)Functions.identity(), true, maxConcurrency, bufferSize);
}
/**
* Provides an API (via a cold {@code 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);
*
* });
*
*
* Whenever an {@link Observer} subscribes to the returned {@code Observable}, the provided
* {@link ObservableOnSubscribe} callback is invoked with a fresh instance of an {@link ObservableEmitter}
* that will interact only with that specific {@code Observer}. If this {@code Observer}
* disposes the flow (making {@link ObservableEmitter#isDisposed} return {@code true}),
* other observers subscribed to the same returned {@code Observable} are not affected.
*
*
*
* You should call the {@code ObservableEmitter}'s {@code onNext}, {@code onError} and {@code 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 {@code Observer} subscribes to the returned {@code Observable}
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source} is {@code null}
* @see ObservableOnSubscribe
* @see ObservableEmitter
* @see Cancellable
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable create(@NonNull ObservableOnSubscribe source) {
Objects.requireNonNull(source, "source is null");
return RxJavaPlugins.onAssembly(new ObservableCreate<>(source));
}
/**
* Returns an {@code Observable} that calls an {@link ObservableSource} factory to create an {@code ObservableSource} for each new {@link Observer}
* that subscribes. That is, for each subscriber, the actual {@code ObservableSource} that subscriber observes is
* determined by the factory function.
*
*
*
* The {@code defer} operator allows you to defer or delay emitting items from an {@code ObservableSource} until such time as an
* {@code Observer} subscribes to the {@code ObservableSource}. This allows an {@code 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 {@code ObservableSource} factory function to invoke for each {@code Observer} that subscribes to the
* resulting {@code Observable}
* @param
* the type of the items emitted by the {@code ObservableSource}
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code supplier} is {@code null}
* @see ReactiveX operators documentation: Defer
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable defer(@NonNull Supplier extends ObservableSource extends T>> supplier) {
Objects.requireNonNull(supplier, "supplier is null");
return RxJavaPlugins.onAssembly(new ObservableDefer<>(supplier));
}
/**
* Returns an {@code 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 {@code Observable}
* @return the shared {@code Observable} instance
* @see ReactiveX operators documentation: Empty
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
@NonNull
public static Observable empty() {
return RxJavaPlugins.onAssembly((Observable) ObservableEmpty.INSTANCE);
}
/**
* Returns an {@code Observable} that invokes an {@link Observer}'s {@link Observer#onError onError} method when the
* {@code Observer} subscribes to it.
*
*
*
* - Scheduler:
* - {@code error} does not operate by default on a particular {@link Scheduler}.
*
*
* @param supplier
* a {@link Supplier} factory to return a {@link Throwable} for each individual {@code Observer}
* @param
* the type of the items (ostensibly) emitted by the {@code Observable}
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code supplier} is {@code null}
* @see ReactiveX operators documentation: Throw
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable error(@NonNull Supplier extends Throwable> supplier) {
Objects.requireNonNull(supplier, "supplier is null");
return RxJavaPlugins.onAssembly(new ObservableError<>(supplier));
}
/**
* Returns an {@code Observable} that invokes an {@link Observer}'s {@link Observer#onError onError} method when the
* {@code Observer} subscribes to it.
*
*
*
* - Scheduler:
* - {@code error} does not operate by default on a particular {@link Scheduler}.
*
*
* @param throwable
* the particular {@link Throwable} to pass to {@link Observer#onError onError}
* @param
* the type of the items (ostensibly) emitted by the {@code Observable}
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code throwable} is {@code null}
* @see ReactiveX operators documentation: Throw
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable error(@NonNull Throwable throwable) {
Objects.requireNonNull(throwable, "throwable is null");
return error(Functions.justSupplier(throwable));
}
/**
* Returns an {@code Observable} instance that runs the given {@link 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 {@code Action} throws an exception, the respective {@link Throwable} is
* delivered to the downstream via {@link Observer#onError(Throwable)},
* except when the downstream has canceled the resulting {@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.rxjava3.exceptions.UndeliverableException UndeliverableException}.
*
*
* @param the target type
* @param action the {@code Action} to run for each subscriber
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code action} is {@code null}
* @since 3.0.0
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromAction(@NonNull Action action) {
Objects.requireNonNull(action, "action is null");
return RxJavaPlugins.onAssembly(new ObservableFromAction<>(action));
}
/**
* Converts an array into an {@link 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 {@code Observable}
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code items} is {@code null}
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@NonNull
@SafeVarargs
public static Observable fromArray(@NonNull T... items) {
Objects.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 {@code 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
* {@code Observable}. 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 the current {@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 UndeliverableException}.
*
*
* @param callable
* a function, the execution of which should be deferred; {@code fromCallable} will invoke this
* function only when an observer subscribes to the {@code Observable} that {@code fromCallable} returns
* @param
* the type of the item returned by the {@code Callable} and emitted by the {@code Observable}
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code callable} is {@code null}
* @see #defer(Supplier)
* @see #fromSupplier(Supplier)
* @since 2.0
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromCallable(@NonNull Callable extends T> callable) {
Objects.requireNonNull(callable, "callable is null");
return RxJavaPlugins.onAssembly(new ObservableFromCallable<>(callable));
}
/**
* Wraps a {@link CompletableSource} into an {@code Observable}.
*
*
*
* - Scheduler:
* - {@code fromCompletable} does not operate by default on a particular {@link Scheduler}.
*
* @param the target type
* @param completableSource the {@code CompletableSource} to convert from
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code completableSource} is {@code null}
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromCompletable(@NonNull CompletableSource completableSource) {
Objects.requireNonNull(completableSource, "completableSource is null");
return RxJavaPlugins.onAssembly(new ObservableFromCompletable<>(completableSource));
}
/**
* Converts a {@link Future} into an {@code Observable}.
*
*
*
* The operator calls {@link Future#get()}, which is a blocking method, on the subscription thread.
* It is recommended applying {@link #subscribeOn(Scheduler)} to move this blocking wait to a
* background thread, and if the {@link Scheduler} supports it, interrupt the wait when the flow
* is disposed.
*
* Unlike 1.x, disposing the {@code Observable} won't cancel the future. If necessary, one can use composition to achieve the
* cancellation effect: {@code futureObservableSource.doOnDispose(() -> future.cancel(true));}.
*
* Also note that this operator will consume a {@link CompletionStage}-based {@code Future} subclass (such as
* {@link CompletableFuture}) in a blocking manner as well. Use the {@link #fromCompletionStage(CompletionStage)}
* operator to convert and consume such sources in a non-blocking fashion instead.
*
* - Scheduler:
* - {@code fromFuture} does not operate by default on a particular {@code Scheduler}.
*
*
* @param future
* the source {@code Future}
* @param
* the type of object that the {@code Future} returns, and also the type of item to be emitted by
* the resulting {@code Observable}
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code future} is {@code null}
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromFuture(@NonNull Future extends T> future) {
Objects.requireNonNull(future, "future is null");
return RxJavaPlugins.onAssembly(new ObservableFromFuture<>(future, 0L, null));
}
/**
* Converts a {@link Future} into an {@code Observable}, with a timeout on the {@code Future}.
*
*
*
* The operator calls {@link Future#get(long, TimeUnit)}, which is a blocking method, on the subscription thread.
* It is recommended applying {@link #subscribeOn(Scheduler)} to move this blocking wait to a
* background thread, and if the {@link Scheduler} supports it, interrupt the wait when the flow
* is disposed.
*
* Unlike 1.x, disposing the {@code Observable} won't cancel the future. If necessary, one can use composition to achieve the
* cancellation effect: {@code futureObservableSource.doOnDispose(() -> future.cancel(true));}.
*
* Also note that this operator will consume a {@link CompletionStage}-based {@code Future} subclass (such as
* {@link CompletableFuture}) in a blocking manner as well. Use the {@link #fromCompletionStage(CompletionStage)}
* operator to convert and consume such sources in a non-blocking fashion instead.
*
* - Scheduler:
* - {@code fromFuture} does not operate by default on a particular {@code Scheduler}.
*
*
* @param future
* the source {@code 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 {@code Future} returns, and also the type of item to be emitted by
* the resulting {@code Observable}
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code future} or {@code unit} is {@code null}
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromFuture(@NonNull Future extends T> future, long timeout, @NonNull TimeUnit unit) {
Objects.requireNonNull(future, "future is null");
Objects.requireNonNull(unit, "unit is null");
return RxJavaPlugins.onAssembly(new ObservableFromFuture<>(future, timeout, unit));
}
/**
* Converts an {@link Iterable} sequence into an {@code Observable} that emits the items in the sequence.
*
*
*
* - Scheduler:
* - {@code fromIterable} does not operate by default on a particular {@link Scheduler}.
*
*
* @param source
* the source {@code Iterable} sequence
* @param
* the type of items in the {@code Iterable} sequence and the type of items to be emitted by the
* resulting {@code Observable}
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source} is {@code null}
* @see ReactiveX operators documentation: From
* @see #fromStream(Stream)
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromIterable(@NonNull Iterable<@NonNull ? extends T> source) {
Objects.requireNonNull(source, "source is null");
return RxJavaPlugins.onAssembly(new ObservableFromIterable<>(source));
}
/**
* Returns an {@code Observable} instance that when subscribed to, subscribes to the {@link MaybeSource} instance and
* emits {@code onSuccess} as a single item or forwards any {@code onComplete} or
* {@code onError} signal.
*
*
*
* - Scheduler:
* - {@code fromMaybe} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type of the {@code MaybeSource} element
* @param maybe the {@code MaybeSource} instance to subscribe to, not {@code null}
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code maybe} is {@code null}
* @since 3.0.0
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromMaybe(@NonNull MaybeSource maybe) {
Objects.requireNonNull(maybe, "maybe is null");
return RxJavaPlugins.onAssembly(new MaybeToObservable<>(maybe));
}
/**
* Converts an arbitrary Reactive Streams {@link Publisher} into an {@code Observable}.
*
*
*
* The {@code Publisher} must follow the
* Reactive-Streams specification.
* Violating the specification may result in undefined behavior.
*
* If possible, use {@link #create(ObservableOnSubscribe)} to create a
* source-like {@code Observable} instead.
*
* Note that even though {@code Publisher} appears to be a functional interface, it
* is not recommended to implement it through a lambda as the specification requires
* state management that is not achievable with a stateless lambda.
*
* - Backpressure:
* - The source {@code publisher} is consumed in an unbounded fashion without applying any
* backpressure to it.
* - Scheduler:
* - {@code fromPublisher} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type of the flow
* @param publisher the {@code Publisher} to convert
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code publisher} is {@code null}
* @see #create(ObservableOnSubscribe)
*/
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromPublisher(@NonNull Publisher<@NonNull ? extends T> publisher) {
Objects.requireNonNull(publisher, "publisher is null");
return RxJavaPlugins.onAssembly(new ObservableFromPublisher<>(publisher));
}
/**
* Returns an {@code Observable} instance that runs the given {@link Runnable} for each observer and
* emits either its exception or simply completes.
*
*
*
* - Scheduler:
* - {@code fromRunnable} does not operate by default on a particular {@link Scheduler}.
* - Error handling:
* - If the {@code Runnable} throws an exception, the respective {@link Throwable} is
* delivered to the downstream via {@link Observer#onError(Throwable)},
* except when the downstream has canceled the resulting {@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.rxjava3.exceptions.UndeliverableException UndeliverableException}.
*
*
* @param the target type
* @param run the {@code Runnable} to run for each observer
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code run} is {@code null}
* @since 3.0.0
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromRunnable(@NonNull Runnable run) {
Objects.requireNonNull(run, "run is null");
return RxJavaPlugins.onAssembly(new ObservableFromRunnable<>(run));
}
/**
* Returns an {@code Observable} instance that when subscribed to, subscribes to the {@link SingleSource} instance and
* emits {@code onSuccess} as a single item or forwards the {@code onError} signal.
*
*
*
* - Scheduler:
* - {@code fromSingle} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type of the {@code SingleSource} element
* @param source the {@code SingleSource} instance to subscribe to, not {@code null}
* @return the new {@code Observable} instance
* @throws NullPointerException if {@code source} is {@code null}
* @since 3.0.0
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromSingle(@NonNull SingleSource