io.reactivex.observable.Observable Maven / Gradle / Ivy
Show all versions of rxjava3-observable Show documentation
/**
* Copyright (c) 2016-present, RxJava Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/
package io.reactivex.observable;
import java.util.*;
import java.util.concurrent.*;
import io.reactivex.common.*;
import io.reactivex.common.annotations.*;
import io.reactivex.common.exceptions.Exceptions;
import io.reactivex.common.functions.*;
import io.reactivex.common.internal.functions.*;
import io.reactivex.common.internal.utils.*;
import io.reactivex.observable.extensions.ScalarCallable;
import io.reactivex.observable.internal.observers.*;
import io.reactivex.observable.internal.operators.*;
import io.reactivex.observable.observers.*;
/**
* The Observable class that is designed similar to the Reactive-Streams Pattern, minus the backpressure,
* and offers factory methods, intermediate operators and the ability to consume reactive dataflows.
*
* Reactive-Streams operates with {@code ObservableSource}s which {@code Observable} extends. Many operators
* therefore accept general {@code ObservableSource}s directly and allow direct interoperation with other
* Reactive-Streams implementations.
*
* The Observable's operators, by default, run with a buffer size of 128 elements,
* that can be overridden globally via the system parameter {@code rx2.buffer-size}. Most operators, however, have
* overloads that allow setting their internal buffer size explicitly.
*
* The documentation for this class makes use of marble diagrams. The following legend explains these diagrams:
*
*
*
* For more information see the ReactiveX
* documentation.
*
* @param
* the type of the items emitted by the Observable
*/
public abstract class Observable implements ObservableSource {
/** The default buffer size. */
static final int BUFFER_SIZE;
static {
BUFFER_SIZE = Math.max(16, Integer.getInteger("rx2.buffer-size", 128));
}
/**
* Mirrors the one ObservableSource in an Iterable of several ObservableSources that first either emits an item or sends
* a termination notification.
*
*
*
* - Scheduler:
* - {@code amb} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element type
* @param sources
* an Iterable of ObservableSource sources competing to react first. A subscription to each source will
* occur in the same order as in the Iterable.
* @return an Observable that emits the same sequence as whichever of the source ObservableSources first
* emitted an item or sent a termination notification
* @see ReactiveX operators documentation: Amb
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable amb(Iterable extends ObservableSource extends T>> sources) {
ObjectHelper.requireNonNull(sources, "sources is null");
return RxJavaObservablePlugins.onAssembly(new ObservableAmb(null, sources));
}
/**
* Mirrors the one ObservableSource in an array of several ObservableSources that first either emits an item or sends
* a termination notification.
*
*
*
* - Scheduler:
* - {@code ambArray} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element type
* @param sources
* an array of ObservableSource sources competing to react first. A subscription to each source will
* occur in the same order as in the array.
* @return an Observable that emits the same sequence as whichever of the source ObservableSources first
* emitted an item or sent a termination notification
* @see ReactiveX operators documentation: Amb
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable ambArray(ObservableSource extends T>... sources) {
ObjectHelper.requireNonNull(sources, "sources is null");
int len = sources.length;
if (len == 0) {
return empty();
}
if (len == 1) {
return (Observable)wrap(sources[0]);
}
return RxJavaObservablePlugins.onAssembly(new ObservableAmb(sources, null));
}
/**
* Returns the default 'island' size or capacity-increment hint for unbounded buffers.
* The value can be overridden via system parameter {@code rx2.buffer-size}
* before the {@link Observable} class is loaded.
* @return the default 'island' size or capacity-increment hint
*/
public static int bufferSize() {
return BUFFER_SIZE;
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the
* implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a
* {@code Function} passed to the method would trigger a {@code ClassCastException}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @param bufferSize
* the internal buffer size and prefetch amount applied to every source Observable
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(Function super Object[], ? extends R> combiner, int bufferSize, ObservableSource extends T>... sources) {
return combineLatest(sources, combiner, bufferSize);
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the
* implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a
* {@code Function} passed to the method would trigger a {@code ClassCastException}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(Iterable extends ObservableSource extends T>> sources,
Function super Object[], ? extends R> combiner) {
return combineLatest(sources, combiner, bufferSize());
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the
* implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a
* {@code Function} passed to the method would trigger a {@code ClassCastException}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @param bufferSize
* the internal buffer size and prefetch amount applied to every source Observable
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(Iterable extends ObservableSource extends T>> sources,
Function super Object[], ? extends R> combiner, int bufferSize) {
ObjectHelper.requireNonNull(sources, "sources is null");
ObjectHelper.requireNonNull(combiner, "combiner is null");
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
// the queue holds a pair of values so we need to double the capacity
int s = bufferSize << 1;
return RxJavaObservablePlugins.onAssembly(new ObservableCombineLatest(null, sources, combiner, s, false));
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the
* implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a
* {@code Function} passed to the method would trigger a {@code ClassCastException}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(ObservableSource extends T>[] sources,
Function super Object[], ? extends R> combiner) {
return combineLatest(sources, combiner, bufferSize());
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the
* implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a
* {@code Function} passed to the method would trigger a {@code ClassCastException}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @param bufferSize
* the internal buffer size and prefetch amount applied to every source Observable
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(ObservableSource extends T>[] sources,
Function super Object[], ? extends R> combiner, int bufferSize) {
ObjectHelper.requireNonNull(sources, "sources is null");
if (sources.length == 0) {
return empty();
}
ObjectHelper.requireNonNull(combiner, "combiner is null");
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
// the queue holds a pair of values so we need to double the capacity
int s = bufferSize << 1;
return RxJavaObservablePlugins.onAssembly(new ObservableCombineLatest(sources, null, combiner, s, false));
}
/**
* Combines two source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from either of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
BiFunction super T1, ? super T2, ? extends R> combiner) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2);
}
/**
* Combines three source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3,
Function3 super T1, ? super T2, ? super T3, ? extends R> combiner) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3);
}
/**
* Combines four source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the element type of the fourth source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param source4
* the fourth source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3, ObservableSource extends T4> source4,
Function4 super T1, ? super T2, ? super T3, ? super T4, ? extends R> combiner) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
ObjectHelper.requireNonNull(source4, "source4 is null");
return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4);
}
/**
* Combines five source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the element type of the fourth source
* @param the element type of the fifth source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param source4
* the fourth source ObservableSource
* @param source5
* the fifth source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3, ObservableSource extends T4> source4,
ObservableSource extends T5> source5,
Function5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> combiner) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
ObjectHelper.requireNonNull(source4, "source4 is null");
ObjectHelper.requireNonNull(source5, "source5 is null");
return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5);
}
/**
* Combines six source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the element type of the fourth source
* @param the element type of the fifth source
* @param the element type of the sixth source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param source4
* the fourth source ObservableSource
* @param source5
* the fifth source ObservableSource
* @param source6
* the sixth source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3, ObservableSource extends T4> source4,
ObservableSource extends T5> source5, ObservableSource extends T6> source6,
Function6 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> combiner) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
ObjectHelper.requireNonNull(source4, "source4 is null");
ObjectHelper.requireNonNull(source5, "source5 is null");
ObjectHelper.requireNonNull(source6, "source6 is null");
return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5, source6);
}
/**
* Combines seven source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the element type of the fourth source
* @param the element type of the fifth source
* @param the element type of the sixth source
* @param the element type of the seventh source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param source4
* the fourth source ObservableSource
* @param source5
* the fifth source ObservableSource
* @param source6
* the sixth source ObservableSource
* @param source7
* the seventh source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3, ObservableSource extends T4> source4,
ObservableSource extends T5> source5, ObservableSource extends T6> source6,
ObservableSource extends T7> source7,
Function7 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> combiner) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
ObjectHelper.requireNonNull(source4, "source4 is null");
ObjectHelper.requireNonNull(source5, "source5 is null");
ObjectHelper.requireNonNull(source6, "source6 is null");
ObjectHelper.requireNonNull(source7, "source7 is null");
return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5, source6, source7);
}
/**
* Combines eight source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the element type of the fourth source
* @param the element type of the fifth source
* @param the element type of the sixth source
* @param the element type of the seventh source
* @param the element type of the eighth source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param source4
* the fourth source ObservableSource
* @param source5
* the fifth source ObservableSource
* @param source6
* the sixth source ObservableSource
* @param source7
* the seventh source ObservableSource
* @param source8
* the eighth source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3, ObservableSource extends T4> source4,
ObservableSource extends T5> source5, ObservableSource extends T6> source6,
ObservableSource extends T7> source7, ObservableSource extends T8> source8,
Function8 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> combiner) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
ObjectHelper.requireNonNull(source4, "source4 is null");
ObjectHelper.requireNonNull(source5, "source5 is null");
ObjectHelper.requireNonNull(source6, "source6 is null");
ObjectHelper.requireNonNull(source7, "source7 is null");
ObjectHelper.requireNonNull(source8, "source8 is null");
return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5, source6, source7, source8);
}
/**
* Combines nine source ObservableSources by emitting an item that aggregates the latest values of each of the
* source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type of the first source
* @param the element type of the second source
* @param the element type of the third source
* @param the element type of the fourth source
* @param the element type of the fifth source
* @param the element type of the sixth source
* @param the element type of the seventh source
* @param the element type of the eighth source
* @param the element type of the ninth source
* @param the combined output type
* @param source1
* the first source ObservableSource
* @param source2
* the second source ObservableSource
* @param source3
* the third source ObservableSource
* @param source4
* the fourth source ObservableSource
* @param source5
* the fifth source ObservableSource
* @param source6
* the sixth source ObservableSource
* @param source7
* the seventh source ObservableSource
* @param source8
* the eighth source ObservableSource
* @param source9
* the ninth source ObservableSource
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatest(
ObservableSource extends T1> source1, ObservableSource extends T2> source2,
ObservableSource extends T3> source3, ObservableSource extends T4> source4,
ObservableSource extends T5> source5, ObservableSource extends T6> source6,
ObservableSource extends T7> source7, ObservableSource extends T8> source8,
ObservableSource extends T9> source9,
Function9 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9, ? extends R> combiner) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
ObjectHelper.requireNonNull(source4, "source4 is null");
ObjectHelper.requireNonNull(source5, "source5 is null");
ObjectHelper.requireNonNull(source6, "source6 is null");
ObjectHelper.requireNonNull(source7, "source7 is null");
ObjectHelper.requireNonNull(source8, "source8 is null");
ObjectHelper.requireNonNull(source9, "source9 is null");
return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5, source6, source7, source8, source9);
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function.
*
* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the
* implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a
* {@code Function} passed to the method would trigger a {@code ClassCastException}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
* - Scheduler:
* - {@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatestDelayError(ObservableSource extends T>[] sources,
Function super Object[], ? extends R> combiner) {
return combineLatestDelayError(sources, combiner, bufferSize());
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function and delays any error from the sources until
* all source ObservableSources terminate.
*
* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the
* implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a
* {@code Function} passed to the method would trigger a {@code ClassCastException}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
* - Scheduler:
* - {@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @param bufferSize
* the internal buffer size and prefetch amount applied to every source Observable
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatestDelayError(Function super Object[], ? extends R> combiner,
int bufferSize, ObservableSource extends T>... sources) {
return combineLatestDelayError(sources, combiner, bufferSize);
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function and delays any error from the sources until
* all source ObservableSources terminate.
*
* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the
* implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a
* {@code Function} passed to the method would trigger a {@code ClassCastException}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @param bufferSize
* the internal buffer size and prefetch amount applied to every source Observable
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatestDelayError(ObservableSource extends T>[] sources,
Function super Object[], ? extends R> combiner, int bufferSize) {
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
ObjectHelper.requireNonNull(combiner, "combiner is null");
if (sources.length == 0) {
return empty();
}
// the queue holds a pair of values so we need to double the capacity
int s = bufferSize << 1;
return RxJavaObservablePlugins.onAssembly(new ObservableCombineLatest(sources, null, combiner, s, true));
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function and delays any error from the sources until
* all source ObservableSources terminate.
*
* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the
* implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a
* {@code Function} passed to the method would trigger a {@code ClassCastException}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatestDelayError(Iterable extends ObservableSource extends T>> sources,
Function super Object[], ? extends R> combiner) {
return combineLatestDelayError(sources, combiner, bufferSize());
}
/**
* Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of
* the source ObservableSources each time an item is received from any of the source ObservableSources, where this
* aggregation is defined by a specified function and delays any error from the sources until
* all source ObservableSources terminate.
*
* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the
* implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a
* {@code Function} passed to the method would trigger a {@code ClassCastException}.
*
* If any of the sources never produces an item but only terminates (normally or with an error), the
* resulting sequence terminates immediately (normally or with all the errors accumulated till that point).
* If that input source is also synchronous, other sources after it will not be subscribed to.
*
*
*
* - Scheduler:
* - {@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the common base type of source values
* @param
* the result type
* @param sources
* the collection of source ObservableSources
* @param combiner
* the aggregation function used to combine the items emitted by the source ObservableSources
* @param bufferSize
* the internal buffer size and prefetch amount applied to every source Observable
* @return an Observable that emits items that are the result of combining the items emitted by the source
* ObservableSources by means of the given aggregation function
* @see ReactiveX operators documentation: CombineLatest
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable combineLatestDelayError(Iterable extends ObservableSource extends T>> sources,
Function super Object[], ? extends R> combiner, int bufferSize) {
ObjectHelper.requireNonNull(sources, "sources is null");
ObjectHelper.requireNonNull(combiner, "combiner is null");
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
// the queue holds a pair of values so we need to double the capacity
int s = bufferSize << 1;
return RxJavaObservablePlugins.onAssembly(new ObservableCombineLatest(null, sources, combiner, s, true));
}
/**
* Concatenates elements of each ObservableSource provided via an Iterable sequence into a single sequence
* of elements without interleaving them.
*
*
*
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
* @param the common value type of the sources
* @param sources the Iterable sequence of ObservableSources
* @return the new Observable instance
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(Iterable extends ObservableSource extends T>> sources) {
ObjectHelper.requireNonNull(sources, "sources is null");
return fromIterable(sources).concatMapDelayError((Function)Functions.identity(), bufferSize(), false);
}
/**
* Returns an Observable that emits the items emitted by each of the ObservableSources emitted by the source
* ObservableSource, one after the other, without interleaving them.
*
*
*
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param sources
* an ObservableSource that emits ObservableSources
* @return an Observable that emits items all of the items emitted by the ObservableSources emitted by
* {@code ObservableSources}, one after the other, without interleaving them
* @see ReactiveX operators documentation: Concat
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(ObservableSource extends ObservableSource extends T>> sources) {
return concat(sources, bufferSize());
}
/**
* Returns an Observable that emits the items emitted by each of the ObservableSources emitted by the source
* ObservableSource, one after the other, without interleaving them.
*
*
*
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param sources
* an ObservableSource that emits ObservableSources
* @param prefetch
* the number of ObservableSources to prefetch from the sources sequence.
* @return an Observable that emits items all of the items emitted by the ObservableSources emitted by
* {@code ObservableSources}, one after the other, without interleaving them
* @see ReactiveX operators documentation: Concat
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(ObservableSource extends ObservableSource extends T>> sources, int prefetch) {
ObjectHelper.requireNonNull(sources, "sources is null");
ObjectHelper.verifyPositive(prefetch, "prefetch");
return RxJavaObservablePlugins.onAssembly(new ObservableConcatMap(sources, Functions.identity(), prefetch, ErrorMode.IMMEDIATE));
}
/**
* Returns an Observable that emits the items emitted by two ObservableSources, one after the other, without
* interleaving them.
*
*
*
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param source1
* an ObservableSource to be concatenated
* @param source2
* an ObservableSource to be concatenated
* @return an Observable that emits items emitted by the two source ObservableSources, one after the other,
* without interleaving them
* @see ReactiveX operators documentation: Concat
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(ObservableSource extends T> source1, ObservableSource extends T> source2) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
return concatArray(source1, source2);
}
/**
* Returns an Observable that emits the items emitted by three ObservableSources, one after the other, without
* interleaving them.
*
*
*
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param source1
* an ObservableSource to be concatenated
* @param source2
* an ObservableSource to be concatenated
* @param source3
* an ObservableSource to be concatenated
* @return an Observable that emits items emitted by the three source ObservableSources, one after the other,
* without interleaving them
* @see ReactiveX operators documentation: Concat
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(
ObservableSource extends T> source1, ObservableSource extends T> source2,
ObservableSource extends T> source3) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
return concatArray(source1, source2, source3);
}
/**
* Returns an Observable that emits the items emitted by four ObservableSources, one after the other, without
* interleaving them.
*
*
*
* - Scheduler:
* - {@code concat} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param source1
* an ObservableSource to be concatenated
* @param source2
* an ObservableSource to be concatenated
* @param source3
* an ObservableSource to be concatenated
* @param source4
* an ObservableSource to be concatenated
* @return an Observable that emits items emitted by the four source ObservableSources, one after the other,
* without interleaving them
* @see ReactiveX operators documentation: Concat
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concat(
ObservableSource extends T> source1, ObservableSource extends T> source2,
ObservableSource extends T> source3, ObservableSource extends T> source4) {
ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
ObjectHelper.requireNonNull(source4, "source4 is null");
return concatArray(source1, source2, source3, source4);
}
/**
* Concatenates a variable number of ObservableSource sources.
*
* Note: named this way because of overload conflict with concat(ObservableSource<ObservableSource>)
*
*
*
* - Scheduler:
* - {@code concatArray} does not operate by default on a particular {@link Scheduler}.
*
* @param sources the array of sources
* @param the common base value type
* @return the new Observable instance
* @throws NullPointerException if sources is null
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatArray(ObservableSource extends T>... sources) {
if (sources.length == 0) {
return empty();
} else
if (sources.length == 1) {
return wrap((ObservableSource)sources[0]);
}
return RxJavaObservablePlugins.onAssembly(new ObservableConcatMap(fromArray(sources), Functions.identity(), bufferSize(), ErrorMode.BOUNDARY));
}
/**
* Concatenates a variable number of ObservableSource sources and delays errors from any of them
* till all terminate.
*
*
*
* - Scheduler:
* - {@code concatArrayDelayError} does not operate by default on a particular {@link Scheduler}.
*
* @param sources the array of sources
* @param the common base value type
* @return the new Observable instance
* @throws NullPointerException if sources is null
*/
@SuppressWarnings({ "unchecked" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatArrayDelayError(ObservableSource extends T>... sources) {
if (sources.length == 0) {
return empty();
} else
if (sources.length == 1) {
return (Observable)wrap(sources[0]);
}
return concatDelayError(fromArray(sources));
}
/**
* Concatenates a sequence of ObservableSources eagerly into a single stream of values.
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them
* in order, each one after the previous one completes.
*
*
*
* - Scheduler:
* - This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type
* @param sources a sequence of ObservableSources that need to be eagerly concatenated
* @return the new ObservableSource instance with the specified concatenation behavior
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatArrayEager(ObservableSource extends T>... sources) {
return concatArrayEager(bufferSize(), bufferSize(), sources);
}
/**
* Concatenates a sequence of ObservableSources eagerly into a single stream of values.
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them
* in order, each one after the previous one completes.
*
* - Scheduler:
* - This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type
* @param sources a sequence of ObservableSources that need to be eagerly concatenated
* @param maxConcurrency the maximum number of concurrent subscriptions at a time, Integer.MAX_VALUE
* is interpreted as indication to subscribe to all sources at once
* @param prefetch the number of elements to prefetch from each ObservableSource source
* @return the new ObservableSource instance with the specified concatenation behavior
* @since 2.0
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatArrayEager(int maxConcurrency, int prefetch, ObservableSource extends T>... sources) {
return fromArray(sources).concatMapEagerDelayError((Function)Functions.identity(), maxConcurrency, prefetch, false);
}
/**
* Concatenates the Iterable sequence of ObservableSources into a single sequence by subscribing to each ObservableSource,
* one after the other, one at a time and delays any errors till the all inner ObservableSources terminate.
*
*
*
* - Scheduler:
* - {@code concatDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param sources the Iterable sequence of ObservableSources
* @return the new ObservableSource with the concatenating behavior
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatDelayError(Iterable extends ObservableSource extends T>> sources) {
ObjectHelper.requireNonNull(sources, "sources is null");
return concatDelayError(fromIterable(sources));
}
/**
* Concatenates the ObservableSource sequence of ObservableSources into a single sequence by subscribing to each inner ObservableSource,
* one after the other, one at a time and delays any errors till the all inner and the outer ObservableSources terminate.
*
*
*
* - Scheduler:
* - {@code concatDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param sources the ObservableSource sequence of ObservableSources
* @return the new ObservableSource with the concatenating behavior
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatDelayError(ObservableSource extends ObservableSource extends T>> sources) {
return concatDelayError(sources, bufferSize(), true);
}
/**
* Concatenates the ObservableSource sequence of ObservableSources into a single sequence by subscribing to each inner ObservableSource,
* one after the other, one at a time and delays any errors till the all inner and the outer ObservableSources terminate.
*
*
*
* - Scheduler:
* - {@code concatDelayError} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the common element base type
* @param sources the ObservableSource sequence of ObservableSources
* @param prefetch the number of elements to prefetch from the outer ObservableSource
* @param tillTheEnd if true exceptions from the outer and all inner ObservableSources are delayed to the end
* if false, exception from the outer ObservableSource is delayed till the current ObservableSource terminates
* @return the new ObservableSource with the concatenating behavior
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatDelayError(ObservableSource extends ObservableSource extends T>> sources, int prefetch, boolean tillTheEnd) {
ObjectHelper.requireNonNull(sources, "sources is null");
ObjectHelper.verifyPositive(prefetch, "prefetch is null");
return RxJavaObservablePlugins.onAssembly(new ObservableConcatMap(sources, Functions.identity(), prefetch, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY));
}
/**
* Concatenates an ObservableSource sequence of ObservableSources eagerly into a single stream of values.
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* emitted source ObservableSources as they are observed. The operator buffers the values emitted by these
* ObservableSources and then drains them in order, each one after the previous one completes.
*
*
*
* - Scheduler:
* - This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type
* @param sources a sequence of ObservableSources that need to be eagerly concatenated
* @return the new ObservableSource instance with the specified concatenation behavior
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatEager(ObservableSource extends ObservableSource extends T>> sources) {
return concatEager(sources, bufferSize(), bufferSize());
}
/**
* Concatenates an ObservableSource sequence of ObservableSources eagerly into a single stream of values.
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* emitted source ObservableSources as they are observed. The operator buffers the values emitted by these
* ObservableSources and then drains them in order, each one after the previous one completes.
*
*
*
* - Scheduler:
* - This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type
* @param sources a sequence of ObservableSources that need to be eagerly concatenated
* @param maxConcurrency the maximum number of concurrently running inner ObservableSources; Integer.MAX_VALUE
* is interpreted as all inner ObservableSources can be active at the same time
* @param prefetch the number of elements to prefetch from each inner ObservableSource source
* @return the new ObservableSource instance with the specified concatenation behavior
* @since 2.0
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatEager(ObservableSource extends ObservableSource extends T>> sources, int maxConcurrency, int prefetch) {
ObjectHelper.requireNonNull(maxConcurrency, "maxConcurrency is null");
ObjectHelper.requireNonNull(prefetch, "prefetch is null");
return wrap(sources).concatMapEager((Function)Functions.identity(), maxConcurrency, prefetch);
}
/**
* Concatenates a sequence of ObservableSources eagerly into a single stream of values.
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them
* in order, each one after the previous one completes.
*
*
*
* - Scheduler:
* - This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type
* @param sources a sequence of ObservableSources that need to be eagerly concatenated
* @return the new ObservableSource instance with the specified concatenation behavior
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatEager(Iterable extends ObservableSource extends T>> sources) {
return concatEager(sources, bufferSize(), bufferSize());
}
/**
* Concatenates a sequence of ObservableSources eagerly into a single stream of values.
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
* source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them
* in order, each one after the previous one completes.
*
*
*
* - Scheduler:
* - This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type
* @param sources a sequence of ObservableSources that need to be eagerly concatenated
* @param maxConcurrency the maximum number of concurrently running inner ObservableSources; Integer.MAX_VALUE
* is interpreted as all inner ObservableSources can be active at the same time
* @param prefetch the number of elements to prefetch from each inner ObservableSource source
* @return the new ObservableSource instance with the specified concatenation behavior
* @since 2.0
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable concatEager(Iterable extends ObservableSource extends T>> sources, int maxConcurrency, int prefetch) {
ObjectHelper.requireNonNull(maxConcurrency, "maxConcurrency is null");
ObjectHelper.requireNonNull(prefetch, "prefetch is null");
return fromIterable(sources).concatMapEagerDelayError((Function)Functions.identity(), maxConcurrency, prefetch, false);
}
/**
* Provides an API (via a cold Observable) that bridges the reactive world with the callback-style world.
*
* Example:
*
* Observable.<Event>create(emitter -> {
* Callback listener = new Callback() {
* @Override
* public void onEvent(Event e) {
* emitter.onNext(e);
* if (e.isLast()) {
* emitter.onComplete();
* }
* }
*
* @Override
* public void onFailure(Exception e) {
* emitter.onError(e);
* }
* };
*
* AutoCloseable c = api.someMethod(listener);
*
* emitter.setCancellable(c::close);
*
* });
*
*
*
*
* You should call the ObservableEmitter's onNext, onError and onComplete methods in a serialized fashion. The
* rest of its methods are thread-safe.
*
* - Scheduler:
* - {@code create} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the element type
* @param source the emitter that is called when an Observer subscribes to the returned {@code Observable}
* @return the new Observable instance
* @see ObservableOnSubscribe
* @see ObservableEmitter
* @see Cancellable
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable create(ObservableOnSubscribe source) {
ObjectHelper.requireNonNull(source, "source is null");
return RxJavaObservablePlugins.onAssembly(new ObservableCreate(source));
}
/**
* Returns an Observable that calls an ObservableSource factory to create an ObservableSource for each new Observer
* that subscribes. That is, for each subscriber, the actual ObservableSource that subscriber observes is
* determined by the factory function.
*
*
*
* The defer Observer allows you to defer or delay emitting items from an ObservableSource until such time as an
* Observer subscribes to the ObservableSource. This allows an {@link Observer} to easily obtain updates or a
* refreshed version of the sequence.
*
* - Scheduler:
* - {@code defer} does not operate by default on a particular {@link Scheduler}.
*
*
* @param supplier
* the ObservableSource factory function to invoke for each {@link Observer} that subscribes to the
* resulting ObservableSource
* @param
* the type of the items emitted by the ObservableSource
* @return an Observable whose {@link Observer}s' subscriptions trigger an invocation of the given
* ObservableSource factory function
* @see ReactiveX operators documentation: Defer
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable defer(Callable extends ObservableSource extends T>> supplier) {
ObjectHelper.requireNonNull(supplier, "supplier is null");
return RxJavaObservablePlugins.onAssembly(new ObservableDefer(supplier));
}
/**
* Returns an Observable that emits no items to the {@link Observer} and immediately invokes its
* {@link Observer#onComplete onComplete} method.
*
*
*
* - Scheduler:
* - {@code empty} does not operate by default on a particular {@link Scheduler}.
*
*
* @param
* the type of the items (ostensibly) emitted by the ObservableSource
* @return an Observable that emits no items to the {@link Observer} but immediately invokes the
* {@link Observer}'s {@link Observer#onComplete() onComplete} method
* @see ReactiveX operators documentation: Empty
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public static Observable empty() {
return RxJavaObservablePlugins.onAssembly((Observable) ObservableEmpty.INSTANCE);
}
/**
* Returns an Observable that invokes an {@link Observer}'s {@link Observer#onError onError} method when the
* Observer subscribes to it.
*
*
*
* - Scheduler:
* - {@code error} does not operate by default on a particular {@link Scheduler}.
*
*
* @param errorSupplier
* a Callable factory to return a Throwable for each individual Observer
* @param
* the type of the items (ostensibly) emitted by the ObservableSource
* @return an Observable that invokes the {@link Observer}'s {@link Observer#onError onError} method when
* the Observer subscribes to it
* @see ReactiveX operators documentation: Throw
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable error(Callable extends Throwable> errorSupplier) {
ObjectHelper.requireNonNull(errorSupplier, "errorSupplier is null");
return RxJavaObservablePlugins.onAssembly(new ObservableError(errorSupplier));
}
/**
* Returns an Observable that invokes an {@link Observer}'s {@link Observer#onError onError} method when the
* Observer subscribes to it.
*
*
*
* - Scheduler:
* - {@code error} does not operate by default on a particular {@link Scheduler}.
*
*
* @param exception
* the particular Throwable to pass to {@link Observer#onError onError}
* @param
* the type of the items (ostensibly) emitted by the ObservableSource
* @return an Observable that invokes the {@link Observer}'s {@link Observer#onError onError} method when
* the Observer subscribes to it
* @see ReactiveX operators documentation: Throw
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable error(final Throwable exception) {
ObjectHelper.requireNonNull(exception, "e is null");
return error(Functions.justCallable(exception));
}
/**
* Converts an Array into an ObservableSource that emits the items in the Array.
*
*
*
* - Scheduler:
* - {@code fromArray} does not operate by default on a particular {@link Scheduler}.
*
*
* @param items
* the array of elements
* @param
* the type of items in the Array and the type of items to be emitted by the resulting ObservableSource
* @return an Observable that emits each item in the source Array
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromArray(T... items) {
ObjectHelper.requireNonNull(items, "items is null");
if (items.length == 0) {
return empty();
} else
if (items.length == 1) {
return just(items[0]);
}
return RxJavaObservablePlugins.onAssembly(new ObservableFromArray(items));
}
/**
* Returns an Observable that, when an observer subscribes to it, invokes a function you specify and then
* emits the value returned from that function.
*
*
*
* This allows you to defer the execution of the function you specify until an observer subscribes to the
* ObservableSource. That is to say, it makes the function "lazy."
*
* - Scheduler:
* - {@code fromCallable} does not operate by default on a particular {@link Scheduler}.
*
*
* @param supplier
* a function, the execution of which should be deferred; {@code fromCallable} will invoke this
* function only when an observer subscribes to the ObservableSource that {@code fromCallable} returns
* @param
* the type of the item emitted by the ObservableSource
* @return an Observable whose {@link Observer}s' subscriptions trigger an invocation of the given function
* @see #defer(Callable)
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromCallable(Callable extends T> supplier) {
ObjectHelper.requireNonNull(supplier, "supplier is null");
return RxJavaObservablePlugins.onAssembly(new ObservableFromCallable(supplier));
}
/**
* Converts a {@link Future} into an ObservableSource.
*
*
*
* You can convert any object that supports the {@link Future} interface into an ObservableSource that emits the
* return value of the {@link Future#get} method of that object, by passing the object into the {@code from}
* method.
*
* Important note: This ObservableSource is blocking; you cannot dispose it.
*
* Unlike 1.x, cancelling the Observable won't cancel the future. If necessary, one can use composition to achieve the
* cancellation effect: {@code futureObservableSource.doOnCancel(() -> future.cancel(true));}.
*
* - Scheduler:
* - {@code fromFuture} does not operate by default on a particular {@link Scheduler}.
*
*
* @param future
* the source {@link Future}
* @param
* the type of object that the {@link Future} returns, and also the type of item to be emitted by
* the resulting ObservableSource
* @return an Observable that emits the item from the source {@link Future}
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromFuture(Future extends T> future) {
ObjectHelper.requireNonNull(future, "future is null");
return RxJavaObservablePlugins.onAssembly(new ObservableFromFuture(future, 0L, null));
}
/**
* Converts a {@link Future} into an ObservableSource, with a timeout on the Future.
*
*
*
* You can convert any object that supports the {@link Future} interface into an ObservableSource that emits the
* return value of the {@link Future#get} method of that object, by passing the object into the {@code from}
* method.
*
* Unlike 1.x, cancelling the Observable won't cancel the future. If necessary, one can use composition to achieve the
* cancellation effect: {@code futureObservableSource.doOnCancel(() -> future.cancel(true));}.
*
* Important note: This ObservableSource is blocking; you cannot dispose it.
*
* - Scheduler:
* - {@code fromFuture} does not operate by default on a particular {@link Scheduler}.
*
*
* @param future
* the source {@link Future}
* @param timeout
* the maximum time to wait before calling {@code get}
* @param unit
* the {@link TimeUnit} of the {@code timeout} argument
* @param
* the type of object that the {@link Future} returns, and also the type of item to be emitted by
* the resulting ObservableSource
* @return an Observable that emits the item from the source {@link Future}
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromFuture(Future extends T> future, long timeout, TimeUnit unit) {
ObjectHelper.requireNonNull(future, "future is null");
ObjectHelper.requireNonNull(unit, "unit is null");
return RxJavaObservablePlugins.onAssembly(new ObservableFromFuture(future, timeout, unit));
}
/**
* Converts a {@link Future} into an ObservableSource, with a timeout on the Future.
*
*
*
* You can convert any object that supports the {@link Future} interface into an ObservableSource that emits the
* return value of the {@link Future#get} method of that object, by passing the object into the {@code from}
* method.
*
* Unlike 1.x, cancelling the Observable won't cancel the future. If necessary, one can use composition to achieve the
* cancellation effect: {@code futureObservableSource.doOnCancel(() -> future.cancel(true));}.
*
* Important note: This ObservableSource is blocking; you cannot dispose it.
*
* - Scheduler:
* - {@code fromFuture} does not operate by default on a particular {@link Scheduler}.
*
*
* @param future
* the source {@link Future}
* @param timeout
* the maximum time to wait before calling {@code get}
* @param unit
* the {@link TimeUnit} of the {@code timeout} argument
* @param scheduler
* the {@link Scheduler} to wait for the Future on. Use a Scheduler such as
* {@link Schedulers#io()} that can block and wait on the Future
* @param
* the type of object that the {@link Future} returns, and also the type of item to be emitted by
* the resulting ObservableSource
* @return an Observable that emits the item from the source {@link Future}
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.CUSTOM)
public static Observable fromFuture(Future extends T> future, long timeout, TimeUnit unit, Scheduler scheduler) {
ObjectHelper.requireNonNull(scheduler, "scheduler is null");
Observable o = fromFuture(future, timeout, unit);
return o.subscribeOn(scheduler);
}
/**
* Converts a {@link Future}, operating on a specified {@link Scheduler}, into an ObservableSource.
*
*
*
* You can convert any object that supports the {@link Future} interface into an ObservableSource that emits the
* return value of the {@link Future#get} method of that object, by passing the object into the {@code from}
* method.
*
* Unlike 1.x, cancelling the Observable won't cancel the future. If necessary, one can use composition to achieve the
* cancellation effect: {@code futureObservableSource.doOnCancel(() -> future.cancel(true));}.
*
* - Scheduler:
* - You specify which {@link Scheduler} this operator will use
*
*
* @param future
* the source {@link Future}
* @param scheduler
* the {@link Scheduler} to wait for the Future on. Use a Scheduler such as
* {@link Schedulers#io()} that can block and wait on the Future
* @param
* the type of object that the {@link Future} returns, and also the type of item to be emitted by
* the resulting ObservableSource
* @return an Observable that emits the item from the source {@link Future}
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.CUSTOM)
public static Observable fromFuture(Future extends T> future, Scheduler scheduler) {
ObjectHelper.requireNonNull(scheduler, "scheduler is null");
Observable o = fromFuture(future);
return o.subscribeOn(scheduler);
}
/**
* Converts an {@link Iterable} sequence into an ObservableSource that emits the items in the sequence.
*
*
*
* - Scheduler:
* - {@code fromIterable} does not operate by default on a particular {@link Scheduler}.
*
*
* @param source
* the source {@link Iterable} sequence
* @param
* the type of items in the {@link Iterable} sequence and the type of items to be emitted by the
* resulting ObservableSource
* @return an Observable that emits each item in the source {@link Iterable} sequence
* @see ReactiveX operators documentation: From
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable fromIterable(Iterable extends T> source) {
ObjectHelper.requireNonNull(source, "source is null");
return RxJavaObservablePlugins.onAssembly(new ObservableFromIterable(source));
}
/**
* Returns a cold, synchronous and stateless generator of values.
*
*
*
* - Scheduler:
* - {@code generate} does not operate by default on a particular {@link Scheduler}.
*
*
* @param the generated value type
* @param generator the Consumer called whenever a particular downstream Observer has
* requested a value. The callback then should call {@code onNext}, {@code onError} or
* {@code onComplete} to signal a value or a terminal event. Signalling multiple {@code onNext}
* in a call will make the operator signal {@code IllegalStateException}.
* @return the new Observable instance
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static Observable generate(final Consumer> generator) {
ObjectHelper.requireNonNull(generator, "generator is null");
return generate(Functions.