Class Observable<T>
- Type Parameters:
T- the type of the items emitted by theObservable
- All Implemented Interfaces:
ObservableSource<T>
- Direct Known Subclasses:
ConnectableObservable, GroupedObservable, Subject
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 ObservableSource(s), the base reactive interface
for such non-backpressured flows, which Observable itself implements as well.
The Observable's operators, by default, run with a buffer size of 128 elements (see Flowable.bufferSize()),
that can be overridden globally via the system parameter 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
org.reactivestreams.Subscription with Disposable as the primary means to dispose of
a flow.
The Observable follows the protocol
onSubscribe onNext* (onError | onComplete)?
where
the stream can be disposed through the Disposable instance provided to consumers through
Observer.onSubscribe.
Unlike the Observable of version 1.x, subscribe(Observer) does not allow external disposal
of a subscription and the 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();
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <@NonNull T>
@NonNull Observable<T> Mirrors the oneObservableSourcein anIterableof severalObservableSources that first either emits an item or sends a termination notification.static <@NonNull T>
@NonNull Observable<T> ambArray(@NonNull ObservableSource<? extends @NonNull T>... sources) Mirrors the oneObservableSourcein an array of severalObservableSources that first either emits an item or sends a termination notification.final @NonNull Observable<T> ambWith(@NonNull ObservableSource<? extends @NonNull T> other) Mirrors the currentObservableor the otherObservableSourceprovided of which the first either emits an item or sends a termination notification.Returns aSinglethat emitstrueif any item emitted by the currentObservablesatisfies a specified condition, otherwisefalse.final TReturns the first item emitted by the currentObservable, or throwsNoSuchElementExceptionif it emits no items.final TblockingFirst(@NonNull T defaultItem) Returns the first item emitted by the currentObservable, or a default value if it emits no items.final voidblockingForEach(@NonNull Consumer<? super @NonNull T> onNext) Consumes the currentObservablein a blocking fashion and invokes the givenConsumerwith each upstream item on the current thread until the upstream terminates.final voidblockingForEach(@NonNull Consumer<? super @NonNull T> onNext, int capacityHint) Consumes the currentObservablein a blocking fashion and invokes the givenConsumerwith each upstream item on the current thread until the upstream terminates.Exposes the currentObservableas anIterablewhich, when iterated, subscribes to the currentObservableand blocks until the currentObservableemits items or terminates.blockingIterable(int capacityHint) Exposes the currentObservableas anIterablewhich, when iterated, subscribes to the currentObservableand blocks until the currentObservableemits items or terminates.final TReturns the last item emitted by the currentObservable, or throwsNoSuchElementExceptionif the currentObservableemits no items.final TblockingLast(@NonNull T defaultItem) Returns the last item emitted by the currentObservable, or a default value if it emits no items.Returns anIterablethat returns the latest item emitted by the currentObservable, waiting if necessary for one to become available.blockingMostRecent(@NonNull T initialItem) Returns anIterablethat always returns the item most recently emitted by the currentObservable.Returns anIterablethat blocks until the currentObservableemits another item, then returns that item.final TIf the currentObservablecompletes after emitting a single item, return that item, otherwise throw aNoSuchElementException.final TblockingSingle(@NonNull T defaultItem) If the currentObservablecompletes after emitting a single item, return that item; if it emits more than one item, throw anIllegalArgumentException; if it emits no items, return a default value.Creates a sequentialStreamto consume or process the currentObservablein a blocking manner via the JavaStreamAPI.blockingStream(int capacityHint) Creates a sequentialStreamto consume or process the currentObservablein a blocking manner via the JavaStreamAPI.final voidRuns the currentObservableto a terminal event, ignoring any values and rethrowing any exception.final voidblockingSubscribe(@NonNull Observer<? super @NonNull T> observer) Subscribes to the source and calls theObservermethods on the current thread.final voidblockingSubscribe(@NonNull Consumer<? super @NonNull T> onNext) Subscribes to the source and calls the given callbacks on the current thread.final voidblockingSubscribe(@NonNull Consumer<? super @NonNull T> onNext, @NonNull Consumer<? super Throwable> onError) Subscribes to the source and calls the given callbacks on the current thread.final voidblockingSubscribe(@NonNull Consumer<? super @NonNull T> onNext, @NonNull Consumer<? super Throwable> onError, @NonNull Action onComplete) Subscribes to the source and calls the given callbacks on the current thread.final @NonNull Observable<@NonNull List<T>> buffer(int count) Returns anObservablethat emits buffers of items it collects from the currentObservable.final @NonNull Observable<@NonNull List<T>> buffer(int count, int skip) Returns anObservablethat emits buffers of items it collects from the currentObservable.final <@NonNull U extends Collection<? super @NonNull T>>
@NonNull Observable<U> Returns anObservablethat emits buffers of items it collects from the currentObservable.final <@NonNull U extends Collection<? super @NonNull T>>
@NonNull Observable<U> Returns anObservablethat emits buffers of items it collects from the currentObservable.final @NonNull Observable<@NonNull List<T>> Returns anObservablethat emits buffers of items it collects from the currentObservable.final @NonNull Observable<@NonNull List<T>> Returns anObservablethat emits buffers of items it collects from the currentObservable.final <@NonNull U extends Collection<? super @NonNull T>>
@NonNull Observable<U> buffer(long timespan, long timeskip, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, @NonNull Supplier<@NonNull U> bufferSupplier) Returns anObservablethat emits buffers of items it collects from the currentObservable.final @NonNull Observable<@NonNull List<T>> Returns anObservablethat emits buffers of items it collects from the currentObservable.final @NonNull Observable<@NonNull List<T>> Returns anObservablethat emits buffers of items it collects from the currentObservable.final @NonNull Observable<@NonNull List<T>> Returns anObservablethat emits buffers of items it collects from the currentObservable.final @NonNull Observable<@NonNull List<T>> Returns anObservablethat emits buffers of items it collects from the currentObservable.final <@NonNull U extends Collection<? super @NonNull T>>
@NonNull Observable<U> buffer(long timespan, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, int count, @NonNull Supplier<@NonNull U> bufferSupplier, boolean restartTimerOnMaxSize) Returns anObservablethat emits buffers of items it collects from the currentObservable.buffer(@NonNull ObservableSource<? extends @NonNull TOpening> openingIndicator, @NonNull Function<? super @NonNull TOpening, ? extends ObservableSource<? extends @NonNull TClosing>> closingIndicator) Returns anObservablethat emits buffers of items it collects from the currentObservable.final <@NonNull TOpening, @NonNull TClosing, @NonNull U extends Collection<? super @NonNull T>>
@NonNull Observable<U> buffer(@NonNull ObservableSource<? extends @NonNull TOpening> openingIndicator, @NonNull Function<? super @NonNull TOpening, ? extends ObservableSource<? extends @NonNull TClosing>> closingIndicator, @NonNull Supplier<@NonNull U> bufferSupplier) Returns anObservablethat emits buffers of items it collects from the currentObservable.buffer(@NonNull ObservableSource<@NonNull B> boundaryIndicator) Returns anObservablethat emits non-overlapping buffered items from the currentObservableeach time the specified boundaryObservableSourceemits an item.buffer(@NonNull ObservableSource<@NonNull B> boundaryIndicator, int initialCapacity) Returns anObservablethat emits non-overlapping buffered items from the currentObservableeach time the specified boundaryObservableSourceemits an item.final <@NonNull B, @NonNull U extends Collection<? super @NonNull T>>
@NonNull Observable<U> buffer(@NonNull ObservableSource<@NonNull B> boundaryIndicator, @NonNull Supplier<@NonNull U> bufferSupplier) Returns anObservablethat emits non-overlapping buffered items from the currentObservableeach time the specified boundaryObservableSourceemits an item.static intReturns the default 'island' size or capacity-increment hint for unbounded buffers.final @NonNull Observable<T> cache()Returns anObservablethat subscribes to the currentObservablelazily, caches all of its events and replays them, in the same order as received, to all the downstream observers.final @NonNull Observable<T> cacheWithInitialCapacity(int initialCapacity) Returns anObservablethat subscribes to the currentObservablelazily, caches all of its events and replays them, in the same order as received, to all the downstream observers.final <@NonNull U>
@NonNull Observable<U> Returns anObservablethat emits the upstream items while they can be cast viaClass.cast(Object)until the upstream terminates, or until the upstream signals an item which can't be cast, resulting in aClassCastExceptionto be signaled to the downstream.collect(@NonNull Supplier<? extends @NonNull U> initialItemSupplier, @NonNull BiConsumer<? super @NonNull U, ? super @NonNull T> collector) Collects items emitted by the finite sourceObservableinto a single mutable data structure and returns aSinglethat emits this structure.collectInto(@NonNull U initialItem, @NonNull BiConsumer<? super @NonNull U, ? super @NonNull T> collector) Collects items emitted by the finite sourceObservableinto a single mutable data structure and returns aSinglethat emits this structure.static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull T8, @NonNull T9, @NonNull R>
@NonNull Observable<R> combineLatest(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull ObservableSource<? extends @NonNull T7> source7, @NonNull ObservableSource<? extends @NonNull T8> source8, @NonNull ObservableSource<? extends @NonNull T9> source9, @NonNull Function9<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? super @NonNull T8, ? super @NonNull T9, ? extends @NonNull R> combiner) Combines nine sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function.static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull T8, @NonNull R>
@NonNull Observable<R> combineLatest(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull ObservableSource<? extends @NonNull T7> source7, @NonNull ObservableSource<? extends @NonNull T8> source8, @NonNull Function8<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? super @NonNull T8, ? extends @NonNull R> combiner) Combines eight sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function.static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull R>
@NonNull Observable<R> combineLatest(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull ObservableSource<? extends @NonNull T7> source7, @NonNull Function7<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? extends @NonNull R> combiner) Combines seven sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function.static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull R>
@NonNull Observable<R> combineLatest(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull Function6<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? extends @NonNull R> combiner) Combines six sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function.static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull R>
@NonNull Observable<R> combineLatest(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull Function5<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? extends @NonNull R> combiner) Combines five sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function.combineLatest(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull Function4<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? extends @NonNull R> combiner) Combines four sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function.combineLatest(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull Function3<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? extends @NonNull R> combiner) Combines three sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function.static <@NonNull T1, @NonNull T2, @NonNull R>
@NonNull Observable<R> combineLatest(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull BiFunction<? super @NonNull T1, ? super @NonNull T2, ? extends @NonNull R> combiner) Combines two sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from either of theObservableSources, where this aggregation is defined by a specified function.static <@NonNull T, @NonNull R>
@NonNull Observable<R> combineLatest(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, @NonNull Function<? super Object[], ? extends @NonNull R> combiner) Combines a collection of sourceObservableSources by emitting an item that aggregates the latest values of each of the returnedObservableSources each time an item is received from any of the returnedObservableSources, where this aggregation is defined by a specified function.static <@NonNull T, @NonNull R>
@NonNull Observable<R> combineLatest(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, @NonNull Function<? super Object[], ? extends @NonNull R> combiner, int bufferSize) Combines anIterableof sourceObservableSources by emitting an item that aggregates the latest values of each of the returnedObservableSources each time an item is received from any of the returnedObservableSources, where this aggregation is defined by a specified function.static <@NonNull T, @NonNull R>
@NonNull Observable<R> combineLatestArray(@NonNull ObservableSource<? extends @NonNull T>[] sources, @NonNull Function<? super Object[], ? extends @NonNull R> combiner) Combines an array of sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of the returnedObservableSources, where this aggregation is defined by a specified function.static <@NonNull T, @NonNull R>
@NonNull Observable<R> combineLatestArray(@NonNull ObservableSource<? extends @NonNull T>[] sources, @NonNull Function<? super Object[], ? extends @NonNull R> combiner, int bufferSize) Combines an array of sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function.static <@NonNull T, @NonNull R>
@NonNull Observable<R> combineLatestArrayDelayError(@NonNull ObservableSource<? extends @NonNull T>[] sources, @NonNull Function<? super Object[], ? extends @NonNull R> combiner) Combines an array ofObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function.static <@NonNull T, @NonNull R>
@NonNull Observable<R> combineLatestArrayDelayError(@NonNull ObservableSource<? extends @NonNull T>[] sources, @NonNull Function<? super Object[], ? extends @NonNull R> combiner, int bufferSize) Combines an array ofObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function and delays any error from the sources until all sourceObservableSources terminate.static <@NonNull T, @NonNull R>
@NonNull Observable<R> combineLatestDelayError(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, @NonNull Function<? super Object[], ? extends @NonNull R> combiner) Combines anIterableofObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function and delays any error from the sources until all sourceObservableSources terminate.static <@NonNull T, @NonNull R>
@NonNull Observable<R> combineLatestDelayError(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, @NonNull Function<? super Object[], ? extends @NonNull R> combiner, int bufferSize) Combines anIterableofObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function and delays any error from the sources until all sourceObservableSources terminate.final <@NonNull R>
@NonNull Observable<R> Transform the currentObservableby applying a particularObservableTransformerfunction to it.static <@NonNull T>
@NonNull Observable<T> concat(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Returns anObservablethat emits the items emitted by each of theObservableSources emitted by theObservableSource, one after the other, without interleaving them.static <@NonNull T>
@NonNull Observable<T> concat(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int bufferSize) Returns anObservablethat emits the items emitted by each of theObservableSources emitted by the outerObservableSource, one after the other, without interleaving them.static <@NonNull T>
@NonNull Observable<T> concat(@NonNull ObservableSource<? extends @NonNull T> source1, @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull ObservableSource<? extends @NonNull T> source3) Returns anObservablethat emits the items emitted by threeObservableSources, one after the other, without interleaving them.static <@NonNull T>
@NonNull Observable<T> concat(@NonNull ObservableSource<? extends @NonNull T> source1, @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull ObservableSource<? extends @NonNull T> source3, @NonNull ObservableSource<? extends @NonNull T> source4) Returns anObservablethat emits the items emitted by fourObservableSources, one after the other, without interleaving them.static <@NonNull T>
@NonNull Observable<T> concat(@NonNull ObservableSource<? extends @NonNull T> source1, ObservableSource<? extends @NonNull T> source2) Returns anObservablethat emits the items emitted by twoObservableSources, one after the other, without interleaving them.static <@NonNull T>
@NonNull Observable<T> Concatenates elements of eachObservableSourceprovided via anIterablesequence into a single sequence of elements without interleaving them.static <@NonNull T>
@NonNull Observable<T> concatArray(@NonNull ObservableSource<? extends @NonNull T>... sources) Concatenates a variable number ofObservableSourcesources.static <@NonNull T>
@NonNull Observable<T> concatArrayDelayError(@NonNull ObservableSource<? extends @NonNull T>... sources) Concatenates a variable number ofObservableSourcesources and delays errors from any of them till all terminate.static <@NonNull T>
@NonNull Observable<T> concatArrayEager(int maxConcurrency, int bufferSize, @NonNull ObservableSource<? extends @NonNull T>... sources) Concatenates an array ofObservableSources eagerly into a single stream of values.static <@NonNull T>
@NonNull Observable<T> concatArrayEager(@NonNull ObservableSource<? extends @NonNull T>... sources) Concatenates an array ofObservableSources eagerly into a single stream of values.static <@NonNull T>
@NonNull Observable<T> concatArrayEagerDelayError(int maxConcurrency, int bufferSize, @NonNull ObservableSource<? extends @NonNull T>... sources) Concatenates an array ofObservableSources eagerly into a single stream of values and delaying any errors until all sources terminate.static <@NonNull T>
@NonNull Observable<T> concatArrayEagerDelayError(@NonNull ObservableSource<? extends @NonNull T>... sources) Concatenates an array ofObservableSources eagerly into a single stream of values and delaying any errors until all sources terminate.static <@NonNull T>
@NonNull Observable<T> concatDelayError(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Concatenates theObservableSourcesequence ofObservableSources into a singleObservablesequence by subscribing to each innerObservableSource, one after the other, one at a time and delays any errors till the all inner and the outerObservableSources terminate.static <@NonNull T>
@NonNull Observable<T> concatDelayError(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int bufferSize, boolean tillTheEnd) Concatenates theObservableSourcesequence ofObservableSources into a single sequence by subscribing to each innerObservableSource, one after the other, one at a time and delays any errors till the all inner and the outerObservableSources terminate.static <@NonNull T>
@NonNull Observable<T> concatDelayError(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources) Concatenates theIterablesequence ofObservableSources into a singleObservablesequence by subscribing to eachObservableSource, one after the other, one at a time and delays any errors till the all innerObservableSources terminate.static <@NonNull T>
@NonNull Observable<T> concatEager(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Concatenates anObservableSourcesequence ofObservableSources eagerly into a single stream of values.static <@NonNull T>
@NonNull Observable<T> concatEager(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency, int bufferSize) Concatenates anObservableSourcesequence ofObservableSources eagerly into a single stream of values and runs a limited number of inner sequences at once.static <@NonNull T>
@NonNull Observable<T> concatEager(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources) Concatenates a sequence ofObservableSources eagerly into a single stream of values.static <@NonNull T>
@NonNull Observable<T> concatEager(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency, int bufferSize) Concatenates a sequence ofObservableSources eagerly into a single stream of values and runs a limited number of inner sequences at once.static <@NonNull T>
@NonNull Observable<T> concatEagerDelayError(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Concatenates anObservableSourcesequence ofObservableSources eagerly into a single stream of values, delaying errors until all the inner and the outer sequence terminate.static <@NonNull T>
@NonNull Observable<T> concatEagerDelayError(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency, int bufferSize) Concatenates anObservableSourcesequence ofObservableSources 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.static <@NonNull T>
@NonNull Observable<T> concatEagerDelayError(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources) Concatenates a sequence ofObservableSources eagerly into a single stream of values, delaying errors until all the inner sequences terminate.static <@NonNull T>
@NonNull Observable<T> concatEagerDelayError(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency, int bufferSize) Concatenates a sequence ofObservableSources 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.final <@NonNull R>
@NonNull Observable<R> concatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper) Returns a newObservablethat emits items resulting from applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then emitting the items that result from concatenating those returnedObservableSources.final <@NonNull R>
@NonNull Observable<R> concatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, int bufferSize) Returns a newObservablethat emits items resulting from applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then emitting the items that result from concatenating those returnedObservableSources.final <@NonNull R>
@NonNull Observable<R> concatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, int bufferSize, @NonNull Scheduler scheduler) Returns a newObservablethat emits items resulting from applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then emitting the items that result from concatenating those returnedObservableSources.final @NonNull CompletableconcatMapCompletable(@NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Maps each element of the currentObservableintoCompletableSources, subscribes to them one at a time in order and waits until the upstream and allCompletableSources complete.final @NonNull CompletableconcatMapCompletable(@NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper, int capacityHint) Maps each element of the currentObservableintoCompletableSources, subscribes to them one at a time in order and waits until the upstream and allCompletableSources complete.final @NonNull CompletableconcatMapCompletableDelayError(@NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Maps the upstream items intoCompletableSources and subscribes to them one after the other terminates, delaying all errors till both the currentObservableand all innerCompletableSources terminate.final @NonNull CompletableconcatMapCompletableDelayError(@NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper, boolean tillTheEnd) Maps the upstream items intoCompletableSources and subscribes to them one after the other terminates, optionally delaying all errors till both the currentObservableand all innerCompletableSources terminate.final @NonNull CompletableconcatMapCompletableDelayError(@NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper, boolean tillTheEnd, int bufferSize) Maps the upstream items intoCompletableSources and subscribes to them one after the other terminates, optionally delaying all errors till both the currentObservableand all innerCompletableSources terminate.final <@NonNull R>
@NonNull Observable<R> concatMapDelayError(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper) Maps each of the items into anObservableSource, subscribes to them one after the other, one at a time and emits their values in order while delaying any error from either this or any of the innerObservableSources till all of them terminate.final <@NonNull R>
@NonNull Observable<R> concatMapDelayError(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean tillTheEnd, int bufferSize) Maps each of the items into anObservableSource, subscribes to them one after the other, one at a time and emits their values in order while delaying any error from either this or any of the innerObservableSources till all of them terminate.final <@NonNull R>
@NonNull Observable<R> concatMapDelayError(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean tillTheEnd, int bufferSize, @NonNull Scheduler scheduler) Maps each of the items into anObservableSource, subscribes to them one after the other, one at a time and emits their values in order while delaying any error from either this or any of the innerObservableSources till all of them terminate.final <@NonNull R>
@NonNull Observable<R> concatMapEager(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper) Maps a sequence of values intoObservableSources and concatenates theseObservableSources eagerly into a singleObservablesequence.final <@NonNull R>
@NonNull Observable<R> concatMapEager(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, int maxConcurrency, int bufferSize) Maps a sequence of values intoObservableSources and concatenates theseObservableSources eagerly into a singleObservablesequence.final <@NonNull R>
@NonNull Observable<R> concatMapEagerDelayError(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean tillTheEnd) Maps a sequence of values intoObservableSources and concatenates theseObservableSources eagerly into a singleObservablesequence.final <@NonNull R>
@NonNull Observable<R> concatMapEagerDelayError(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean tillTheEnd, int maxConcurrency, int bufferSize) Maps a sequence of values intoObservableSources and concatenates theseObservableSources eagerly into a singleObservablesequence.final <@NonNull U>
@NonNull Observable<U> concatMapIterable(@NonNull Function<? super @NonNull T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper) Returns anObservablethat concatenate each item emitted by the currentObservablewith the values in anIterablecorresponding to that item that is generated by a selector.final <@NonNull R>
@NonNull Observable<R> concatMapMaybe(@NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper) Maps the upstream items intoMaybeSources and subscribes to them one after the other succeeds or completes, emits their success value if available or terminates immediately if either the currentObservableor the current innerMaybeSourcefail.final <@NonNull R>
@NonNull Observable<R> concatMapMaybe(@NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper, int bufferSize) Maps the upstream items intoMaybeSources and subscribes to them one after the other succeeds or completes, emits their success value if available or terminates immediately if either the currentObservableor the current innerMaybeSourcefail.final <@NonNull R>
@NonNull Observable<R> concatMapMaybeDelayError(@NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper) Maps the upstream items intoMaybeSources and subscribes to them one after the other terminates, emits their success value if available and delaying all errors till both the currentObservableand all innerMaybeSources terminate.final <@NonNull R>
@NonNull Observable<R> concatMapMaybeDelayError(@NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper, boolean tillTheEnd) Maps the upstream items intoMaybeSources and subscribes to them one after the other terminates, emits their success value if available and optionally delaying all errors till both the currentObservableand all innerMaybeSources terminate.final <@NonNull R>
@NonNull Observable<R> concatMapMaybeDelayError(@NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper, boolean tillTheEnd, int bufferSize) Maps the upstream items intoMaybeSources and subscribes to them one after the other terminates, emits their success value if available and optionally delaying all errors till both the currentObservableand all innerMaybeSources terminate.final <@NonNull R>
@NonNull Observable<R> concatMapSingle(@NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Maps the upstream items intoSingleSources and subscribes to them one after the other succeeds, emits their success values or terminates immediately if either the currentObservableor the current innerSingleSourcefail.final <@NonNull R>
@NonNull Observable<R> concatMapSingle(@NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper, int bufferSize) Maps the upstream items intoSingleSources and subscribes to them one after the other succeeds, emits their success values or terminates immediately if either the currentObservableor the current innerSingleSourcefail.final <@NonNull R>
@NonNull Observable<R> concatMapSingleDelayError(@NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Maps the upstream items intoSingleSources and subscribes to them one after the other succeeds or fails, emits their success values and delays all errors till both the currentObservableand all innerSingleSources terminate.final <@NonNull R>
@NonNull Observable<R> concatMapSingleDelayError(@NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper, boolean tillTheEnd) Maps the upstream items intoSingleSources and subscribes to them one after the other succeeds or fails, emits their success values and optionally delays all errors till both the currentObservableand all innerSingleSources terminate.final <@NonNull R>
@NonNull Observable<R> concatMapSingleDelayError(@NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper, boolean tillTheEnd, int bufferSize) Maps the upstream items intoSingleSources and subscribes to them one after the other succeeds or fails, emits their success values and optionally delays errors till both the currentObservableand all innerSingleSources terminate.final <@NonNull R>
@NonNull Observable<R> concatMapStream(@NonNull Function<? super @NonNull T, @NonNull ? extends Stream<? extends @NonNull R>> mapper) Maps each upstream item into aStreamand emits theStream's items to the downstream in a sequential fashion.final @NonNull Observable<T> concatWith(@NonNull CompletableSource other) Returns anObservablethat emits items from the currentObservableand when it completes normally, the otherCompletableSourceis subscribed to and the returnedObservableemits its terminal events.final @NonNull Observable<T> concatWith(@NonNull MaybeSource<? extends @NonNull T> other) Returns anObservablethat emits the items from the currentObservablefollowed by the success item or terminal events of the otherMaybeSource.final @NonNull Observable<T> concatWith(@NonNull ObservableSource<? extends @NonNull T> other) Returns anObservablethat first emits the items emitted from the currentObservable, then items from theotherObservableSourcewithout interleaving them.final @NonNull Observable<T> concatWith(@NonNull SingleSource<? extends @NonNull T> other) Returns anObservablethat emits the items from the currentObservablefollowed by the success item or error event of theotherSingleSource.count()static <@NonNull T>
@NonNull Observable<T> create(@NonNull ObservableOnSubscribe<@NonNull T> source) Provides an API (via a coldObservable) that bridges the reactive world with the callback-style world.final @NonNull Observable<T> Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by newer items before a timeout value expires.final @NonNull Observable<T> Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by newer items before a timeout value expires on a specifiedScheduler.final @NonNull Observable<T> debounce(long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, @NonNull Consumer<? super @NonNull T> onDropped) Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by newer items before a timeout value expires on a specifiedScheduler.final <@NonNull U>
@NonNull Observable<T> debounce(@NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull U>> debounceIndicator) Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by another item within a computed debounce duration denoted by an item emission or completion from a generated innerObservableSourcefor that original item.final @NonNull Observable<T> defaultIfEmpty(@NonNull T defaultItem) Returns anObservablethat emits the items emitted by the currentObservableor a specified default item if the currentObservableis empty.static <@NonNull T>
@NonNull Observable<T> Returns anObservablethat calls anObservableSourcefactory to create anObservableSourcefor each newObserverthat subscribes.final @NonNull Observable<T> Returns anObservablethat emits the items emitted by the currentObservableshifted forward in time by a specified delay.final @NonNull Observable<T> Returns anObservablethat emits the items emitted by the currentObservableshifted forward in time by a specified delay.final @NonNull Observable<T> Returns anObservablethat emits the items emitted by the currentObservableshifted forward in time by a specified delay.final @NonNull Observable<T> Returns anObservablethat emits the items emitted by the currentObservableshifted forward in time by a specified delay.final <@NonNull U, @NonNull V>
@NonNull Observable<T> delay(@NonNull ObservableSource<@NonNull U> subscriptionIndicator, @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull V>> itemDelayIndicator) Returns anObservablethat delays the subscription to and emissions from the currentObservableviaObservableSources for the subscription itself and on a per-item basis.final <@NonNull U>
@NonNull Observable<T> delay(@NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull U>> itemDelayIndicator) Returns anObservablethat delays the emissions of the currentObservablevia a per-item derivedObservableSource's item emission or termination, on a per source item basis.final @NonNull Observable<T> delaySubscription(long time, @NonNull TimeUnit unit) Returns anObservablethat delays the subscription to the currentObservableby a given amount of time.final @NonNull Observable<T> delaySubscription(long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler) Returns anObservablethat delays the subscription to the currentObservableby a given amount of time, both waiting and subscribing on a givenScheduler.final <@NonNull U>
@NonNull Observable<T> delaySubscription(@NonNull ObservableSource<@NonNull U> subscriptionIndicator) Returns anObservablethat delays the subscription to the currentObservableuntil the otherObservableSourceemits an element or completes normally.final <@NonNull R>
@NonNull Observable<R> dematerialize(@NonNull Function<? super @NonNull T, Notification<@NonNull R>> selector) Returns anObservablethat reverses the effect ofmaterializeby transforming theNotificationobjects extracted from the source items via a selector function into their respectiveObserversignal types.final @NonNull Observable<T> distinct()Returns anObservablethat emits all items emitted by the currentObservablethat are distinct based onObject.equals(Object)comparison.final <@NonNull K>
@NonNull Observable<T> Returns anObservablethat emits all items emitted by the currentObservablethat are distinct according to a key selector function and based onObject.equals(Object)comparison of the objects returned by the key selector function.final <@NonNull K>
@NonNull Observable<T> distinct(@NonNull Function<? super @NonNull T, @NonNull K> keySelector, @NonNull Supplier<? extends Collection<? super @NonNull K>> collectionSupplier) Returns anObservablethat emits all items emitted by the currentObservablethat are distinct according to a key selector function and based onObject.equals(Object)comparison of the objects returned by the key selector function.final @NonNull Observable<T> Returns anObservablethat emits all items emitted by the currentObservablethat are distinct from their immediate predecessors based onObject.equals(Object)comparison.final @NonNull Observable<T> distinctUntilChanged(@NonNull BiPredicate<? super @NonNull T, ? super @NonNull T> comparer) Returns anObservablethat emits all items emitted by the currentObservablethat are distinct from their immediate predecessors when compared with each other via the provided comparator function.final <@NonNull K>
@NonNull Observable<T> Returns anObservablethat emits all items emitted by the currentObservablethat are distinct from their immediate predecessors, according to a key selector function and based onObject.equals(Object)comparison of those objects returned by the key selector function.final @NonNull Observable<T> doAfterNext(@NonNull Consumer<? super @NonNull T> onAfterNext) Calls the specifiedConsumerwith the current item after this item has been emitted to the downstream.final @NonNull Observable<T> doAfterTerminate(@NonNull Action onAfterTerminate) final @NonNull Observable<T> Calls the specified action after the currentObservablesignalsonErrororonCompletedor gets disposed by the downstream.final @NonNull Observable<T> doOnComplete(@NonNull Action onComplete) final @NonNull Observable<T> doOnDispose(@NonNull Action onDispose) Calls the given sharedActionif the downstream disposes the sequence.final @NonNull Observable<T> Returns anObservablethat forwards the items and terminal events of the currentObservableto itsObservers and to the given sharedObserverinstance.final @NonNull Observable<T> Returns anObservablethat invokes aConsumerwith the appropriateNotificationobject when the currentObservablesignals an item or terminates.final @NonNull Observable<T> final @NonNull Observable<T> doOnLifecycle(@NonNull Consumer<? super Disposable> onSubscribe, @NonNull Action onDispose) Calls the appropriateonXXXmethod (shared between allObservers) for the lifecycle events of the sequence (subscription, disposal).final @NonNull Observable<T> Calls the givenConsumerwith the value emitted by the currentObservablebefore forwarding it to the downstream.final @NonNull Observable<T> doOnSubscribe(@NonNull Consumer<? super Disposable> onSubscribe) final @NonNull Observable<T> doOnTerminate(@NonNull Action onTerminate) Returns anObservableso that it invokes an action when the currentObservablecallsonCompleteoronError.elementAt(long index) Returns aMaybethat emits the single item at a specified index in a sequence of emissions from the currentObservableor completes if the currentObservablesignals fewer elements than index.Returns aSinglethat emits the item found at a specified index in a sequence of emissions from the currentObservable, or a default item if that index is out of range.elementAtOrError(long index) Returns aSinglethat emits the item found at a specified index in a sequence of emissions from the currentObservableor signals aNoSuchElementExceptionif the currentObservablesignals fewer elements than index.static <@NonNull T>
@NonNull Observable<T> empty()Returns anObservablethat emits no items to theObserverand immediately invokes itsonCompletemethod.static <@NonNull T>
@NonNull Observable<T> static <@NonNull T>
@NonNull Observable<T> final @NonNull Observable<T> Filters items emitted by the currentObservableby only emitting those that satisfy a specifiedPredicate.Returns aSinglethat emits only the very first item emitted by the currentObservable, or a default item if the currentObservablecompletes without emitting any items.Returns aMaybethat emits only the very first item emitted by the currentObservable, or completes if the currentObservableis empty.Returns aSinglethat emits only the very first item emitted by the currentObservableor signals aNoSuchElementExceptionif the currentObservableis empty.final @NonNull CompletionStage<T> Signals the first upstream item or aNoSuchElementExceptionif the upstream is empty via aCompletionStage.final @NonNull CompletionStage<T> firstStage(@NonNull T defaultItem) Signals the first upstream item (or the default item if the upstream is empty) via aCompletionStage.final <@NonNull R>
@NonNull Observable<R> flatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper) Returns anObservablethat emits items based on applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then merging those returnedObservableSources and emitting the results of this merger.final <@NonNull R>
@NonNull Observable<R> flatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean delayErrors) Returns anObservablethat emits items based on applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then merging those returnedObservableSources and emitting the results of this merger.final <@NonNull R>
@NonNull Observable<R> flatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean delayErrors, int maxConcurrency) Returns anObservablethat emits items based on applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then merging those returnedObservableSources and emitting the results of this merger, while limiting the maximum number of concurrent subscriptions to theseObservableSources.final <@NonNull R>
@NonNull Observable<R> flatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean delayErrors, int maxConcurrency, int bufferSize) Returns anObservablethat emits items based on applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then merging those returnedObservableSources and emitting the results of this merger, while limiting the maximum number of concurrent subscriptions to theseObservableSources.final <@NonNull R>
@NonNull Observable<R> flatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, int maxConcurrency) Returns anObservablethat emits items based on applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then merging those returnedObservableSources and emitting the results of this merger, while limiting the maximum number of concurrent subscriptions to theseObservableSources.final <@NonNull R>
@NonNull Observable<R> flatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> onNextMapper, @NonNull Function<? super Throwable, ? extends ObservableSource<? extends @NonNull R>> onErrorMapper, @NonNull Supplier<? extends ObservableSource<? extends @NonNull R>> onCompleteSupplier) Returns anObservablethat applies a function to each item emitted or notification raised by the currentObservableand then flattens theObservableSources returned from these functions and emits the resulting items.final <@NonNull R>
@NonNull Observable<R> flatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> onNextMapper, @NonNull Function<Throwable, ? extends ObservableSource<? extends @NonNull R>> onErrorMapper, @NonNull Supplier<? extends ObservableSource<? extends @NonNull R>> onCompleteSupplier, int maxConcurrency) Returns anObservablethat applies a function to each item emitted or notification raised by the currentObservableand then flattens theObservableSources returned from these functions and emits the resulting items, while limiting the maximum number of concurrent subscriptions to theseObservableSources.final <@NonNull U, @NonNull R>
@NonNull Observable<R> flatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull U>> mapper, @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> combiner) Returns anObservablethat emits the results of a specified function to the pair of values emitted by the currentObservableand the mapped innerObservableSource.final <@NonNull U, @NonNull R>
@NonNull Observable<R> flatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull U>> mapper, @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> combiner, boolean delayErrors) Returns anObservablethat emits the results of a specified function to the pair of values emitted by the currentObservableand the mapped innerObservableSource.final <@NonNull U, @NonNull R>
@NonNull Observable<R> flatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull U>> mapper, @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> combiner, boolean delayErrors, int maxConcurrency) Returns anObservablethat emits the results of a specified function to the pair of values emitted by the currentObservableand the mapped innerObservableSource, while limiting the maximum number of concurrent subscriptions to theseObservableSources.final <@NonNull U, @NonNull R>
@NonNull Observable<R> flatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull U>> mapper, @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> combiner, boolean delayErrors, int maxConcurrency, int bufferSize) Returns anObservablethat emits the results of a specified function to the pair of values emitted by the currentObservableand the mapped innerObservableSource, while limiting the maximum number of concurrent subscriptions to theseObservableSources.final <@NonNull U, @NonNull R>
@NonNull Observable<R> flatMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull U>> mapper, @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> combiner, int maxConcurrency) Returns anObservablethat emits the results of a specified function to the pair of values emitted by the currentObservableand the mapped innerObservableSource, while limiting the maximum number of concurrent subscriptions to theseObservableSources.final @NonNull CompletableflatMapCompletable(@NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Maps each element of the currentObservableintoCompletableSources, subscribes to them and waits until the upstream and allCompletableSources complete.final @NonNull CompletableflatMapCompletable(@NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper, boolean delayErrors) Maps each element of the currentObservableintoCompletableSources, subscribes to them and waits until the upstream and allCompletableSources complete, optionally delaying all errors.final <@NonNull U>
@NonNull Observable<U> flatMapIterable(@NonNull Function<? super @NonNull T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper) final <@NonNull U, @NonNull V>
@NonNull Observable<V> flatMapIterable(@NonNull Function<? super @NonNull T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper, @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull V> combiner) MergesIterables generated by a mapperFunctionfor each individual item emitted by the currentObservableinto a singleObservablesequence where the resulting items will be the combination of the original item and each inner item of the respectiveIterableas returned by theresultSelectorBiFunction.final <@NonNull R>
@NonNull Observable<R> flatMapMaybe(@NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper) Maps each element of the currentObservableintoMaybeSources, subscribes to all of them and merges theironSuccessvalues, in no particular order, into a singleObservablesequence.final <@NonNull R>
@NonNull Observable<R> flatMapMaybe(@NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper, boolean delayErrors) Maps each element of the currentObservableintoMaybeSources, subscribes to them and merges theironSuccessvalues, in no particular order, into a singleObservablesequence, optionally delaying all errors.final <@NonNull R>
@NonNull Observable<R> flatMapSingle(@NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Maps each element of the currentObservableintoSingleSources, subscribes to all of them and merges theironSuccessvalues, in no particular order, into a singleObservablesequence.final <@NonNull R>
@NonNull Observable<R> flatMapSingle(@NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper, boolean delayErrors) Maps each element of the currentObservableintoSingleSources, subscribes to them and merges theironSuccessvalues, in no particular order, into a singleObservablesequence, optionally delaying all errors.final <@NonNull R>
@NonNull Observable<R> flatMapStream(@NonNull Function<? super @NonNull T, @NonNull ? extends Stream<? extends @NonNull R>> mapper) Maps each upstream item into aStreamand emits theStream's items to the downstream in a sequential fashion.final @NonNull DisposableSubscribes to theObservableSourceand calls aConsumerfor each item of the currentObservableon its emission thread.final @NonNull DisposableforEachWhile(@NonNull Predicate<? super @NonNull T> onNext) Subscribes to theObservableSourceand calls aPredicatefor each item of the currentObservable, on its emission thread, until the predicate returnsfalse.final @NonNull DisposableforEachWhile(@NonNull Predicate<? super @NonNull T> onNext, @NonNull Consumer<? super Throwable> onError) Subscribes to theObservableSourceand calls aPredicatefor each item or aConsumerwith the error of the currentObservable, on their original emission threads, until the predicate returnsfalse.final @NonNull DisposableforEachWhile(@NonNull Predicate<? super @NonNull T> onNext, @NonNull Consumer<? super Throwable> onError, @NonNull Action onComplete) Subscribes to theObservableSourceand calls aPredicatefor each item, aConsumerwith the error or anActionupon completion of the currentObservable, on their original emission threads, until the predicate returnsfalse.static <@NonNull T>
@NonNull Observable<T> fromAction(@NonNull Action action) static <@NonNull T>
@NonNull Observable<T> Converts an array into anObservableSourcethat emits the items in the array.static <@NonNull T>
@NonNull Observable<T> fromCallable(@NonNull Callable<? extends @NonNull T> callable) Returns anObservablethat, when an observer subscribes to it, invokes a function you specify and then emits the value returned from that function.static <@NonNull T>
@NonNull Observable<T> fromCompletable(@NonNull CompletableSource completableSource) Wraps aCompletableSourceinto anObservable.static <@NonNull T>
@NonNull Observable<@NonNull T> fromCompletionStage(@NonNull CompletionStage<@NonNull T> stage) Signals the completion value or error of the given (hot)CompletionStage-based asynchronous calculation.static <@NonNull T>
@NonNull Observable<T> fromFuture(@NonNull Future<? extends @NonNull T> future) Converts aFutureinto anObservable.static <@NonNull T>
@NonNull Observable<T> static <@NonNull T>
@NonNull Observable<T> fromIterable(@NonNull Iterable<? extends @NonNull T> source) Converts anIterablesequence into anObservablethat emits the items in the sequence.static <@NonNull T>
@NonNull Observable<T> fromMaybe(@NonNull MaybeSource<@NonNull T> maybe) Returns anObservableinstance that when subscribed to, subscribes to theMaybeSourceinstance and emitsonSuccessas a single item or forwards anyonCompleteoronErrorsignal.static <@NonNull T>
@NonNull Observable<@NonNull T> fromOptional(@NonNull Optional<@NonNull T> optional) Converts the existing value of the provided optional into ajust(Object)or an empty optional into anempty()Observableinstance.static <@NonNull T>
@NonNull Observable<T> fromPublisher(@NonNull Flow.Publisher<? extends @NonNull T> publisher) Converts an arbitrary Reactive StreamsFlow.Publisherinto anObservable.static <@NonNull T>
@NonNull Observable<T> fromRunnable(@NonNull Runnable run) static <@NonNull T>
@NonNull Observable<T> fromSingle(@NonNull SingleSource<@NonNull T> source) Returns anObservableinstance that when subscribed to, subscribes to theSingleSourceinstance and emitsonSuccessas a single item or forwards theonErrorsignal.static <@NonNull T>
@NonNull Observable<@NonNull T> fromStream(@NonNull Stream<@NonNull T> stream) Converts aStreaminto a finiteObservableand emits its items in the sequence.static <@NonNull T>
@NonNull Observable<T> fromSupplier(@NonNull Supplier<? extends @NonNull T> supplier) Returns anObservablethat, when an observer subscribes to it, invokes a supplier function you specify and then emits the value returned from that function.static <@NonNull T>
@NonNull Observable<T> Returns a cold, synchronous and stateless generator of values.static <@NonNull T, @NonNull S>
@NonNull Observable<T> generate(@NonNull Supplier<@NonNull S> initialState, @NonNull BiConsumer<@NonNull S, Emitter<@NonNull T>> generator) Returns a cold, synchronous and stateful generator of values.static <@NonNull T, @NonNull S>
@NonNull Observable<T> generate(@NonNull Supplier<@NonNull S> initialState, @NonNull BiConsumer<@NonNull S, Emitter<@NonNull T>> generator, @NonNull Consumer<? super @NonNull S> disposeState) Returns a cold, synchronous and stateful generator of values.static <@NonNull T, @NonNull S>
@NonNull Observable<T> generate(@NonNull Supplier<@NonNull S> initialState, @NonNull BiFunction<@NonNull S, Emitter<@NonNull T>, @NonNull S> generator) Returns a cold, synchronous and stateful generator of values.static <@NonNull T, @NonNull S>
@NonNull Observable<T> generate(@NonNull Supplier<@NonNull S> initialState, @NonNull BiFunction<@NonNull S, Emitter<@NonNull T>, @NonNull S> generator, @NonNull Consumer<? super @NonNull S> disposeState) Returns a cold, synchronous and stateful generator of values.final <@NonNull K>
@NonNull Observable<GroupedObservable<K, T>> Groups the items emitted by the currentObservableaccording to a specified criterion, and emits these grouped items asGroupedObservables.final <@NonNull K>
@NonNull Observable<GroupedObservable<K, T>> groupBy(@NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, boolean delayError) Groups the items emitted by the currentObservableaccording to a specified criterion, and emits these grouped items asGroupedObservables.final <@NonNull K, @NonNull V>
@NonNull Observable<GroupedObservable<K, V>> groupBy(@NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, @NonNull Function<? super @NonNull T, ? extends @NonNull V> valueSelector, boolean delayError) Groups the items emitted by the currentObservableaccording to a specified criterion, and emits these grouped items asGroupedObservables.final <@NonNull K, @NonNull V>
@NonNull Observable<GroupedObservable<K, V>> groupBy(@NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, @NonNull Function<? super @NonNull T, ? extends @NonNull V> valueSelector, boolean delayError, int bufferSize) Groups the items emitted by the currentObservableaccording to a specified criterion, and emits these grouped items asGroupedObservables.final <@NonNull K, @NonNull V>
@NonNull Observable<GroupedObservable<K, V>> groupBy(@NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, Function<? super @NonNull T, ? extends @NonNull V> valueSelector) Groups the items emitted by the currentObservableaccording to a specified criterion, and emits these grouped items asGroupedObservables.groupJoin(@NonNull ObservableSource<? extends @NonNull TRight> other, @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull TLeftEnd>> leftEnd, @NonNull Function<? super @NonNull TRight, ? extends ObservableSource<@NonNull TRightEnd>> rightEnd, @NonNull BiFunction<? super @NonNull T, ? super Observable<@NonNull TRight>, ? extends @NonNull R> resultSelector) Returns anObservablethat correlates twoObservableSources when they overlap in time and groups the results.final @NonNull Observable<T> hide()Hides the identity of the currentObservableand itsDisposable.final @NonNull CompletableIgnores all items emitted by the currentObservableand only callsonCompleteoronError.static @NonNull Observable<Long> Returns anObservablethat emits a0Lafter theinitialDelayand ever increasing numbers after eachperiodof time thereafter.static @NonNull Observable<Long> Returns anObservablethat emits a0Lafter theinitialDelayand ever increasing numbers after eachperiodof time thereafter, on a specifiedScheduler.static @NonNull Observable<Long> Returns anObservablethat emits a sequential number every specified interval of time.static @NonNull Observable<Long> Returns anObservablethat emits a sequential number every specified interval of time, on a specifiedScheduler.static @NonNull Observable<Long> intervalRange(long start, long count, long initialDelay, long period, @NonNull TimeUnit unit) Signals a range of long values, the first after some initial delay and the rest periodically after.static @NonNull Observable<Long> intervalRange(long start, long count, long initialDelay, long period, @NonNull TimeUnit unit, @NonNull Scheduler scheduler) Signals a range of long values, the first after some initial delay and the rest periodically after.isEmpty()join(@NonNull ObservableSource<? extends @NonNull TRight> other, @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull TLeftEnd>> leftEnd, @NonNull Function<? super @NonNull TRight, ? extends ObservableSource<@NonNull TRightEnd>> rightEnd, @NonNull BiFunction<? super @NonNull T, ? super @NonNull TRight, ? extends @NonNull R> resultSelector) Correlates the items emitted by twoObservableSources based on overlapping durations.static <@NonNull T>
@NonNull Observable<T> Returns anObservablethat signals the given (constant reference) item and then completes.static <@NonNull T>
@NonNull Observable<T> Converts two items into anObservablethat emits those items.static <@NonNull T>
@NonNull Observable<T> Converts three items into anObservablethat emits those items.static <@NonNull T>
@NonNull Observable<T> Converts four items into anObservablethat emits those items.static <@NonNull T>
@NonNull Observable<T> Converts five items into anObservablethat emits those items.static <@NonNull T>
@NonNull Observable<T> just(@NonNull T item1, @NonNull T item2, @NonNull T item3, @NonNull T item4, @NonNull T item5, @NonNull T item6) Converts six items into anObservablethat emits those items.static <@NonNull T>
@NonNull Observable<T> just(@NonNull T item1, @NonNull T item2, @NonNull T item3, @NonNull T item4, @NonNull T item5, @NonNull T item6, @NonNull T item7) Converts seven items into anObservablethat emits those items.static <@NonNull T>
@NonNull Observable<T> just(@NonNull T item1, @NonNull T item2, @NonNull T item3, @NonNull T item4, @NonNull T item5, @NonNull T item6, @NonNull T item7, @NonNull T item8) Converts eight items into anObservablethat emits those items.static <@NonNull T>
@NonNull Observable<T> just(@NonNull T item1, @NonNull T item2, @NonNull T item3, @NonNull T item4, @NonNull T item5, @NonNull T item6, @NonNull T item7, @NonNull T item8, @NonNull T item9) Converts nine items into anObservablethat emits those items.static <@NonNull T>
@NonNull Observable<T> just(@NonNull T item1, @NonNull T item2, @NonNull T item3, @NonNull T item4, @NonNull T item5, @NonNull T item6, @NonNull T item7, @NonNull T item8, @NonNull T item9, @NonNull T item10) Converts ten items into anObservablethat emits those items.Returns aSinglethat emits only the last item emitted by the currentObservable, or a default item if the currentObservablecompletes without emitting any items.Returns aMaybethat emits the last item emitted by the currentObservableor completes if the currentObservableis empty.Returns aSinglethat emits only the last item emitted by the currentObservableor signals aNoSuchElementExceptionif the currentObservableis empty.final @NonNull CompletionStage<T> Signals the last upstream item or aNoSuchElementExceptionif the upstream is empty via aCompletionStage.final @NonNull CompletionStage<T> Signals the last upstream item (or the default item if the upstream is empty) via aCompletionStage.final <@NonNull R>
@NonNull Observable<R> This method requires advanced knowledge about building operators, please consider other standard composition methods first; Returns anObservablewhich, when subscribed to, invokes theapply(Observer)method of the providedObservableOperatorfor each individual downstreamObserverand allows the insertion of a custom operator by accessing the downstream'sObserverduring this subscription phase and providing a newObserver, containing the custom operator's intended business logic, that will be used in the subscription process going further upstream.final <@NonNull R>
@NonNull Observable<R> Returns anObservablethat applies a specified function to each item emitted by the currentObservableand emits the results of these function applications.final <@NonNull R>
@NonNull Observable<R> Maps each upstream value into anOptionaland emits the contained item if not empty.final @NonNull Observable<Notification<T>> Returns anObservablethat represents all of the emissions and notifications from the currentObservableinto emissions marked with their original types withinNotificationobjects.static <@NonNull T>
@NonNull Observable<T> merge(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Flattens anObservableSourcethat emitsObservableSources into a singleObservablethat emits the items emitted by thoseObservableSources, without any transformation.static <@NonNull T>
@NonNull Observable<T> merge(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency) Flattens anObservableSourcethat emitsObservableSources into a singleObservablethat emits the items emitted by thoseObservableSources, without any transformation, while limiting the maximum number of concurrent subscriptions to theseObservableSources.static <@NonNull T>
@NonNull Observable<T> merge(@NonNull ObservableSource<? extends @NonNull T> source1, @NonNull ObservableSource<? extends @NonNull T> source2) Flattens twoObservableSources into a singleObservable, without any transformation.static <@NonNull T>
@NonNull Observable<T> merge(@NonNull ObservableSource<? extends @NonNull T> source1, @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull ObservableSource<? extends @NonNull T> source3) Flattens threeObservableSources into a singleObservable, without any transformation.static <@NonNull T>
@NonNull Observable<T> merge(@NonNull ObservableSource<? extends @NonNull T> source1, @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull ObservableSource<? extends @NonNull T> source3, @NonNull ObservableSource<? extends @NonNull T> source4) Flattens fourObservableSources into a singleObservable, without any transformation.static <@NonNull T>
@NonNull Observable<T> static <@NonNull T>
@NonNull Observable<T> merge(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency) Flattens anIterableofObservableSources into oneObservable, without any transformation, while limiting the number of concurrent subscriptions to theseObservableSources.static <@NonNull T>
@NonNull Observable<T> merge(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency, int bufferSize) Flattens anIterableofObservableSources into oneObservable, without any transformation, while limiting the number of concurrent subscriptions to theseObservableSources.static <@NonNull T>
@NonNull Observable<T> mergeArray(int maxConcurrency, int bufferSize, @NonNull ObservableSource<? extends @NonNull T>... sources) Flattens an array ofObservableSources into oneObservable, without any transformation, while limiting the number of concurrent subscriptions to theseObservableSources.static <@NonNull T>
@NonNull Observable<T> mergeArray(@NonNull ObservableSource<? extends @NonNull T>... sources) Flattens an array ofObservableSources into oneObservable, without any transformation.static <@NonNull T>
@NonNull Observable<T> mergeArrayDelayError(int maxConcurrency, int bufferSize, @NonNull ObservableSource<? extends @NonNull T>... sources) Flattens an array ofObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from each of theObservableSources without being interrupted by an error notification from one of them, while limiting the number of concurrent subscriptions to theseObservableSources.static <@NonNull T>
@NonNull Observable<T> mergeArrayDelayError(@NonNull ObservableSource<? extends @NonNull T>... sources) Flattens an array ofObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from each of theObservableSources without being interrupted by an error notification from one of them.static <@NonNull T>
@NonNull Observable<T> mergeDelayError(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Flattens anObservableSourcethat emitsObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from all of the emittedObservableSources without being interrupted by an error notification from one of them.static <@NonNull T>
@NonNull Observable<T> mergeDelayError(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency) Flattens anObservableSourcethat emitsObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from all of the emittedObservableSources without being interrupted by an error notification from one of them, while limiting the number of concurrent subscriptions to theseObservableSources.static <@NonNull T>
@NonNull Observable<T> mergeDelayError(@NonNull ObservableSource<? extends @NonNull T> source1, @NonNull ObservableSource<? extends @NonNull T> source2) Flattens twoObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from each of theObservableSources without being interrupted by an error notification from one of them.static <@NonNull T>
@NonNull Observable<T> mergeDelayError(@NonNull ObservableSource<? extends @NonNull T> source1, @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull ObservableSource<? extends @NonNull T> source3) Flattens threeObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from all of theObservableSources without being interrupted by an error notification from one of them.static <@NonNull T>
@NonNull Observable<T> mergeDelayError(@NonNull ObservableSource<? extends @NonNull T> source1, @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull ObservableSource<? extends @NonNull T> source3, @NonNull ObservableSource<? extends @NonNull T> source4) Flattens fourObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from all of theObservableSources without being interrupted by an error notification from one of them.static <@NonNull T>
@NonNull Observable<T> mergeDelayError(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources) Flattens anIterableofObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from each of the returnedObservableSources without being interrupted by an error notification from one of them.static <@NonNull T>
@NonNull Observable<T> mergeDelayError(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency) Flattens anIterableofObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from each of the returnedObservableSources without being interrupted by an error notification from one of them, while limiting the number of concurrent subscriptions to theseObservableSources.static <@NonNull T>
@NonNull Observable<T> mergeDelayError(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency, int bufferSize) Flattens anIterableofObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from each of the returnedObservableSources without being interrupted by an error notification from one of them, while limiting the number of concurrent subscriptions to theseObservableSources.final @NonNull Observable<T> mergeWith(@NonNull CompletableSource other) Relays the items of the currentObservableand completes only when the otherCompletableSourcecompletes as well.final @NonNull Observable<T> mergeWith(@NonNull MaybeSource<? extends @NonNull T> other) Merges the sequence of items of the currentObservablewith the success value of the otherMaybeSourceor waits both to complete normally if theMaybeSourceis empty.final @NonNull Observable<T> mergeWith(@NonNull ObservableSource<? extends @NonNull T> other) Flattens the currentObservableand anotherObservableSourceinto a singleObservablesequence, without any transformation.final @NonNull Observable<T> mergeWith(@NonNull SingleSource<? extends @NonNull T> other) Merges the sequence of items of the currentObservablewith the success value of the otherSingleSource.static <@NonNull T>
@NonNull Observable<T> never()Returns anObservablethat never sends any items or notifications to anObserver.final @NonNull Observable<T> Returns anObservableto perform the currentObservable's emissions and notifications on a specifiedScheduler, asynchronously with an unbounded buffer withFlowable.bufferSize()"island size".final @NonNull Observable<T> Returns anObservableto perform the currentObservable's emissions and notifications on a specifiedScheduler, asynchronously with an unbounded buffer withFlowable.bufferSize()"island size" and optionally delaysonErrornotifications.final @NonNull Observable<T> Returns anObservableto perform the currentObservable's emissions and notifications on a specifiedScheduler, asynchronously with an unbounded buffer of configurable "island size" and optionally delaysonErrornotifications.final <@NonNull U>
@NonNull Observable<U> Filters the items emitted by the currentObservable, only emitting those of the specified type.final @NonNull Observable<T> Returns anObservableinstance that if the currentObservableemits an error, it will emit anonCompleteand swallow the throwable.final @NonNull Observable<T> onErrorComplete(@NonNull Predicate<? super Throwable> predicate) Returns anObservableinstance that if the currentObservableemits an error and the predicate returnstrue, it will emit anonCompleteand swallow the throwable.final @NonNull Observable<T> onErrorResumeNext(@NonNull Function<? super Throwable, ? extends ObservableSource<? extends @NonNull T>> fallbackSupplier) Resumes the flow with anObservableSourcereturned for the failureThrowableof the currentObservableby a function instead of signaling the error viaonError.final @NonNull Observable<T> onErrorResumeWith(@NonNull ObservableSource<? extends @NonNull T> fallback) Resumes the flow with the givenObservableSourcewhen the currentObservablefails instead of signaling the error viaonError.final @NonNull Observable<T> Ends the flow with a last item returned by a function for theThrowableerror signaled by the currentObservableinstead of signaling the error viaonError.final @NonNull Observable<T> onErrorReturnItem(@NonNull T item) Ends the flow with the given last item when the currentObservablefails instead of signaling the error viaonError.final @NonNull Observable<T> Nulls out references to the upstream producer and downstreamObserverif the sequence is terminated or downstream callsdispose().final @NonNull ConnectableObservable<T> publish()Returns aConnectableObservable, which is a variety ofObservableSourcethat waits until itsconnectmethod is called before it begins emitting items to thoseObservers that have subscribed to it.final <@NonNull R>
@NonNull Observable<R> publish(@NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector) Returns anObservablethat emits the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservablesequence.static @NonNull Observable<Integer> range(int start, int count) Returns anObservablethat emits a sequence ofIntegers within a specified range.static @NonNull Observable<Long> rangeLong(long start, long count) Returns anObservablethat emits a sequence ofLongs within a specified range.Returns aMaybethat applies a specified accumulator function to the first item emitted by the currentObservable, then feeds the result of that function along with the second item emitted by the currentObservableinto the same function, and so on until all items have been emitted by the current and finiteObservable, and emits the final result from the final call to your function as its sole item.Returns aSinglethat applies a specified accumulator function to the first item emitted by the currentObservableand a specified seed value, then feeds the result of that function along with the second item emitted by the currentObservableinto the same function, and so on until all items have been emitted by the current and finiteObservable, emitting the final result from the final call to your function as its sole item.reduceWith(@NonNull Supplier<@NonNull R> seedSupplier, @NonNull BiFunction<@NonNull R, ? super @NonNull T, @NonNull R> reducer) Returns aSinglethat applies a specified accumulator function to the first item emitted by the currentObservableand a seed value derived from calling a specifiedseedSupplier, then feeds the result of that function along with the second item emitted by the currentObservableinto the same function, and so on until all items have been emitted by the current and finiteObservable, emitting the final result from the final call to your function as its sole item.final @NonNull Observable<T> repeat()Returns anObservablethat repeats the sequence of items emitted by the currentObservableindefinitely.final @NonNull Observable<T> repeat(long times) Returns anObservablethat repeats the sequence of items emitted by the currentObservableat mostcounttimes.final @NonNull Observable<T> Returns anObservablethat repeats the sequence of items emitted by the currentObservableuntil the provided stop function returnstrue.final @NonNull Observable<T> repeatWhen(@NonNull Function<? super Observable<Object>, ? extends ObservableSource<?>> handler) Returns anObservablethat emits the same values as the currentObservablewith the exception of anonComplete.final @NonNull ConnectableObservable<T> replay()Returns aConnectableObservablethat shares a single subscription to the currentObservablethat will replay all of its items and notifications to any futureObserver.final @NonNull ConnectableObservable<T> replay(int bufferSize) Returns aConnectableObservablethat shares a single subscription to the currentObservablethat replays at mostbufferSizeitems emitted by the currentObservable.final @NonNull ConnectableObservable<T> replay(int bufferSize, boolean eagerTruncate) Returns aConnectableObservablethat shares a single subscription to the currentObservablethat replays at mostbufferSizeitems emitted by the currentObservable.final @NonNull ConnectableObservable<T> Returns aConnectableObservablethat shares a single subscription to the currentObservableand replays at mostbufferSizeitems that were emitted during a specified time window.final @NonNull ConnectableObservable<T> Returns aConnectableObservablethat shares a single subscription to the currentObservableand that replays a maximum ofbufferSizeitems that are emitted within a specified time window.final @NonNull ConnectableObservable<T> replay(int bufferSize, long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, boolean eagerTruncate) Returns aConnectableObservablethat shares a single subscription to the currentObservableand that replays a maximum ofbufferSizeitems that are emitted within a specified time window.final @NonNull ConnectableObservable<T> Returns aConnectableObservablethat shares a single subscription to the currentObservableand replays all items emitted by the currentObservablewithin a specified time window.final @NonNull ConnectableObservable<T> Returns aConnectableObservablethat shares a single subscription to the currentObservableand replays all items emitted by the currentObservablewithin a specified time window.final @NonNull ConnectableObservable<T> Returns aConnectableObservablethat shares a single subscription to the currentObservableand replays all items emitted by the currentObservablewithin a specified time window.final <@NonNull R>
@NonNull Observable<R> replay(@NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector) Returns anObservablethat emits items that are the results of invoking a specified selector on the items emitted by aConnectableObservablethat shares a single subscription to the currentObservable.final <@NonNull R>
@NonNull Observable<R> replay(@NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, int bufferSize) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replayingbufferSizenotifications.final <@NonNull R>
@NonNull Observable<R> replay(@NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, int bufferSize, boolean eagerTruncate) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replayingbufferSizenotifications.final <@NonNull R>
@NonNull Observable<R> replay(@NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, int bufferSize, long time, @NonNull TimeUnit unit) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replaying no more thanbufferSizeitems that were emitted within a specified time window.final <@NonNull R>
@NonNull Observable<R> replay(@NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, int bufferSize, long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replaying no more thanbufferSizeitems that were emitted within a specified time window.final <@NonNull R>
@NonNull Observable<R> replay(@NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, int bufferSize, long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, boolean eagerTruncate) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replaying no more thanbufferSizeitems that were emitted within a specified time window.final <@NonNull R>
@NonNull Observable<R> replay(@NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, long time, @NonNull TimeUnit unit) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replaying all items that were emitted within a specified time window.final <@NonNull R>
@NonNull Observable<R> replay(@NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replaying all items that were emitted within a specified time window.final <@NonNull R>
@NonNull Observable<R> replay(@NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, boolean eagerTruncate) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replaying all items that were emitted within a specified time window.final @NonNull Observable<T> retry()Returns anObservablethat mirrors the currentObservable, resubscribing to it if it callsonError(infinite retry count).final @NonNull Observable<T> retry(long times) Returns anObservablethat mirrors the currentObservable, resubscribing to it if it callsonErrorup to a specified number of retries.final @NonNull Observable<T> Retries at most times or until the predicate returnsfalse, whichever happens first.final @NonNull Observable<T> retry(@NonNull BiPredicate<? super Integer, ? super Throwable> predicate) Returns anObservablethat mirrors the currentObservable, resubscribing to it if it callsonErrorand the predicate returnstruefor that specific exception and retry count.final @NonNull Observable<T> Retries the currentObservableif the predicate returnstrue.final @NonNull Observable<T> Retries until the given stop function returnstrue.final @NonNull Observable<T> retryWhen(@NonNull Function<? super Observable<Throwable>, ? extends ObservableSource<?>> handler) Returns anObservablethat emits the same values as the currentObservablewith the exception of anonError.final voidsafeSubscribe(@NonNull Observer<? super @NonNull T> observer) Subscribes to the currentObservableand wraps the givenObserverinto aSafeObserver(if not already aSafeObserver) that deals with exceptions thrown by a misbehavingObserver(that doesn't follow the Reactive Streams specification).final @NonNull Observable<T> Returns anObservablethat emits the most recently emitted item (if any) emitted by the currentObservablewithin periodic time intervals.final @NonNull Observable<T> Returns anObservablethat emits the most recently emitted item (if any) emitted by the currentObservablewithin periodic time intervals and optionally emit the very last upstream item when the upstream completes.final @NonNull Observable<T> Returns anObservablethat emits the most recently emitted item (if any) emitted by the currentObservablewithin periodic time intervals, where the intervals are defined on a particularScheduler.final @NonNull Observable<T> Returns anObservablethat emits the most recently emitted item (if any) emitted by the currentObservablewithin periodic time intervals, where the intervals are defined on a particularSchedulerand optionally emit the very last upstream item when the upstream completes.final @NonNull Observable<T> sample(long period, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, boolean emitLast, @NonNull Consumer<? super @NonNull T> onDropped) Returns anObservablethat emits the most recently emitted item (if any) emitted by the currentObservablewithin periodic time intervals, where the intervals are defined on a particularScheduler.final <@NonNull U>
@NonNull Observable<T> sample(@NonNull ObservableSource<@NonNull U> sampler) Returns anObservablethat, when the specifiedsamplerObservableSourceemits an item or completes, emits the most recently emitted item (if any) emitted by the currentObservablesince the previous emission from thesamplerObservableSource.final <@NonNull U>
@NonNull Observable<T> sample(@NonNull ObservableSource<@NonNull U> sampler, boolean emitLast) Returns anObservablethat, when the specifiedsamplerObservableSourceemits an item or completes, emits the most recently emitted item (if any) emitted by the currentObservablesince the previous emission from thesamplerObservableSourceand optionally emit the very last upstream item when the upstream or otherObservableSourcecomplete.final @NonNull Observable<T> Returns anObservablethat emits the first value emitted by the currentObservable, then emits one value for each subsequent value emitted by the currentObservable.final <@NonNull R>
@NonNull Observable<R> scan(@NonNull R initialValue, @NonNull BiFunction<@NonNull R, ? super @NonNull T, @NonNull R> accumulator) Returns anObservablethat emits the provided initial (seed) value, then emits one value for each value emitted by the currentObservable.final <@NonNull R>
@NonNull Observable<R> scanWith(@NonNull Supplier<@NonNull R> seedSupplier, @NonNull BiFunction<@NonNull R, ? super @NonNull T, @NonNull R> accumulator) Returns anObservablethat emits the provided initial (seed) value, then emits one value for each value emitted by the currentObservable.sequenceEqual(@NonNull ObservableSource<? extends @NonNull T> source1, @NonNull ObservableSource<? extends @NonNull T> source2) Returns aSinglethat emits aBooleanvalue that indicates whether twoObservableSourcesequences are the same by comparing the items emitted by eachObservableSourcepairwise.sequenceEqual(@NonNull ObservableSource<? extends @NonNull T> source1, @NonNull ObservableSource<? extends @NonNull T> source2, int bufferSize) Returns aSinglethat emits aBooleanvalue that indicates whether twoObservableSourcesequences are the same by comparing the items emitted by eachObservableSourcepairwise.sequenceEqual(@NonNull ObservableSource<? extends @NonNull T> source1, @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull BiPredicate<? super @NonNull T, ? super @NonNull T> isEqual) Returns aSinglethat emits aBooleanvalue that indicates whether twoObservableSourcesequences are the same by comparing the items emitted by eachObservableSourcepairwise based on the results of a specified equality function.sequenceEqual(@NonNull ObservableSource<? extends @NonNull T> source1, @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull BiPredicate<? super @NonNull T, ? super @NonNull T> isEqual, int bufferSize) Returns aSinglethat emits aBooleanvalue that indicates whether twoObservableSourcesequences are the same by comparing the items emitted by eachObservableSourcepairwise based on the results of a specified equality function.final @NonNull Observable<T> Forces the currentObservable's emissions and notifications to be serialized and for it to obey theObservableSourcecontract in other ways.final @NonNull Observable<T> share()Returns a newObservablethat multicasts (and shares a single subscription to) the currentObservable.Returns aSinglethat emits the single item emitted by the currentObservable, if the currentObservableemits only a single item, or a default item if the currentObservableemits no items.Returns aMaybethat completes if the currentObservableis empty or emits the single item emitted by the currentObservable, or signals anIllegalArgumentExceptionif the currentObservableemits more than one item.Returns aSinglethat emits the single item emitted by the currentObservableif it emits only a single item, otherwise if the currentObservablecompletes without emitting any items or emits more than one item aNoSuchElementExceptionorIllegalArgumentExceptionwill be signaled respectively.final @NonNull CompletionStage<T> Signals the only expected upstream item, aNoSuchElementExceptionif the upstream is empty or signalsIllegalArgumentExceptionif the upstream has more than one item via aCompletionStage.final @NonNull CompletionStage<T> singleStage(@NonNull T defaultItem) Signals the only expected upstream item (or the default item if the upstream is empty) or signalsIllegalArgumentExceptionif the upstream has more than one item via aCompletionStage.final @NonNull Observable<T> skip(long count) Returns anObservablethat skips the firstcountitems emitted by the currentObservableand emits the remainder.final @NonNull Observable<T> Returns anObservablethat skips values emitted by the currentObservablebefore a specified time window elapses.final @NonNull Observable<T> Returns anObservablethat skips values emitted by the currentObservablebefore a specified time window on a specifiedSchedulerelapses.final @NonNull Observable<T> skipLast(int count) Returns anObservablethat drops a specified number of items from the end of the sequence emitted by the currentObservable.final @NonNull Observable<T> Returns anObservablethat drops items emitted by the currentObservableduring a specified time window before the source completes.final @NonNull Observable<T> Returns anObservablethat drops items emitted by the currentObservableduring a specified time window before the source completes.final @NonNull Observable<T> Returns anObservablethat drops items emitted by the currentObservableduring a specified time window (defined on a specified scheduler) before the source completes.final @NonNull Observable<T> Returns anObservablethat drops items emitted by the currentObservableduring a specified time window (defined on a specified scheduler) before the source completes.final @NonNull Observable<T> skipLast(long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, boolean delayError, int bufferSize) Returns anObservablethat drops items emitted by the currentObservableduring a specified time window (defined on a specified scheduler) before the source completes.final <@NonNull U>
@NonNull Observable<T> skipUntil(@NonNull ObservableSource<@NonNull U> other) Returns anObservablethat skips items emitted by the currentObservableuntil a secondObservableSourceemits an item.final @NonNull Observable<T> Returns anObservablethat skips all items emitted by the currentObservableas long as a specified condition holdstrue, but emits all further source items as soon as the condition becomesfalse.final @NonNull Observable<T> sorted()Returns anObservablethat emits the events emitted by the currentObservable, in a sorted order.final @NonNull Observable<T> sorted(@NonNull Comparator<? super @NonNull T> comparator) Returns anObservablethat emits the events emitted by the currentObservable, in a sorted order based on a specified comparison function.final @NonNull Observable<T> startWith(@NonNull CompletableSource other) Returns anObservablewhich first runs the otherCompletableSourcethen the currentObservableif the other completed normally.final @NonNull Observable<T> startWith(@NonNull MaybeSource<@NonNull T> other) Returns anObservablewhich first runs the otherMaybeSourcethen the currentObservableif the other succeeded or completed normally.final @NonNull Observable<T> startWith(@NonNull ObservableSource<? extends @NonNull T> other) Returns anObservablethat emits the items in a specifiedObservableSourcebefore it begins to emit items emitted by the currentObservable.final @NonNull Observable<T> startWith(@NonNull SingleSource<@NonNull T> other) Returns anObservablewhich first runs the otherSingleSourcethen the currentObservableif the other succeeded normally.final @NonNull Observable<T> startWithArray(@NonNull T... items) Returns anObservablethat emits the specified items before it begins to emit items emitted by the currentObservable.final @NonNull Observable<T> startWithItem(@NonNull T item) Returns anObservablethat emits a specified item before it begins to emit items emitted by the currentObservable.final @NonNull Observable<T> startWithIterable(@NonNull Iterable<? extends @NonNull T> items) Returns anObservablethat emits the items in a specifiedIterablebefore it begins to emit items emitted by the currentObservable.final @NonNull DisposableSubscribes to the currentObservableand ignoresonNextandonCompleteemissions.final voidSubscribes the givenObserverto thisObservableSourceinstance.final @NonNull DisposableSubscribes to the currentObservableand provides a callback to handle the items it emits.final @NonNull Disposablesubscribe(@NonNull Consumer<? super @NonNull T> onNext, @NonNull Consumer<? super Throwable> onError) Subscribes to the currentObservableand provides callbacks to handle the items it emits and any error notification it signals.final @NonNull Disposablesubscribe(@NonNull Consumer<? super @NonNull T> onNext, @NonNull Consumer<? super Throwable> onError, @NonNull Action onComplete) Subscribes to the currentObservableand provides callbacks to handle the items it emits and any error or completion notification it signals.final @NonNull Disposablesubscribe(@NonNull Consumer<? super @NonNull T> onNext, @NonNull Consumer<? super Throwable> onError, @NonNull Action onComplete, @NonNull DisposableContainer container) Wraps the given onXXX callbacks into aDisposableObserver, adds it to the givenDisposableContainerand ensures, that if the upstream terminates or this particularDisposableis disposed, theObserveris removed from the given container.protected abstract voidsubscribeActual(@NonNull Observer<? super @NonNull T> observer) Operator implementations (both source and intermediate) should implement this method that performs the necessary business logic and handles the incomingObservers.final @NonNull Observable<T> subscribeOn(@NonNull Scheduler scheduler) subscribeWith(@NonNull E observer) Subscribes a givenObserver(subclass) to the currentObservableand returns the givenObserverinstance as is.final @NonNull Observable<T> switchIfEmpty(@NonNull ObservableSource<? extends @NonNull T> other) Returns anObservablethat emits the items emitted by the currentObservableor the items of an alternateObservableSourceif the currentObservableis empty.final <@NonNull R>
@NonNull Observable<R> switchMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper) Returns a newObservableby applying a function that you supply to each item emitted by the currentObservablethat returns anObservableSource, and then emitting the items emitted by the most recently emitted of theseObservableSources.final <@NonNull R>
@NonNull Observable<R> switchMap(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, int bufferSize) Returns a newObservableby applying a function that you supply to each item emitted by the currentObservablethat returns anObservableSource, and then emitting the items emitted by the most recently emitted of theseObservableSources.final @NonNull CompletableswitchMapCompletable(@NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Maps the items of the currentObservableintoCompletableSources, subscribes to the newer one while disposing the subscription to the previousCompletableSource, thus keeping at most one activeCompletableSourcerunning.final @NonNull CompletableswitchMapCompletableDelayError(@NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Maps the upstream values intoCompletableSources, subscribes to the newer one while disposing the subscription to the previousCompletableSource, thus keeping at most one activeCompletableSourcerunning and delaying any main or inner errors until all of them terminate.final <@NonNull R>
@NonNull Observable<R> switchMapDelayError(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper) Returns a newObservableby applying a function that you supply to each item emitted by the currentObservablethat returns anObservableSource, and then emitting the items emitted by the most recently emitted of theseObservableSources and delays any error until allObservableSources terminate.final <@NonNull R>
@NonNull Observable<R> switchMapDelayError(@NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, int bufferSize) Returns a newObservableby applying a function that you supply to each item emitted by the currentObservablethat returns anObservableSource, and then emitting the items emitted by the most recently emitted of theseObservableSources and delays any error until allObservableSources terminate.final <@NonNull R>
@NonNull Observable<R> switchMapMaybe(@NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper) Maps the items of the currentObservableintoMaybeSources and switches (subscribes) to the newer ones while disposing the older ones (and ignoring their signals) and emits the latest success value of the current one if available while failing immediately if the currentObservableor any of the active innerMaybeSources fail.final <@NonNull R>
@NonNull Observable<R> switchMapMaybeDelayError(@NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper) Maps the upstream items intoMaybeSources and switches (subscribes) to the newer ones while disposing the older ones (and ignoring their signals) and emits the latest success value of the current one if available, delaying errors from the currentObservableor the innerMaybeSources until all terminate.final <@NonNull R>
@NonNull Observable<R> switchMapSingle(@NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Returns a newObservableby applying a function that you supply to each item emitted by the currentObservablethat returns aSingleSource, and then emitting the item emitted by the most recently emitted of theseSingleSources.final <@NonNull R>
@NonNull Observable<R> switchMapSingleDelayError(@NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Returns a newObservableby applying a function that you supply to each item emitted by the currentObservablethat returns aSingleSource, and then emitting the item emitted by the most recently emitted of theseSingleSources and delays any error until allSingleSources terminate.static <@NonNull T>
@NonNull Observable<T> switchOnNext(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Converts anObservableSourcethat emitsObservableSources into anObservablethat emits the items emitted by the most recently emitted of thoseObservableSources.static <@NonNull T>
@NonNull Observable<T> switchOnNext(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int bufferSize) Converts anObservableSourcethat emitsObservableSources into anObservablethat emits the items emitted by the most recently emitted of thoseObservableSources.static <@NonNull T>
@NonNull Observable<T> switchOnNextDelayError(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Converts anObservableSourcethat emitsObservableSources into anObservablethat emits the items emitted by the most recently emitted of thoseObservableSources and delays any exception until allObservableSources terminate.static <@NonNull T>
@NonNull Observable<T> switchOnNextDelayError(@NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int bufferSize) Converts anObservableSourcethat emitsObservableSources into anObservablethat emits the items emitted by the most recently emitted of thoseObservableSources and delays any exception until allObservableSources terminate.final @NonNull Observable<T> take(long count) Returns anObservablethat emits only the firstcountitems emitted by the currentObservable.final @NonNull Observable<T> Returns anObservablethat emits those items emitted by the currentObservablebefore a specified time runs out.final @NonNull Observable<T> Returns anObservablethat emits those items emitted by the currentObservablebefore a specified time (on a specifiedScheduler) runs out.final @NonNull Observable<T> takeLast(int count) Returns anObservablethat emits at most the lastcountitems emitted by the currentObservable.final @NonNull Observable<T> Returns anObservablethat emits at most a specified number of items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted.final @NonNull Observable<T> Returns anObservablethat emits at most a specified number of items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted, where the timing information is provided by a givenScheduler.final @NonNull Observable<T> takeLast(long count, long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, boolean delayError, int bufferSize) Returns anObservablethat emits at most a specified number of items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted, where the timing information is provided by a givenScheduler.final @NonNull Observable<T> Returns anObservablethat emits the items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted.final @NonNull Observable<T> Returns anObservablethat emits the items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted.final @NonNull Observable<T> Returns anObservablethat emits the items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted, where the timing information is provided by a specifiedScheduler.final @NonNull Observable<T> Returns anObservablethat emits the items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted, where the timing information is provided by a specifiedScheduler.final @NonNull Observable<T> takeLast(long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, boolean delayError, int bufferSize) Returns anObservablethat emits the items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted, where the timing information is provided by a specifiedScheduler.final <@NonNull U>
@NonNull Observable<T> takeUntil(@NonNull ObservableSource<@NonNull U> other) Returns anObservablethat emits the items emitted by the currentObservableuntil a secondObservableSourceemits an item or completes.final @NonNull Observable<T> Returns anObservablethat emits items emitted by the currentObservable, checks the specified predicate for each item, and then completes when the condition is satisfied.final @NonNull Observable<T> Returns anObservablethat emits items emitted by the currentObservableso long as each item satisfied a specified condition, and then completes as soon as this condition is not satisfied.final @NonNull TestObserver<T> test()Creates aTestObserverand subscribes it to the currentObservable.final @NonNull TestObserver<T> test(boolean dispose) Creates aTestObserver, optionally disposes it and then subscribes it to the currentObservable.final @NonNull Observable<T> throttleFirst(long windowDuration, @NonNull TimeUnit unit) Returns anObservablethat emits only the first item emitted by the currentObservableduring sequential time windows of a specified duration.final @NonNull Observable<T> throttleFirst(long skipDuration, @NonNull TimeUnit unit, @NonNull Scheduler scheduler) Returns anObservablethat emits only the first item emitted by the currentObservableduring sequential time windows of a specified duration, where the windows are managed by a specifiedScheduler.final @NonNull Observable<T> throttleFirst(long skipDuration, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, @NonNull Consumer<? super @NonNull T> onDropped) Returns anObservablethat emits only the first item emitted by the currentObservableduring sequential time windows of a specified duration, where the windows are managed by a specifiedScheduler.final @NonNull Observable<T> throttleLast(long intervalDuration, @NonNull TimeUnit unit) Returns anObservablethat emits only the last item emitted by the currentObservableduring sequential time windows of a specified duration.final @NonNull Observable<T> throttleLast(long intervalDuration, @NonNull TimeUnit unit, @NonNull Scheduler scheduler) Returns anObservablethat emits only the last item emitted by the currentObservableduring sequential time windows of a specified duration, where the duration is governed by a specifiedScheduler.final @NonNull Observable<T> throttleLast(long intervalDuration, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, @NonNull Consumer<? super @NonNull T> onDropped) Returns anObservablethat emits only the last item emitted by the currentObservableduring sequential time windows of a specified duration, where the duration is governed by a specifiedScheduler.final @NonNull Observable<T> throttleLatest(long timeout, @NonNull TimeUnit unit) Throttles items from the currentObservableby first emitting the next item from upstream, then periodically emitting the latest item (if any) when the specified timeout elapses between them.final @NonNull Observable<T> throttleLatest(long timeout, @NonNull TimeUnit unit, boolean emitLast) Throttles items from the currentObservableby first emitting the next item from upstream, then periodically emitting the latest item (if any) when the specified timeout elapses between them.final @NonNull Observable<T> throttleLatest(long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler) Throttles items from the currentObservableby first emitting the next item from upstream, then periodically emitting the latest item (if any) when the specified timeout elapses between them.final @NonNull Observable<T> throttleLatest(long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, boolean emitLast) Throttles items from the currentObservableby first emitting the next item from upstream, then periodically emitting the latest item (if any) when the specified timeout elapses between them.final @NonNull Observable<T> throttleLatest(long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, boolean emitLast, @NonNull Consumer<? super @NonNull T> onDropped) Throttles items from the currentObservableby first emitting the next item from upstream, then periodically emitting the latest item (if any) when the specified timeout elapses between them, invoking the consumer for any dropped item.final @NonNull Observable<T> throttleWithTimeout(long timeout, @NonNull TimeUnit unit) Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by newer items before a timeout value expires.final @NonNull Observable<T> throttleWithTimeout(long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler) Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by newer items before a timeout value expires on a specifiedScheduler.final @NonNull Observable<T> throttleWithTimeout(long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, @NonNull Consumer<? super @NonNull T> onDropped) Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by newer items before a timeout value expires on a specifiedScheduler.final @NonNull Observable<Timed<T>> Returns anObservablethat emits records of the time interval between consecutive items emitted by the currentObservable.final @NonNull Observable<Timed<T>> timeInterval(@NonNull Scheduler scheduler) Returns anObservablethat emits records of the time interval between consecutive items emitted by the currentObservable, where this interval is computed on a specifiedScheduler.final @NonNull Observable<Timed<T>> timeInterval(@NonNull TimeUnit unit) Returns anObservablethat emits records of the time interval between consecutive items emitted by the currentObservable.final @NonNull Observable<Timed<T>> timeInterval(@NonNull TimeUnit unit, @NonNull Scheduler scheduler) Returns anObservablethat emits records of the time interval between consecutive items emitted by the currentObservable, where this interval is computed on a specifiedScheduler.final @NonNull Observable<T> Returns anObservablethat mirrors the currentObservablebut applies a timeout policy for each emitted item.final @NonNull Observable<T> timeout(long timeout, @NonNull TimeUnit unit, @NonNull ObservableSource<? extends @NonNull T> fallback) Returns anObservablethat mirrors the currentObservablebut applies a timeout policy for each emitted item.final @NonNull Observable<T> Returns anObservablethat mirrors the currentObservablebut applies a timeout policy for each emitted item, where this policy is governed on a specifiedScheduler.final @NonNull Observable<T> timeout(long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, @NonNull ObservableSource<? extends @NonNull T> fallback) Returns anObservablethat mirrors the currentObservablebut applies a timeout policy for each emitted item using a specifiedScheduler.final <@NonNull U, @NonNull V>
@NonNull Observable<T> timeout(@NonNull ObservableSource<@NonNull U> firstTimeoutIndicator, @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull V>> itemTimeoutIndicator) Returns anObservablethat mirrors the currentObservable, but notifies observers of aTimeoutExceptionif either the first item emitted by the currentObservableor any subsequent item doesn't arrive within time windows defined by indicatorObservableSources.final <@NonNull U, @NonNull V>
@NonNull Observable<T> timeout(@NonNull ObservableSource<@NonNull U> firstTimeoutIndicator, @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull V>> itemTimeoutIndicator, @NonNull ObservableSource<? extends @NonNull T> fallback) Returns anObservablethat mirrors the currentObservable, but switches to a fallbackObservableSourceif either the first item emitted by the currentObservableor any subsequent item doesn't arrive within time windows defined by indicatorObservableSources.final <@NonNull V>
@NonNull Observable<T> timeout(@NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull V>> itemTimeoutIndicator) Returns anObservablethat mirrors the currentObservable, but notifies observers of aTimeoutExceptionif an item emitted by the currentObservabledoesn't arrive within a window of time after the emission of the previous item, where that period of time is measured by anObservableSourcethat is a function of the previous item.final <@NonNull V>
@NonNull Observable<T> timeout(@NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull V>> itemTimeoutIndicator, @NonNull ObservableSource<? extends @NonNull T> fallback) Returns anObservablethat mirrors the currentObservable, but that switches to a fallbackObservableSourceif an item emitted by the currentObservabledoesn't arrive within a window of time after the emission of the previous item, where that period of time is measured by anObservableSourcethat is a function of the previous item.static @NonNull Observable<Long> Returns anObservablethat emits0Lafter a specified delay, and then completes.static @NonNull Observable<Long> Returns anObservablethat emits0Lafter a specified delay, on a specifiedScheduler, and then completes.final @NonNull Observable<Timed<T>> Returns anObservablethat emits each item emitted by the currentObservable, wrapped in aTimedobject.final @NonNull Observable<Timed<T>> final @NonNull Observable<Timed<T>> Returns anObservablethat emits each item emitted by the currentObservable, wrapped in aTimedobject.final @NonNull Observable<Timed<T>> final <@NonNull R>
RCalls the specified converter function during assembly time and returns its resulting value.toFlowable(@NonNull BackpressureStrategy strategy) Converts the currentObservableinto aFlowableby applying the specified backpressure strategy.toFuture()Returns aFuturerepresenting the only value emitted by the currentObservable.toList()toList(int capacityHint) Returns aSinglethat emits a single item, aCollection(subclass) composed of all the items emitted by the finite upstreamObservable.toMap(@NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, @NonNull Function<? super @NonNull T, ? extends @NonNull V> valueSelector) toMap(@NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, @NonNull Function<? super @NonNull T, ? extends @NonNull V> valueSelector, @NonNull Supplier<? extends Map<@NonNull K, @NonNull V>> mapSupplier) toMultimap(@NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, @NonNull Function<? super @NonNull T, ? extends @NonNull V> valueSelector, @NonNull Supplier<? extends Map<@NonNull K, Collection<@NonNull V>>> mapSupplier, @NonNull Function<? super @NonNull K, ? extends Collection<? super @NonNull V>> collectionFactory) Returns aSinglethat emits a singleMap(subclass), returned by a specifiedmapFactoryfunction, that contains a customCollectionof values, extracted by a specifiedvalueSelectorfunction from items emitted by the current and finiteObservable, and keyed by thekeySelectorfunction.toMultimap(@NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, @NonNull Function<? super @NonNull T, ? extends @NonNull V> valueSelector, @NonNull Supplier<Map<@NonNull K, Collection<@NonNull V>>> mapSupplier) toMultimap(@NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, Function<? super @NonNull T, ? extends @NonNull V> valueSelector) toSortedList(int capacityHint) toSortedList(@NonNull Comparator<? super @NonNull T> comparator) toSortedList(@NonNull Comparator<? super @NonNull T> comparator, int capacityHint) static <@NonNull T>
@NonNull Observable<T> unsafeCreate(@NonNull ObservableSource<@NonNull T> onSubscribe) Create anObservableby wrapping anObservableSourcewhich has to be implemented according to theObservablespecification derived from the Reactive Streams specification by handling disposal correctly; no safeguards are provided by theObservableitself.final @NonNull Observable<T> unsubscribeOn(@NonNull Scheduler scheduler) static <@NonNull T, @NonNull D>
@NonNull Observable<T> using(@NonNull Supplier<? extends @NonNull D> resourceSupplier, @NonNull Function<? super @NonNull D, ? extends ObservableSource<? extends @NonNull T>> sourceSupplier, @NonNull Consumer<? super @NonNull D> resourceCleanup) Constructs anObservablethat creates a dependent resource object, anObservableSourcewith that resource and calls the providedresourceDisposerfunction if this inner source terminates or the downstream disposes the flow.static <@NonNull T, @NonNull D>
@NonNull Observable<T> using(@NonNull Supplier<? extends @NonNull D> resourceSupplier, @NonNull Function<? super @NonNull D, ? extends ObservableSource<? extends @NonNull T>> sourceSupplier, @NonNull Consumer<? super @NonNull D> resourceCleanup, boolean eager) Constructs anObservablethat creates a dependent resource object, anObservableSourcewith that resource and calls the provideddisposerfunction if this inner source terminates or the downstream disposes the flow; doing it before these end-states have been reached ifeager == true, after otherwise.final @NonNull Observable<Observable<T>> window(long count) Returns anObservablethat emits windows of items it collects from the currentObservable.final @NonNull Observable<Observable<T>> window(long count, long skip) Returns anObservablethat emits windows of items it collects from the currentObservable.final @NonNull Observable<Observable<T>> window(long count, long skip, int bufferSize) Returns anObservablethat emits windows of items it collects from the currentObservable.final @NonNull Observable<Observable<T>> Returns anObservablethat emits windows of items it collects from the currentObservable.final @NonNull Observable<Observable<T>> Returns anObservablethat emits windows of items it collects from the currentObservable.final @NonNull Observable<Observable<T>> window(long timespan, long timeskip, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, int bufferSize) Returns anObservablethat emits windows of items it collects from the currentObservable.final @NonNull Observable<Observable<T>> Returns anObservablethat emits windows of items it collects from the currentObservable.final @NonNull Observable<Observable<T>> Returns anObservablethat emits windows of items it collects from the currentObservable.final @NonNull Observable<Observable<T>> Returns anObservablethat emits windows of items it collects from the currentObservable.final @NonNull Observable<Observable<T>> Returns anObservablethat emits windows of items it collects from the currentObservable.final @NonNull Observable<Observable<T>> Returns anObservablethat emits windows of items it collects from the currentObservable.final @NonNull Observable<Observable<T>> window(long timespan, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, long count, boolean restart) Returns anObservablethat emits windows of items it collects from the currentObservable.final @NonNull Observable<Observable<T>> window(long timespan, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, long count, boolean restart, int bufferSize) Returns anObservablethat emits windows of items it collects from the currentObservable.final <@NonNull B>
@NonNull Observable<Observable<T>> window(@NonNull ObservableSource<@NonNull B> boundaryIndicator) Returns anObservablethat emits non-overlapping windows of items it collects from the currentObservablewhere the boundary of each window is determined by the items emitted from a specified boundary-governingObservableSource.final <@NonNull B>
@NonNull Observable<Observable<T>> window(@NonNull ObservableSource<@NonNull B> boundaryIndicator, int bufferSize) Returns anObservablethat emits non-overlapping windows of items it collects from the currentObservablewhere the boundary of each window is determined by the items emitted from a specified boundary-governingObservableSource.final <@NonNull U, @NonNull V>
@NonNull Observable<Observable<T>> window(@NonNull ObservableSource<@NonNull U> openingIndicator, @NonNull Function<? super @NonNull U, ? extends ObservableSource<@NonNull V>> closingIndicator) Returns anObservablethat emits windows of items it collects from the currentObservable.final <@NonNull U, @NonNull V>
@NonNull Observable<Observable<T>> window(@NonNull ObservableSource<@NonNull U> openingIndicator, @NonNull Function<? super @NonNull U, ? extends ObservableSource<@NonNull V>> closingIndicator, int bufferSize) Returns anObservablethat emits windows of items it collects from the currentObservable.final <@NonNull R>
@NonNull Observable<R> withLatestFrom(@NonNull ObservableSource<?>[] others, @NonNull Function<? super Object[], @NonNull R> combiner) Combines the value emission from the currentObservablewith the latest emissions from the otherObservableSources via a function to produce the output item.final <@NonNull U, @NonNull R>
@NonNull Observable<R> withLatestFrom(@NonNull ObservableSource<? extends @NonNull U> other, @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> combiner) Merges the specifiedObservableSourceinto the currentObservablesequence by using theresultSelectorfunction only when the currentObservableemits an item.withLatestFrom(@NonNull ObservableSource<@NonNull T1> source1, @NonNull ObservableSource<@NonNull T2> source2, @NonNull ObservableSource<@NonNull T3> source3, @NonNull ObservableSource<@NonNull T4> source4, @NonNull Function5<? super @NonNull T, ? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, @NonNull R> combiner) Combines the value emission from the currentObservablewith the latest emissions from the otherObservableSources via a function to produce the output item.withLatestFrom(@NonNull ObservableSource<@NonNull T1> source1, @NonNull ObservableSource<@NonNull T2> source2, @NonNull ObservableSource<@NonNull T3> source3, @NonNull Function4<? super @NonNull T, ? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, @NonNull R> combiner) Combines the value emission from the currentObservablewith the latest emissions from the otherObservableSources via a function to produce the output item.final <@NonNull T1, @NonNull T2, @NonNull R>
@NonNull Observable<R> withLatestFrom(@NonNull ObservableSource<@NonNull T1> source1, @NonNull ObservableSource<@NonNull T2> source2, @NonNull Function3<? super @NonNull T, ? super @NonNull T1, ? super @NonNull T2, @NonNull R> combiner) Combines the value emission from the currentObservablewith the latest emissions from the otherObservableSources via a function to produce the output item.final <@NonNull R>
@NonNull Observable<R> withLatestFrom(@NonNull Iterable<@NonNull ? extends ObservableSource<?>> others, @NonNull Function<? super Object[], @NonNull R> combiner) Combines the value emission from the currentObservablewith the latest emissions from the otherObservableSources via a function to produce the output item.static <@NonNull T>
@NonNull Observable<T> wrap(@NonNull ObservableSource<@NonNull T> source) static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull T8, @NonNull T9, @NonNull R>
@NonNull Observable<R> zip(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull ObservableSource<? extends @NonNull T7> source7, @NonNull ObservableSource<? extends @NonNull T8> source8, @NonNull ObservableSource<? extends @NonNull T9> source9, @NonNull Function9<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? super @NonNull T8, ? super @NonNull T9, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of nine items emitted, in sequence, by nine otherObservableSources.static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull T8, @NonNull R>
@NonNull Observable<R> zip(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull ObservableSource<? extends @NonNull T7> source7, @NonNull ObservableSource<? extends @NonNull T8> source8, @NonNull Function8<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? super @NonNull T8, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of eight items emitted, in sequence, by eight otherObservableSources.static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull R>
@NonNull Observable<R> zip(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull ObservableSource<? extends @NonNull T7> source7, @NonNull Function7<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of seven items emitted, in sequence, by seven otherObservableSources.static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull R>
@NonNull Observable<R> zip(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull Function6<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of six items emitted, in sequence, by six otherObservableSources.static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull R>
@NonNull Observable<R> zip(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull Function5<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of five items emitted, in sequence, by five otherObservableSources.zip(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull Function4<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of four items emitted, in sequence, by four otherObservableSources.zip(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull Function3<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of three items emitted, in sequence, by three otherObservableSources.static <@NonNull T1, @NonNull T2, @NonNull R>
@NonNull Observable<R> zip(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull BiFunction<? super @NonNull T1, ? super @NonNull T2, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of two items emitted, in sequence, by two otherObservableSources.static <@NonNull T1, @NonNull T2, @NonNull R>
@NonNull Observable<R> zip(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull BiFunction<? super @NonNull T1, ? super @NonNull T2, ? extends @NonNull R> zipper, boolean delayError) Returns anObservablethat emits the results of a specified combiner function applied to combinations of two items emitted, in sequence, by two otherObservableSources.static <@NonNull T1, @NonNull T2, @NonNull R>
@NonNull Observable<R> zip(@NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull BiFunction<? super @NonNull T1, ? super @NonNull T2, ? extends @NonNull R> zipper, boolean delayError, int bufferSize) Returns anObservablethat emits the results of a specified combiner function applied to combinations of two items emitted, in sequence, by two otherObservableSources.static <@NonNull T, @NonNull R>
@NonNull Observable<R> zip(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, @NonNull Function<? super Object[], ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by anIterableof otherObservableSources.static <@NonNull T, @NonNull R>
@NonNull Observable<R> zip(@NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, @NonNull Function<? super Object[], ? extends @NonNull R> zipper, boolean delayError, int bufferSize) Returns anObservablethat emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by anIterableof otherObservableSources.static <@NonNull T, @NonNull R>
@NonNull Observable<R> zipArray(@NonNull Function<? super Object[], ? extends @NonNull R> zipper, boolean delayError, int bufferSize, @NonNull ObservableSource<? extends @NonNull T>... sources) Returns anObservablethat emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by an array of otherObservableSources.final <@NonNull U, @NonNull R>
@NonNull Observable<R> zipWith(@NonNull ObservableSource<? extends @NonNull U> other, @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> zipper) Returns anObservablethat emits items that are the result of applying a specified function to pairs of values, one each from the currentObservableand another specifiedObservableSource.final <@NonNull U, @NonNull R>
@NonNull Observable<R> zipWith(@NonNull ObservableSource<? extends @NonNull U> other, @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> zipper, boolean delayError) Returns anObservablethat emits items that are the result of applying a specified function to pairs of values, one each from the currentObservableand another specifiedObservableSource.final <@NonNull U, @NonNull R>
@NonNull Observable<R> zipWith(@NonNull ObservableSource<? extends @NonNull U> other, @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> zipper, boolean delayError, int bufferSize) Returns anObservablethat emits items that are the result of applying a specified function to pairs of values, one each from the currentObservableand another specifiedObservableSource.final <@NonNull U, @NonNull R>
@NonNull Observable<R> zipWith(@NonNull Iterable<@NonNull U> other, @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> zipper) Returns anObservablethat emits items that are the result of applying a specified function to pairs of values, one each from the currentObservableand a specifiedIterablesequence.
-
Constructor Details
-
Observable
public Observable()
-
-
Method Details
-
amb
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> amb(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources) Mirrors the oneObservableSourcein anIterableof severalObservableSources that first either emits an item or sends a termination notification.
When one of the
ObservableSources signal an item or terminates first, all subscriptions to the otherObservableSources are disposed.- Scheduler:
ambdoes not operate by default on a particularScheduler.- Error handling:
-
If any of the losing
ObservableSources signals an error, the error is routed to the global error handler viaRxJavaPlugins.onError(Throwable).
- Type Parameters:
T- the common element type- Parameters:
sources- anIterableofObservableSourcesources competing to react first. A subscription to each source will occur in the same order as in theIterable.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
ambArray
@CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static <@NonNull T> @NonNull Observable<T> ambArray(@NonNull @NonNull ObservableSource<? extends @NonNull T>... sources) Mirrors the oneObservableSourcein an array of severalObservableSources that first either emits an item or sends a termination notification.
When one of the
ObservableSources signal an item or terminates first, all subscriptions to the otherObservableSources are disposed.- Scheduler:
ambArraydoes not operate by default on a particularScheduler.- Error handling:
-
If any of the losing
ObservableSources signals an error, the error is routed to the global error handler viaRxJavaPlugins.onError(Throwable).
- Type Parameters:
T- the common element type- Parameters:
sources- an array ofObservableSourcesources competing to react first. A subscription to each source will occur in the same order as in the array.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
bufferSize
Returns the default 'island' size or capacity-increment hint for unbounded buffers.Delegates to
Flowable.bufferSize()but is public for convenience.The value can be overridden via system parameter
rx3.buffer-sizebefore theFlowableclass is loaded.- Returns:
- the default 'island' size or capacity-increment hint
-
combineLatest
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T, @NonNull R> @NonNull Observable<R> combineLatest(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, @NonNull @NonNull Function<? super Object[], ? extends @NonNull R> combiner) Combines a collection of sourceObservableSources by emitting an item that aggregates the latest values of each of the returnedObservableSources each time an item is received from any of the returnedObservableSources, where this aggregation is defined by a specified function.Note on method signature: since Java doesn't allow creating a generic array with
new T[], the implementation of this operator has to create anObject[]instead. Unfortunately, aFunction<Integer[], R>passed to the method would trigger aClassCastException.If any of the sources never produces an item but only terminates (normally or with an error), the resulting sequence terminates immediately (normally or with all the errors accumulated till that point). If that input source is also synchronous, other sources after it will not be subscribed to.
If the provided iterable of
ObservableSources is empty, the resulting sequence completes immediately without emitting any items and without any calls to the combiner function.
- Scheduler:
combineLatestdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common base type of source valuesR- the result type- Parameters:
sources- the collection of sourceObservableSourcescombiner- the aggregation function used to combine the items emitted by the returnedObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesorcombinerisnull- See Also:
-
combineLatest
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T, @NonNull R> @NonNull Observable<R> combineLatest(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, @NonNull @NonNull Function<? super Object[], ? extends @NonNull R> combiner, int bufferSize) Combines anIterableof sourceObservableSources by emitting an item that aggregates the latest values of each of the returnedObservableSources each time an item is received from any of the returnedObservableSources, where this aggregation is defined by a specified function.Note on method signature: since Java doesn't allow creating a generic array with
new T[], the implementation of this operator has to create anObject[]instead. Unfortunately, aFunction<Integer[], R>passed to the method would trigger aClassCastException.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
IterableofObservableSources is empty, the resulting sequence completes immediately without emitting any items and without any calls to the combiner function.
- Scheduler:
combineLatestdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common base type of source valuesR- the result type- Parameters:
sources- the collection of sourceObservableSourcescombiner- the aggregation function used to combine the items emitted by the returnedObservableSourcesbufferSize- the expected number of row combination items to be buffered internally- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesorcombinerisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
combineLatestArray
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T, @NonNull R> @NonNull Observable<R> combineLatestArray(@NonNull @NonNull ObservableSource<? extends @NonNull T>[] sources, @NonNull @NonNull Function<? super Object[], ? extends @NonNull R> combiner) Combines an array of sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of the returnedObservableSources, where this aggregation is defined by a specified function.Note on method signature: since Java doesn't allow creating a generic array with
new T[], the implementation of this operator has to create anObject[]instead. Unfortunately, aFunction<Integer[], R>passed to the method would trigger aClassCastException.If any of the sources never produces an item but only terminates (normally or with an error), the resulting sequence terminates immediately (normally or with all the errors accumulated till that point). If that input source is also synchronous, other sources after it will not be subscribed to.
If the provided array of
ObservableSources is empty, the resulting sequence completes immediately without emitting any items and without any calls to the combiner function.
- Scheduler:
combineLatestArraydoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common base type of source valuesR- the result type- Parameters:
sources- the collection of sourceObservableSourcescombiner- the aggregation function used to combine the items emitted by theObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesorcombinerisnull- See Also:
-
combineLatestArray
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T, @NonNull R> @NonNull Observable<R> combineLatestArray(@NonNull @NonNull ObservableSource<? extends @NonNull T>[] sources, @NonNull @NonNull Function<? super Object[], ? extends @NonNull R> combiner, int bufferSize) Combines an array of sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function.Note on method signature: since Java doesn't allow creating a generic array with
new T[], the implementation of this operator has to create anObject[]instead. Unfortunately, aFunction<Integer[], R>passed to the method would trigger aClassCastException.If any of the sources never produces an item but only terminates (normally or with an error), the resulting sequence terminates immediately (normally or with all the errors accumulated till that point). If that input source is also synchronous, other sources after it will not be subscribed to.
If the provided array of
ObservableSources is empty, the resulting sequence completes immediately without emitting any items and without any calls to the combiner function.
- Scheduler:
combineLatestArraydoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common base type of source valuesR- the result type- Parameters:
sources- the collection of sourceObservableSourcescombiner- the aggregation function used to combine the items emitted by theObservableSourcesbufferSize- the expected number of row combination items to be buffered internally- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesorcombinerisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
combineLatest
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull R> @NonNull Observable<R> combineLatest(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull BiFunction<? super @NonNull T1, ? super @NonNull T2, ? extends @NonNull R> combiner) Combines two sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from either of theObservableSources, 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:
combineLatestdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the element type of the first sourceT2- the element type of the second sourceR- the combined output type- Parameters:
source1- the first sourceObservableSourcesource2- the second sourceObservableSourcecombiner- the aggregation function used to combine the items emitted by theObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2orcombinerisnull- See Also:
-
combineLatest
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull R> @NonNull Observable<R> combineLatest(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull Function3<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? extends @NonNull R> combiner) Combines three sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, 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:
combineLatestdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the element type of the first sourceT2- the element type of the second sourceT3- the element type of the third sourceR- the combined output type- Parameters:
source1- the first sourceObservableSourcesource2- the second sourceObservableSourcesource3- the third sourceObservableSourcecombiner- the aggregation function used to combine the items emitted by theObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3orcombinerisnull- See Also:
-
combineLatest
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull R> @NonNull Observable<R> combineLatest(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull @NonNull Function4<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? extends @NonNull R> combiner) Combines four sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, 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:
combineLatestdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the element type of the first sourceT2- the element type of the second sourceT3- the element type of the third sourceT4- the element type of the fourth sourceR- the combined output type- Parameters:
source1- the first sourceObservableSourcesource2- the second sourceObservableSourcesource3- the third sourceObservableSourcesource4- the fourth sourceObservableSourcecombiner- the aggregation function used to combine the items emitted by theObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4orcombinerisnull- See Also:
-
combineLatest
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull R> @NonNull Observable<R> combineLatest(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull @NonNull Function5<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? extends @NonNull R> combiner) Combines five sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, 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:
combineLatestdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the element type of the first sourceT2- the element type of the second sourceT3- the element type of the third sourceT4- the element type of the fourth sourceT5- the element type of the fifth sourceR- the combined output type- Parameters:
source1- the first sourceObservableSourcesource2- the second sourceObservableSourcesource3- the third sourceObservableSourcesource4- the fourth sourceObservableSourcesource5- the fifth sourceObservableSourcecombiner- the aggregation function used to combine the items emitted by theObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5orcombinerisnull- See Also:
-
combineLatest
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull R> @NonNull Observable<R> combineLatest(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull @NonNull Function6<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? extends @NonNull R> combiner) Combines six sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, 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:
combineLatestdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the element type of the first sourceT2- the element type of the second sourceT3- the element type of the third sourceT4- the element type of the fourth sourceT5- the element type of the fifth sourceT6- the element type of the sixth sourceR- the combined output type- Parameters:
source1- the first sourceObservableSourcesource2- the second sourceObservableSourcesource3- the third sourceObservableSourcesource4- the fourth sourceObservableSourcesource5- the fifth sourceObservableSourcesource6- the sixth sourceObservableSourcecombiner- the aggregation function used to combine the items emitted by theObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5,source6orcombinerisnull- See Also:
-
combineLatest
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull R> @NonNull Observable<R> combineLatest(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull @NonNull ObservableSource<? extends @NonNull T7> source7, @NonNull @NonNull Function7<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? extends @NonNull R> combiner) Combines seven sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, 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:
combineLatestdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the element type of the first sourceT2- the element type of the second sourceT3- the element type of the third sourceT4- the element type of the fourth sourceT5- the element type of the fifth sourceT6- the element type of the sixth sourceT7- the element type of the seventh sourceR- the combined output type- Parameters:
source1- the first sourceObservableSourcesource2- the second sourceObservableSourcesource3- the third sourceObservableSourcesource4- the fourth sourceObservableSourcesource5- the fifth sourceObservableSourcesource6- the sixth sourceObservableSourcesource7- the seventh sourceObservableSourcecombiner- the aggregation function used to combine the items emitted by theObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5,source6,source7orcombinerisnull- See Also:
-
combineLatest
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull T8, @NonNull R> @NonNull Observable<R> combineLatest(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull @NonNull ObservableSource<? extends @NonNull T7> source7, @NonNull @NonNull ObservableSource<? extends @NonNull T8> source8, @NonNull @NonNull Function8<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? super @NonNull T8, ? extends @NonNull R> combiner) Combines eight sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, 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:
combineLatestdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the element type of the first sourceT2- the element type of the second sourceT3- the element type of the third sourceT4- the element type of the fourth sourceT5- the element type of the fifth sourceT6- the element type of the sixth sourceT7- the element type of the seventh sourceT8- the element type of the eighth sourceR- the combined output type- Parameters:
source1- the first sourceObservableSourcesource2- the second sourceObservableSourcesource3- the third sourceObservableSourcesource4- the fourth sourceObservableSourcesource5- the fifth sourceObservableSourcesource6- the sixth sourceObservableSourcesource7- the seventh sourceObservableSourcesource8- the eighth sourceObservableSourcecombiner- the aggregation function used to combine the items emitted by theObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5,source6,source7,source8orcombinerisnull- See Also:
-
combineLatest
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull T8, @NonNull T9, @NonNull R> @NonNull Observable<R> combineLatest(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull @NonNull ObservableSource<? extends @NonNull T7> source7, @NonNull @NonNull ObservableSource<? extends @NonNull T8> source8, @NonNull @NonNull ObservableSource<? extends @NonNull T9> source9, @NonNull @NonNull Function9<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? super @NonNull T8, ? super @NonNull T9, ? extends @NonNull R> combiner) Combines nine sourceObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, 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:
combineLatestdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the element type of the first sourceT2- the element type of the second sourceT3- the element type of the third sourceT4- the element type of the fourth sourceT5- the element type of the fifth sourceT6- the element type of the sixth sourceT7- the element type of the seventh sourceT8- the element type of the eighth sourceT9- the element type of the ninth sourceR- the combined output type- Parameters:
source1- the first sourceObservableSourcesource2- the second sourceObservableSourcesource3- the third sourceObservableSourcesource4- the fourth sourceObservableSourcesource5- the fifth sourceObservableSourcesource6- the sixth sourceObservableSourcesource7- the seventh sourceObservableSourcesource8- the eighth sourceObservableSourcesource9- the ninth sourceObservableSourcecombiner- the aggregation function used to combine the items emitted by theObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5,source6,source7,source8,source9orcombinerisnull- See Also:
-
combineLatestArrayDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T, @NonNull R> @NonNull Observable<R> combineLatestArrayDelayError(@NonNull @NonNull ObservableSource<? extends @NonNull T>[] sources, @NonNull @NonNull Function<? super Object[], ? extends @NonNull R> combiner) Combines an array ofObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function.
Note on method signature: since Java doesn't allow creating a generic array with
new T[], the implementation of this operator has to create anObject[]instead. Unfortunately, aFunction<Integer[], R>passed to the method would trigger aClassCastException.If any of the sources never produces an item but only terminates (normally or with an error), the resulting sequence terminates immediately (normally or with all the errors accumulated till that point). If that input source is also synchronous, other sources after it will not be subscribed to.
If the provided array of
ObservableSources is empty, the resulting sequence completes immediately without emitting any items and without any calls to the combiner function.- Scheduler:
combineLatestArrayDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common base type of source valuesR- the result type- Parameters:
sources- the collection of sourceObservableSourcescombiner- the aggregation function used to combine the items emitted by theObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesorcombinerisnull- See Also:
-
combineLatestArrayDelayError
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T, @NonNull R> @NonNull Observable<R> combineLatestArrayDelayError(@NonNull @NonNull ObservableSource<? extends @NonNull T>[] sources, @NonNull @NonNull Function<? super Object[], ? extends @NonNull R> combiner, int bufferSize) Combines an array ofObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function and delays any error from the sources until all sourceObservableSources terminate.Note on method signature: since Java doesn't allow creating a generic array with
new T[], the implementation of this operator has to create anObject[]instead. Unfortunately, aFunction<Integer[], R>passed to the method would trigger aClassCastException.If any of the sources never produces an item but only terminates (normally or with an error), the resulting sequence terminates immediately (normally or with all the errors accumulated till that point). If that input source is also synchronous, other sources after it will not be subscribed to.
If the provided array of
ObservableSources is empty, the resulting sequence completes immediately without emitting any items and without any calls to the combiner function.
- Scheduler:
combineLatestArrayDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common base type of source valuesR- the result type- Parameters:
sources- the collection of sourceObservableSourcescombiner- the aggregation function used to combine the items emitted by theObservableSourcesbufferSize- the expected number of row combination items to be buffered internally- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesorcombinerisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
combineLatestDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T, @NonNull R> @NonNull Observable<R> combineLatestDelayError(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, @NonNull @NonNull Function<? super Object[], ? extends @NonNull R> combiner) Combines anIterableofObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function and delays any error from the sources until all sourceObservableSources terminate.Note on method signature: since Java doesn't allow creating a generic array with
new T[], the implementation of this operator has to create anObject[]instead. Unfortunately, aFunction<Integer[], R>passed to the method would trigger aClassCastException.If any of the sources never produces an item but only terminates (normally or with an error), the resulting sequence terminates immediately (normally or with all the errors accumulated till that point). If that input source is also synchronous, other sources after it will not be subscribed to.
If the provided iterable of
ObservableSources is empty, the resulting sequence completes immediately without emitting any items and without any calls to the combiner function.
- Scheduler:
combineLatestDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common base type of source valuesR- the result type- Parameters:
sources- theIterableof sourceObservableSourcescombiner- the aggregation function used to combine the items emitted by theObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesorcombinerisnull- See Also:
-
combineLatestDelayError
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T, @NonNull R> @NonNull Observable<R> combineLatestDelayError(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, @NonNull @NonNull Function<? super Object[], ? extends @NonNull R> combiner, int bufferSize) Combines anIterableofObservableSources by emitting an item that aggregates the latest values of each of theObservableSources each time an item is received from any of theObservableSources, where this aggregation is defined by a specified function and delays any error from the sources until all sourceObservableSources terminate.Note on method signature: since Java doesn't allow creating a generic array with
new T[], the implementation of this operator has to create anObject[]instead. Unfortunately, aFunction<Integer[], R>passed to the method would trigger aClassCastException.If any of the sources never produces an item but only terminates (normally or with an error), the resulting sequence terminates immediately (normally or with all the errors accumulated till that point). If that input source is also synchronous, other sources after it will not be subscribed to.
If the provided iterable of
ObservableSources is empty, the resulting sequence completes immediately without emitting any items and without any calls to the combiner function.
- Scheduler:
combineLatestDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common base type of source valuesR- the result type- Parameters:
sources- the collection of sourceObservableSourcescombiner- the aggregation function used to combine the items emitted by theObservableSourcesbufferSize- the expected number of row combination items to be buffered internally- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesorcombinerisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
concat
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> concat(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources) Concatenates elements of eachObservableSourceprovided via anIterablesequence into a single sequence of elements without interleaving them.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type of the sources- Parameters:
sources- theIterablesequence ofObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull
-
concat
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> concat(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Returns anObservablethat emits the items emitted by each of theObservableSources emitted by theObservableSource, one after the other, without interleaving them.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- anObservableSourcethat emitsObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
concat
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> concat(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int bufferSize) Returns anObservablethat emits the items emitted by each of theObservableSources emitted by the outerObservableSource, one after the other, without interleaving them.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- anObservableSourcethat emitsObservableSourcesbufferSize- the number of innerObservableSources expected to be buffered.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
concat
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> concat(@NonNull @NonNull ObservableSource<? extends @NonNull T> source1, ObservableSource<? extends @NonNull T> source2) Returns anObservablethat emits the items emitted by twoObservableSources, one after the other, without interleaving them.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
source1- anObservableSourceto be concatenatedsource2- anObservableSourceto be concatenated- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1orsource2isnull- See Also:
-
concat
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> concat(@NonNull @NonNull ObservableSource<? extends @NonNull T> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T> source3) Returns anObservablethat emits the items emitted by threeObservableSources, one after the other, without interleaving them.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
source1- anObservableSourceto be concatenatedsource2- anObservableSourceto be concatenatedsource3- anObservableSourceto be concatenated- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2orsource3isnull- See Also:
-
concat
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> concat(@NonNull @NonNull ObservableSource<? extends @NonNull T> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T> source4) Returns anObservablethat emits the items emitted by fourObservableSources, one after the other, without interleaving them.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
source1- anObservableSourceto be concatenatedsource2- anObservableSourceto be concatenatedsource3- anObservableSourceto be concatenatedsource4- anObservableSourceto be concatenated- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3orsource4isnull- See Also:
-
concatArray
@CheckReturnValue @SchedulerSupport("none") @NonNull @SafeVarargs public static <@NonNull T> @NonNull Observable<T> concatArray(@NonNull @NonNull ObservableSource<? extends @NonNull T>... sources) Concatenates a variable number ofObservableSourcesources.Note: named this way because of overload conflict with
concat(ObservableSource<ObservableSource>)
- Scheduler:
concatArraydoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common base value type- Parameters:
sources- the array of sources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull
-
concatArrayDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull @SafeVarargs public static <@NonNull T> @NonNull Observable<T> concatArrayDelayError(@NonNull @NonNull ObservableSource<? extends @NonNull T>... sources) Concatenates a variable number ofObservableSourcesources and delays errors from any of them till all terminate.
- Scheduler:
concatArrayDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common base value type- Parameters:
sources- the array of sources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull
-
concatArrayEager
@CheckReturnValue @SchedulerSupport("none") @SafeVarargs @NonNull public static <@NonNull T> @NonNull Observable<T> concatArrayEager(@NonNull @NonNull ObservableSource<? extends @NonNull T>... sources) Concatenates an array ofObservableSources eagerly into a single stream of values.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
ObservableSources. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- an array ofObservableSources that need to be eagerly concatenated- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.0
-
concatArrayEager
@CheckReturnValue @SchedulerSupport("none") @NonNull @SafeVarargs public static <@NonNull T> @NonNull Observable<T> concatArrayEager(int maxConcurrency, int bufferSize, @NonNull @NonNull ObservableSource<? extends @NonNull T>... sources) Concatenates an array ofObservableSources eagerly into a single stream of values.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
ObservableSources. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
maxConcurrency- the maximum number of concurrent subscriptions at a time,Integer.MAX_VALUEis interpreted as indication to subscribe to all sources at oncebufferSize- the number of elements expected from eachObservableSourceto be bufferedsources- an array ofObservableSources that need to be eagerly concatenated- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- Since:
- 2.0
-
concatArrayEagerDelayError
@CheckReturnValue @SchedulerSupport("none") @SafeVarargs @NonNull public static <@NonNull T> @NonNull Observable<T> concatArrayEagerDelayError(@NonNull @NonNull ObservableSource<? extends @NonNull T>... sources) Concatenates an array ofObservableSources 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
ObservableSources. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- an array ofObservableSources that need to be eagerly concatenated- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.2.1 - experimental
-
concatArrayEagerDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull @SafeVarargs public static <@NonNull T> @NonNull Observable<T> concatArrayEagerDelayError(int maxConcurrency, int bufferSize, @NonNull @NonNull ObservableSource<? extends @NonNull T>... sources) Concatenates an array ofObservableSources 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
ObservableSources. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
maxConcurrency- the maximum number of concurrent subscriptions at a time,Integer.MAX_VALUEis interpreted as indication to subscribe to all sources at oncebufferSize- the number of elements expected from eachObservableSourceto be bufferedsources- an array ofObservableSources that need to be eagerly concatenated- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- Since:
- 2.2.1 - experimental
-
concatDelayError
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> concatDelayError(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources) Concatenates theIterablesequence ofObservableSources into a singleObservablesequence by subscribing to eachObservableSource, one after the other, one at a time and delays any errors till the all innerObservableSources terminate.
- Scheduler:
concatDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- theIterablesequence ofObservableSources- Returns:
- the new
Observablewith the concatenating behavior - Throws:
NullPointerException- ifsourcesisnull
-
concatDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> concatDelayError(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Concatenates theObservableSourcesequence ofObservableSources into a singleObservablesequence by subscribing to each innerObservableSource, one after the other, one at a time and delays any errors till the all inner and the outerObservableSources terminate.
- Scheduler:
concatDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- theObservableSourcesequence ofObservableSources- Returns:
- the new
Observablewith the concatenating behavior - Throws:
NullPointerException- ifsourcesisnull
-
concatDelayError
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> concatDelayError(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int bufferSize, boolean tillTheEnd) Concatenates theObservableSourcesequence ofObservableSources into a single sequence by subscribing to each innerObservableSource, one after the other, one at a time and delays any errors till the all inner and the outerObservableSources terminate.
- Scheduler:
concatDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- theObservableSourcesequence ofObservableSourcesbufferSize- the number of innerObservableSources expected to be bufferedtillTheEnd- iftrue, exceptions from the outer and all innerObservableSources are delayed to the end iffalse, exception from the outerObservableSourceis delayed till the activeObservableSourceterminates- Returns:
- the new
Observablewith the concatenating behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifbufferSizeis non-positive
-
concatEager
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> concatEager(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources) Concatenates a sequence ofObservableSources eagerly into a single stream of values.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
ObservableSources. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofObservableSources that need to be eagerly concatenated- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.0
-
concatEager
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> concatEager(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency, int bufferSize) Concatenates a sequence ofObservableSources 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
ObservableSources. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofObservableSources that need to be eagerly concatenatedmaxConcurrency- the maximum number of concurrently running innerObservableSources;Integer.MAX_VALUEis interpreted as all innerObservableSources can be active at the same timebufferSize- the number of elements expected from each innerObservableSourceto be buffered- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- Since:
- 2.0
-
concatEager
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> concatEager(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Concatenates anObservableSourcesequence ofObservableSources 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 theseObservableSources and then drains them in order, each one after the previous one completes.- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofObservableSources that need to be eagerly concatenated- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.0
-
concatEager
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> concatEager(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency, int bufferSize) Concatenates anObservableSourcesequence ofObservableSources 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
ObservableSources as they are observed. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofObservableSources that need to be eagerly concatenatedmaxConcurrency- the maximum number of concurrently running innerObservableSources;Integer.MAX_VALUEis interpreted as all innerObservableSources can be active at the same timebufferSize- the number of innerObservableSourceexpected to be buffered- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- Since:
- 2.0
-
concatEagerDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> concatEagerDelayError(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources) Concatenates a sequence ofObservableSources 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
ObservableSources. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofObservableSources that need to be eagerly concatenated- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
-
concatEagerDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> concatEagerDelayError(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency, int bufferSize) Concatenates a sequence ofObservableSources 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
ObservableSources. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofObservableSources that need to be eagerly concatenatedmaxConcurrency- the maximum number of concurrently running innerObservableSources;Integer.MAX_VALUEis interpreted as all innerObservableSources can be active at the same timebufferSize- the number of elements expected from each innerObservableSourceto be buffered- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- Since:
- 3.0.0
-
concatEagerDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> concatEagerDelayError(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Concatenates anObservableSourcesequence ofObservableSources 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
ObservableSources as they are observed. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofObservableSources that need to be eagerly concatenated- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
-
concatEagerDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> concatEagerDelayError(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency, int bufferSize) Concatenates anObservableSourcesequence ofObservableSources 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
ObservableSources as they are observed. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofObservableSources that need to be eagerly concatenatedmaxConcurrency- the maximum number of concurrently running innerObservableSources;Integer.MAX_VALUEis interpreted as all innerObservableSources can be active at the same timebufferSize- the number of innerObservableSourceexpected to be buffered- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- Since:
- 3.0.0
-
create
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> create(@NonNull @NonNull ObservableOnSubscribe<@NonNull T> source) Provides an API (via a coldObservable) 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
Observersubscribes to the returnedObservable, the providedObservableOnSubscribecallback is invoked with a fresh instance of anObservableEmitterthat will interact only with that specificObserver. If thisObserverdisposes the flow (makingObservableEmitter.isDisposed()returntrue), other observers subscribed to the same returnedObservableare not affected.
You should call the
ObservableEmitter'sonNext,onErrorandonCompletemethods in a serialized fashion. The rest of its methods are thread-safe.- Scheduler:
createdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the element type- Parameters:
source- the emitter that is called when anObserversubscribes to the returnedObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourceisnull- See Also:
-
defer
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> defer(@NonNull @NonNull Supplier<? extends @NonNull ObservableSource<? extends @NonNull T>> supplier) Returns anObservablethat calls anObservableSourcefactory to create anObservableSourcefor each newObserverthat subscribes. That is, for each subscriber, the actualObservableSourcethat subscriber observes is determined by the factory function.
The
deferoperator allows you to defer or delay emitting items from anObservableSourceuntil such time as anObserversubscribes to theObservableSource. This allows anObserverto easily obtain updates or a refreshed version of the sequence.- Scheduler:
deferdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of the items emitted by theObservableSource- Parameters:
supplier- theObservableSourcefactory function to invoke for eachObserverthat subscribes to the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsupplierisnull- See Also:
-
empty
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> empty()Returns anObservablethat emits no items to theObserverand immediately invokes itsonCompletemethod.
- Scheduler:
emptydoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of the items (ostensibly) emitted by theObservable- Returns:
- the shared
Observableinstance - See Also:
-
error
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> error(@NonNull @NonNull Supplier<? extends @NonNull Throwable> supplier) Returns anObservablethat invokes anObserver'sonErrormethod when theObserversubscribes to it.
- Scheduler:
errordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of the items (ostensibly) emitted by theObservable- Parameters:
supplier- aSupplierfactory to return aThrowablefor each individualObserver- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsupplierisnull- See Also:
-
error
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> error(@NonNull @NonNull Throwable throwable) Returns anObservablethat invokes anObserver'sonErrormethod when theObserversubscribes to it.
- Scheduler:
errordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of the items (ostensibly) emitted by theObservable- Parameters:
throwable- the particularThrowableto pass toonError- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifthrowableisnull- See Also:
-
fromAction
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> fromAction(@NonNull @NonNull Action action) Returns anObservableinstance that runs the givenActionfor eachObserverand emits either its exception or simply completes.
- Scheduler:
fromActiondoes not operate by default on a particularScheduler.- Error handling:
- If the
Actionthrows an exception, the respectiveThrowableis delivered to the downstream viaObserver.onError(Throwable), except when the downstream has canceled the resultingObservablesource. In this latter case, theThrowableis delivered to the global error handler viaRxJavaPlugins.onError(Throwable)as anUndeliverableException.
- Type Parameters:
T- the target type- Parameters:
action- theActionto run for eachObserver- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifactionisnull- Since:
- 3.0.0
-
fromArray
@CheckReturnValue @SchedulerSupport("none") @NonNull @SafeVarargs public static <@NonNull T> @NonNull Observable<T> fromArray(@NonNull @NonNull T... items) Converts an array into anObservableSourcethat emits the items in the array.
- Scheduler:
fromArraydoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of items in the array and the type of items to be emitted by the resultingObservable- Parameters:
items- the array of elements- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitemsisnull- See Also:
-
fromCallable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> fromCallable(@NonNull @NonNull Callable<? extends @NonNull T> callable) Returns anObservablethat, 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
Observable. That is to say, it makes the function "lazy."- Scheduler:
fromCallabledoes not operate by default on a particularScheduler.- Error handling:
- If the
Callablethrows an exception, the respectiveThrowableis delivered to the downstream viaObserver.onError(Throwable), except when the downstream has disposed the currentObservablesource. In this latter case, theThrowableis delivered to the global error handler viaRxJavaPlugins.onError(Throwable)as anUndeliverableException.
- Type Parameters:
T- the type of the item returned by theCallableand emitted by theObservable- Parameters:
callable- a function, the execution of which should be deferred;fromCallablewill invoke this function only when an observer subscribes to theObservablethatfromCallablereturns- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifcallableisnull- Since:
- 2.0
- See Also:
-
fromCompletable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> fromCompletable(@NonNull @NonNull CompletableSource completableSource) Wraps aCompletableSourceinto anObservable.
- Scheduler:
fromCompletabledoes not operate by default on a particularScheduler.
- Type Parameters:
T- the target type- Parameters:
completableSource- theCompletableSourceto convert from- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifcompletableSourceisnull
-
fromFuture
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> fromFuture(@NonNull @NonNull Future<? extends @NonNull T> future) Converts aFutureinto anObservable.
The operator calls
Future.get(), which is a blocking method, on the subscription thread. It is recommended applyingsubscribeOn(Scheduler)to move this blocking wait to a background thread, and if theSchedulersupports it, interrupt the wait when the flow is disposed.Unlike 1.x, disposing the
Observablewon't cancel the future. If necessary, one can use composition to achieve the cancellation effect:futureObservableSource.doOnDispose(() -> future.cancel(true));.Also note that this operator will consume a
CompletionStage-basedFuturesubclass (such asCompletableFuture) in a blocking manner as well. Use thefromCompletionStage(CompletionStage)operator to convert and consume such sources in a non-blocking fashion instead.- Scheduler:
fromFuturedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of object that theFuturereturns, and also the type of item to be emitted by the resultingObservable- Parameters:
future- the sourceFuture- Returns:
- the new
Observableinstance - Throws:
NullPointerException- iffutureisnull- See Also:
-
fromFuture
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> fromFuture(@NonNull @NonNull Future<? extends @NonNull T> future, long timeout, @NonNull @NonNull TimeUnit unit) Converts aFutureinto anObservable, with a timeout on theFuture.
The operator calls
Future.get(long, TimeUnit), which is a blocking method, on the subscription thread. It is recommended applyingsubscribeOn(Scheduler)to move this blocking wait to a background thread, and if theSchedulersupports it, interrupt the wait when the flow is disposed.Unlike 1.x, disposing the
Observablewon't cancel the future. If necessary, one can use composition to achieve the cancellation effect:futureObservableSource.doOnDispose(() -> future.cancel(true));.Also note that this operator will consume a
CompletionStage-basedFuturesubclass (such asCompletableFuture) in a blocking manner as well. Use thefromCompletionStage(CompletionStage)operator to convert and consume such sources in a non-blocking fashion instead.- Scheduler:
fromFuturedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of object that theFuturereturns, and also the type of item to be emitted by the resultingObservable- Parameters:
future- the sourceFuturetimeout- the maximum time to wait before callinggetunit- theTimeUnitof thetimeoutargument- Returns:
- the new
Observableinstance - Throws:
NullPointerException- iffutureorunitisnull- See Also:
-
fromIterable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> fromIterable(@NonNull @NonNull Iterable<? extends @NonNull T> source) Converts anIterablesequence into anObservablethat emits the items in the sequence.
- Scheduler:
fromIterabledoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of items in theIterablesequence and the type of items to be emitted by the resultingObservable- Parameters:
source- the sourceIterablesequence- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourceisnull- See Also:
-
fromMaybe
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> fromMaybe(@NonNull @NonNull MaybeSource<@NonNull T> maybe) Returns anObservableinstance that when subscribed to, subscribes to theMaybeSourceinstance and emitsonSuccessas a single item or forwards anyonCompleteoronErrorsignal.
- Scheduler:
fromMaybedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type of theMaybeSourceelement- Parameters:
maybe- theMaybeSourceinstance to subscribe to, notnull- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmaybeisnull- Since:
- 3.0.0
-
fromPublisher
@BackpressureSupport(UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> fromPublisher(@NonNull @NonNull Flow.Publisher<? extends @NonNull T> publisher) Converts an arbitrary Reactive StreamsFlow.Publisherinto anObservable.
The
Publishermust follow the Reactive-Streams specification. Violating the specification may result in undefined behavior.If possible, use
create(ObservableOnSubscribe)to create a source-likeObservableinstead.Note that even though
Publisherappears 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
publisheris consumed in an unbounded fashion without applying any backpressure to it. - Scheduler:
fromPublisherdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type of the flow- Parameters:
publisher- thePublisherto convert- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifpublisherisnull- See Also:
-
fromRunnable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> fromRunnable(@NonNull @NonNull Runnable run) Returns anObservableinstance that runs the givenRunnablefor eachObserverand emits either its unchecked exception or simply completes.
If the code to be wrapped needs to throw a checked or more broader
Throwableexception, that exception has to be converted to an unchecked exception by the wrapped code itself. Alternatively, use thefromAction(Action)method which allows the wrapped code to throw anyThrowableexception and will signal it to observers as-is.- Scheduler:
fromRunnabledoes not operate by default on a particularScheduler.- Error handling:
- If the
Runnablethrows an exception, the respectiveThrowableis delivered to the downstream viaObserver.onError(Throwable), except when the downstream has canceled the resultingObservablesource. In this latter case, theThrowableis delivered to the global error handler viaRxJavaPlugins.onError(Throwable)as anUndeliverableException.
- Type Parameters:
T- the target type- Parameters:
run- theRunnableto run for eachObserver- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifrunisnull- Since:
- 3.0.0
- See Also:
-
fromSingle
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> fromSingle(@NonNull @NonNull SingleSource<@NonNull T> source) Returns anObservableinstance that when subscribed to, subscribes to theSingleSourceinstance and emitsonSuccessas a single item or forwards theonErrorsignal.
- Scheduler:
fromSingledoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type of theSingleSourceelement- Parameters:
source- theSingleSourceinstance to subscribe to, notnull- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourceisnull- Since:
- 3.0.0
-
fromSupplier
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> fromSupplier(@NonNull @NonNull Supplier<? extends @NonNull T> supplier) Returns anObservablethat, when an observer subscribes to it, invokes a supplier 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
Observable. That is to say, it makes the function "lazy."- Scheduler:
fromSupplierdoes not operate by default on a particularScheduler.- Error handling:
- If the
Supplierthrows an exception, the respectiveThrowableis delivered to the downstream viaObserver.onError(Throwable), except when the downstream has disposed the currentObservablesource. In this latter case, theThrowableis delivered to the global error handler viaRxJavaPlugins.onError(Throwable)as anUndeliverableException.
- Type Parameters:
T- the type of the item emitted by theObservable- Parameters:
supplier- a function, the execution of which should be deferred;fromSupplierwill invoke this function only when an observer subscribes to theObservablethatfromSupplierreturns- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsupplierisnull- Since:
- 3.0.0
- See Also:
-
generate
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> generate(@NonNull @NonNull Consumer<Emitter<@NonNull T>> generator) Returns a cold, synchronous and stateless generator of values.
Note that the
Emitter.onNext(T),Emitter.onError(Throwable)andEmitter.onComplete()methods provided to the function via theEmitterinstance should be called synchronously, never concurrently and only while the function body is executing. Calling them from multiple threads or outside the function call is not supported and leads to an undefined behavior.- Scheduler:
generatedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the generated value type- Parameters:
generator- theConsumercalled in a loop after a downstreamObserverhas subscribed. The callback then should callonNext,onErrororonCompleteto signal a value or a terminal event. Signaling multipleonNextin a call will make the operator signalIllegalStateException.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifgeneratorisnull
-
generate
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T, @NonNull S> @NonNull Observable<T> generate(@NonNull @NonNull Supplier<@NonNull S> initialState, @NonNull @NonNull BiConsumer<@NonNull S, Emitter<@NonNull T>> generator) Returns a cold, synchronous and stateful generator of values.
Note that the
Emitter.onNext(T),Emitter.onError(Throwable)andEmitter.onComplete()methods provided to the function via theEmitterinstance should be called synchronously, never concurrently and only while the function body is executing. Calling them from multiple threads or outside the function call is not supported and leads to an undefined behavior.- Scheduler:
generatedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the generated value typeS- the type of the per-Observerstate- Parameters:
initialState- theSupplierto generate the initial state for eachObservergenerator- theBiConsumercalled in a loop after a downstreamObserverhas subscribed. The callback then should callonNext,onErrororonCompleteto signal a value or a terminal event. Signaling multipleonNextin a call will make the operator signalIllegalStateException.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifinitialStateorgeneratorisnull
-
generate
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T, @NonNull S> @NonNull Observable<T> generate(@NonNull @NonNull Supplier<@NonNull S> initialState, @NonNull @NonNull BiConsumer<@NonNull S, Emitter<@NonNull T>> generator, @NonNull @NonNull Consumer<? super @NonNull S> disposeState) Returns a cold, synchronous and stateful generator of values.
Note that the
Emitter.onNext(T),Emitter.onError(Throwable)andEmitter.onComplete()methods provided to the function via theEmitterinstance should be called synchronously, never concurrently and only while the function body is executing. Calling them from multiple threads or outside the function call is not supported and leads to an undefined behavior.- Scheduler:
generatedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the generated value typeS- the type of the per-Observerstate- Parameters:
initialState- theSupplierto generate the initial state for eachObservergenerator- theBiConsumercalled in a loop after a downstreamObserverhas subscribed. The callback then should callonNext,onErrororonCompleteto signal a value or a terminal event. Signaling multipleonNextin a call will make the operator signalIllegalStateException.disposeState- theConsumerthat is called with the current state when the generator terminates the sequence or it gets disposed- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifinitialState,generatorordisposeStateisnull
-
generate
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T, @NonNull S> @NonNull Observable<T> generate(@NonNull @NonNull Supplier<@NonNull S> initialState, @NonNull @NonNull BiFunction<@NonNull S, Emitter<@NonNull T>, @NonNull S> generator) Returns a cold, synchronous and stateful generator of values.
Note that the
Emitter.onNext(T),Emitter.onError(Throwable)andEmitter.onComplete()methods provided to the function via theEmitterinstance should be called synchronously, never concurrently and only while the function body is executing. Calling them from multiple threads or outside the function call is not supported and leads to an undefined behavior.- Scheduler:
generatedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the generated value typeS- the type of the per-Observerstate- Parameters:
initialState- theSupplierto generate the initial state for eachObservergenerator- theBiConsumercalled in a loop after a downstreamObserverhas subscribed. The callback then should callonNext,onErrororonCompleteto signal a value or a terminal event and should return a (new) state for the next invocation. Signaling multipleonNextin a call will make the operator signalIllegalStateException.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifinitialStateorgeneratorisnull
-
generate
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T, @NonNull S> @NonNull Observable<T> generate(@NonNull @NonNull Supplier<@NonNull S> initialState, @NonNull @NonNull BiFunction<@NonNull S, Emitter<@NonNull T>, @NonNull S> generator, @NonNull @NonNull Consumer<? super @NonNull S> disposeState) Returns a cold, synchronous and stateful generator of values.
Note that the
Emitter.onNext(T),Emitter.onError(Throwable)andEmitter.onComplete()methods provided to the function via theEmitterinstance should be called synchronously, never concurrently and only while the function body is executing. Calling them from multiple threads or outside the function call is not supported and leads to an undefined behavior.- Scheduler:
generatedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the generated value typeS- the type of the per-Observerstate- Parameters:
initialState- theSupplierto generate the initial state for eachObservergenerator- theBiConsumercalled in a loop after a downstreamObserverhas subscribed. The callback then should callonNext,onErrororonCompleteto signal a value or a terminal event and should return a (new) state for the next invocation. Signaling multipleonNextin a call will make the operator signalIllegalStateException.disposeState- theConsumerthat is called with the current state when the generator terminates the sequence or it gets disposed- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifinitialState,generatorordisposeStateisnull
-
interval
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public static @NonNull Observable<Long> interval(long initialDelay, long period, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits a0Lafter theinitialDelayand ever increasing numbers after eachperiodof time thereafter.
- Scheduler:
intervaloperates by default on thecomputationScheduler.
- Parameters:
initialDelay- the initial delay time to wait before emitting the first value of 0Lperiod- the period of time between emissions of the subsequent numbersunit- the time unit for bothinitialDelayandperiod- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 1.0.12
- See Also:
-
interval
@CheckReturnValue @NonNull @SchedulerSupport("custom") public static @NonNull Observable<Long> interval(long initialDelay, long period, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits a0Lafter theinitialDelayand ever increasing numbers after eachperiodof time thereafter, on a specifiedScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
initialDelay- the initial delay time to wait before emitting the first value of 0Lperiod- the period of time between emissions of the subsequent numbersunit- the time unit for bothinitialDelayandperiodscheduler- theScheduleron which the waiting happens and items are emitted- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- Since:
- 1.0.12
- See Also:
-
interval
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public static @NonNull Observable<Long> interval(long period, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits a sequential number every specified interval of time.
- Scheduler:
intervaloperates by default on thecomputationScheduler.
- Parameters:
period- the period size in time units (see below)unit- time units to use for the interval size- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
interval
@CheckReturnValue @SchedulerSupport("custom") @NonNull public static @NonNull Observable<Long> interval(long period, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits a sequential number every specified interval of time, on a specifiedScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
period- the period size in time units (see below)unit- time units to use for the interval sizescheduler- theSchedulerto use for scheduling the items- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
intervalRange
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public static @NonNull Observable<Long> intervalRange(long start, long count, long initialDelay, long period, @NonNull @NonNull TimeUnit unit) Signals a range of long values, the first after some initial delay and the rest periodically after.The sequence completes immediately after the last value (start + count - 1) has been reached.
- Scheduler:
intervalRangeby default operates on thecomputationScheduler.
- Parameters:
start- that start value of the rangecount- the number of values to emit in total, if zero, the operator emits anonCompleteafter the initial delay.initialDelay- the initial delay before signaling the first value (the start)period- the period between subsequent valuesunit- the unit of measure of theinitialDelayandperiodamounts- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnullIllegalArgumentException- ifcountis negative, or ifstart+count− 1 exceedsLong.MAX_VALUE- See Also:
-
intervalRange
@CheckReturnValue @NonNull @SchedulerSupport("custom") public static @NonNull Observable<Long> intervalRange(long start, long count, long initialDelay, long period, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Signals a range of long values, the first after some initial delay and the rest periodically after.The sequence completes immediately after the last value (start + count - 1) has been reached.
* - Scheduler:
- you provide the
Scheduler.
- Parameters:
start- that start value of the rangecount- the number of values to emit in total, if zero, the operator emits anonCompleteafter the initial delay.initialDelay- the initial delay before signaling the first value (the start)period- the period between subsequent valuesunit- the unit of measure of theinitialDelayandperiodamountsscheduler- the target scheduler where the values and terminal signals will be emitted- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnullIllegalArgumentException- ifcountis negative, or ifstart+count− 1 exceedsLong.MAX_VALUE
-
just
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> just(@NonNull @NonNull T item) Returns anObservablethat signals the given (constant reference) item and then completes.
Note that the item is taken and re-emitted as is and not computed by any means by
just. UsefromCallable(Callable)to generate a single item on demand (whenObservers subscribe to it).See the multi-parameter overloads of
justto emit more than one (constant reference) items one after the other. UsefromArray(Object...)to emit an arbitrary number of items that are known upfront.To emit the items of an
Iterablesequence (such as aList), usefromIterable(Iterable).- Scheduler:
justdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of that item- Parameters:
item- the item to emit- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitemisnull- See Also:
-
just
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> just(@NonNull @NonNull T item1, @NonNull @NonNull T item2) Converts two items into anObservablethat emits those items.
- Scheduler:
justdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of these items- Parameters:
item1- first itemitem2- second item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitem1oritem2isnull- See Also:
-
just
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> just(@NonNull @NonNull T item1, @NonNull @NonNull T item2, @NonNull @NonNull T item3) Converts three items into anObservablethat emits those items.
- Scheduler:
justdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of these items- Parameters:
item1- first itemitem2- second itemitem3- third item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitem1,item2oritem3isnull- See Also:
-
just
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> just(@NonNull @NonNull T item1, @NonNull @NonNull T item2, @NonNull @NonNull T item3, @NonNull @NonNull T item4) Converts four items into anObservablethat emits those items.
- Scheduler:
justdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of these items- Parameters:
item1- first itemitem2- second itemitem3- third itemitem4- fourth item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitem1,item2,item3oritem4isnull- See Also:
-
just
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> just(@NonNull @NonNull T item1, @NonNull @NonNull T item2, @NonNull @NonNull T item3, @NonNull @NonNull T item4, @NonNull @NonNull T item5) Converts five items into anObservablethat emits those items.
- Scheduler:
justdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of these items- Parameters:
item1- first itemitem2- second itemitem3- third itemitem4- fourth itemitem5- fifth item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitem1,item2,item3,item4oritem5isnull- See Also:
-
just
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> just(@NonNull @NonNull T item1, @NonNull @NonNull T item2, @NonNull @NonNull T item3, @NonNull @NonNull T item4, @NonNull @NonNull T item5, @NonNull @NonNull T item6) Converts six items into anObservablethat emits those items.
- Scheduler:
justdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of these items- Parameters:
item1- first itemitem2- second itemitem3- third itemitem4- fourth itemitem5- fifth itemitem6- sixth item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitem1,item2,item3,item4,item5oritem6isnull- See Also:
-
just
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> just(@NonNull @NonNull T item1, @NonNull @NonNull T item2, @NonNull @NonNull T item3, @NonNull @NonNull T item4, @NonNull @NonNull T item5, @NonNull @NonNull T item6, @NonNull @NonNull T item7) Converts seven items into anObservablethat emits those items.
- Scheduler:
justdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of these items- Parameters:
item1- first itemitem2- second itemitem3- third itemitem4- fourth itemitem5- fifth itemitem6- sixth itemitem7- seventh item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitem1,item2,item3,item4,item5,item6oritem7isnull- See Also:
-
just
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> just(@NonNull @NonNull T item1, @NonNull @NonNull T item2, @NonNull @NonNull T item3, @NonNull @NonNull T item4, @NonNull @NonNull T item5, @NonNull @NonNull T item6, @NonNull @NonNull T item7, @NonNull @NonNull T item8) Converts eight items into anObservablethat emits those items.
- Scheduler:
justdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of these items- Parameters:
item1- first itemitem2- second itemitem3- third itemitem4- fourth itemitem5- fifth itemitem6- sixth itemitem7- seventh itemitem8- eighth item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitem1,item2,item3,item4,item5,item6item7oritem8isnull- See Also:
-
just
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> just(@NonNull @NonNull T item1, @NonNull @NonNull T item2, @NonNull @NonNull T item3, @NonNull @NonNull T item4, @NonNull @NonNull T item5, @NonNull @NonNull T item6, @NonNull @NonNull T item7, @NonNull @NonNull T item8, @NonNull @NonNull T item9) Converts nine items into anObservablethat emits those items.
- Scheduler:
justdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of these items- Parameters:
item1- first itemitem2- second itemitem3- third itemitem4- fourth itemitem5- fifth itemitem6- sixth itemitem7- seventh itemitem8- eighth itemitem9- ninth item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitem1,item2,item3,item4,item5,item6item7,item8oritem9isnull- See Also:
-
just
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> just(@NonNull @NonNull T item1, @NonNull @NonNull T item2, @NonNull @NonNull T item3, @NonNull @NonNull T item4, @NonNull @NonNull T item5, @NonNull @NonNull T item6, @NonNull @NonNull T item7, @NonNull @NonNull T item8, @NonNull @NonNull T item9, @NonNull @NonNull T item10) Converts ten items into anObservablethat emits those items.
- Scheduler:
justdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of these items- Parameters:
item1- first itemitem2- second itemitem3- third itemitem4- fourth itemitem5- fifth itemitem6- sixth itemitem7- seventh itemitem8- eighth itemitem9- ninth itemitem10- tenth item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitem1,item2,item3,item4,item5,item6item7,item8,item9oritem10isnull- See Also:
-
merge
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> merge(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency, int bufferSize) Flattens anIterableofObservableSources into oneObservable, without any transformation, while limiting the number of concurrent subscriptions to theseObservableSources.
You can combine the items emitted by multiple
ObservableSources so that they appear as a singleObservableSource, by using themergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the returned
ObservableSources signal aThrowableviaonError, the resultingObservableterminates with thatThrowableand all other sourceObservableSources are disposed. If more than oneObservableSourcesignals an error, the resultingObservablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedObservablehas been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(Iterable, int, int)to merge sources and terminate only when all sourceObservableSources have completed or failed with an error.
- Type Parameters:
T- the common element base type- Parameters:
sources- theIterableofObservableSourcesmaxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrentlybufferSize- the number of items expected from each innerObservableSourceto be buffered- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- See Also:
-
mergeArray
@CheckReturnValue @SchedulerSupport("none") @NonNull @SafeVarargs public static <@NonNull T> @NonNull Observable<T> mergeArray(int maxConcurrency, int bufferSize, @NonNull @NonNull ObservableSource<? extends @NonNull T>... sources) Flattens an array ofObservableSources into oneObservable, without any transformation, while limiting the number of concurrent subscriptions to theseObservableSources.
You can combine the items emitted by multiple
ObservableSources so that they appear as a singleObservableSource, by using themergemethod.- Scheduler:
mergeArraydoes not operate by default on a particularScheduler.- Error handling:
- If any of the
ObservableSources signal aThrowableviaonError, the resultingObservableterminates with thatThrowableand all other sourceObservableSources are disposed. If more than oneObservableSourcesignals an error, the resultingObservablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedObservablehas been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeArrayDelayError(int, int, ObservableSource...)to merge sources and terminate only when all sourceObservableSources have completed or failed with an error.
- Type Parameters:
T- the common element base type- Parameters:
maxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrentlybufferSize- the number of items expected from each innerObservableSourceto be bufferedsources- the array ofObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- See Also:
-
merge
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> merge(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources) Flattens anIterableofObservableSources into oneObservable, without any transformation.
You can combine the items emitted by multiple
ObservableSources so that they appear as a singleObservableSource, by using themergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the returned
ObservableSources signal aThrowableviaonError, the resultingObservableterminates with thatThrowableand all other sourceObservableSources are disposed. If more than oneObservableSourcesignals an error, the resultingObservablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedObservablehas been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(Iterable)to merge sources and terminate only when all sourceObservableSources have completed or failed with an error.
- Type Parameters:
T- the common element base type- Parameters:
sources- theIterableofObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
merge
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> merge(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency) Flattens anIterableofObservableSources into oneObservable, without any transformation, while limiting the number of concurrent subscriptions to theseObservableSources.
You can combine the items emitted by multiple
ObservableSources so that they appear as a singleObservableSource, by using themergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the returned
ObservableSources signal aThrowableviaonError, the resultingObservableterminates with thatThrowableand all other sourceObservableSources are disposed. If more than oneObservableSourcesignals an error, the resultingObservablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedObservablehas been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(Iterable, int)to merge sources and terminate only when all sourceObservableSources have completed or failed with an error.
- Type Parameters:
T- the common element base type- Parameters:
sources- theIterableofObservableSourcesmaxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrently- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis less than or equal to 0- See Also:
-
merge
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> merge(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Flattens anObservableSourcethat emitsObservableSources into a singleObservablethat emits the items emitted by thoseObservableSources, without any transformation.
You can combine the items emitted by multiple
ObservableSources so that they appear as a singleObservableSource, by using themergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the returned
ObservableSources signal aThrowableviaonError, the resultingObservableterminates with thatThrowableand all other sourceObservableSources are disposed. If more than oneObservableSourcesignals an error, the resultingObservablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedObservablehas been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(ObservableSource)to merge sources and terminate only when all sourceObservableSources have completed or failed with an error.
- Type Parameters:
T- the common element base type- Parameters:
sources- anObservableSourcethat emitsObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
merge
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> merge(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency) Flattens anObservableSourcethat emitsObservableSources into a singleObservablethat emits the items emitted by thoseObservableSources, without any transformation, while limiting the maximum number of concurrent subscriptions to theseObservableSources.
You can combine the items emitted by multiple
ObservableSources so that they appear as a singleObservableSource, by using themergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the returned
ObservableSources signal aThrowableviaonError, the resultingObservableterminates with thatThrowableand all other sourceObservableSources are disposed. If more than oneObservableSourcesignals an error, the resultingObservablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedObservablehas been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(ObservableSource, int)to merge sources and terminate only when all sourceObservableSources have completed or failed with an error.
- Type Parameters:
T- the common element base type- Parameters:
sources- anObservableSourcethat emitsObservableSourcesmaxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrently- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 1.1.0
- See Also:
-
merge
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> merge(@NonNull @NonNull ObservableSource<? extends @NonNull T> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T> source2) Flattens twoObservableSources into a singleObservable, without any transformation.
You can combine items emitted by multiple
ObservableSources so that they appear as a singleObservableSource, by using themergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the
ObservableSources signal aThrowableviaonError, the resultingObservableterminates with thatThrowableand all other sourceObservableSources are disposed. If more than oneObservableSourcesignals an error, the resultingObservablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedObservablehas been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(ObservableSource, ObservableSource)to merge sources and terminate only when all sourceObservableSources have completed or failed with an error.
- Type Parameters:
T- the common element base type- Parameters:
source1- anObservableSourceto be mergedsource2- anObservableSourceto be merged- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1orsource2isnull- See Also:
-
merge
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> merge(@NonNull @NonNull ObservableSource<? extends @NonNull T> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T> source3) Flattens threeObservableSources into a singleObservable, without any transformation.
You can combine items emitted by multiple
ObservableSources so that they appear as a singleObservableSource, by using themergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the
ObservableSources signal aThrowableviaonError, the resultingObservableterminates with thatThrowableand all other sourceObservableSources are disposed. If more than oneObservableSourcesignals an error, the resultingObservablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedObservablehas been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(ObservableSource, ObservableSource, ObservableSource)to merge sources and terminate only when all sourceObservableSources have completed or failed with an error.
- Type Parameters:
T- the common element base type- Parameters:
source1- anObservableSourceto be mergedsource2- anObservableSourceto be mergedsource3- anObservableSourceto be merged- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2orsource3isnull- See Also:
-
merge
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> merge(@NonNull @NonNull ObservableSource<? extends @NonNull T> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T> source4) Flattens fourObservableSources into a singleObservable, without any transformation.
You can combine items emitted by multiple
ObservableSources so that they appear as a singleObservableSource, by using themergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the
ObservableSources signal aThrowableviaonError, the resultingObservableterminates with thatThrowableand all other sourceObservableSources are disposed. If more than oneObservableSourcesignals an error, the resultingObservablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedObservablehas been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(ObservableSource, ObservableSource, ObservableSource, ObservableSource)to merge sources and terminate only when all sourceObservableSources have completed or failed with an error.
- Type Parameters:
T- the common element base type- Parameters:
source1- anObservableSourceto be mergedsource2- anObservableSourceto be mergedsource3- anObservableSourceto be mergedsource4- anObservableSourceto be merged- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3orsource4isnull- See Also:
-
mergeArray
@CheckReturnValue @SchedulerSupport("none") @NonNull @SafeVarargs public static <@NonNull T> @NonNull Observable<T> mergeArray(@NonNull @NonNull ObservableSource<? extends @NonNull T>... sources) Flattens an array ofObservableSources into oneObservable, without any transformation.
You can combine items emitted by multiple
ObservableSources so that they appear as a singleObservableSource, by using themergemethod.- Scheduler:
mergeArraydoes not operate by default on a particularScheduler.- Error handling:
- If any of the
ObservableSources signal aThrowableviaonError, the resultingObservableterminates with thatThrowableand all other sourceObservableSources are disposed. If more than oneObservableSourcesignals an error, the resultingObservablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedObservablehas been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeArrayDelayError(ObservableSource...)to merge sources and terminate only when all sourceObservableSources have completed or failed with an error.
- Type Parameters:
T- the common element base type- Parameters:
sources- the array ofObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
mergeDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> mergeDelayError(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources) Flattens anIterableofObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from each of the returnedObservableSources without being interrupted by an error notification from one of them.This behaves like
merge(ObservableSource)except that if any of the mergedObservableSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedObservableSources have finished emitting items.
Even if multiple merged
ObservableSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of itsObservers once.- Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- theIterableofObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
mergeDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> mergeDelayError(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency, int bufferSize) Flattens anIterableofObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from each of the returnedObservableSources without being interrupted by an error notification from one of them, while limiting the number of concurrent subscriptions to theseObservableSources.This behaves like
merge(ObservableSource)except that if any of the mergedObservableSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedObservableSources have finished emitting items.
Even if multiple merged
ObservableSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of itsObservers once.- Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- theIterableofObservableSourcesmaxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrentlybufferSize- the number of items expected from each innerObservableSourceto be buffered- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- See Also:
-
mergeArrayDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull @SafeVarargs public static <@NonNull T> @NonNull Observable<T> mergeArrayDelayError(int maxConcurrency, int bufferSize, @NonNull @NonNull ObservableSource<? extends @NonNull T>... sources) Flattens an array ofObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from each of theObservableSources without being interrupted by an error notification from one of them, while limiting the number of concurrent subscriptions to theseObservableSources.This behaves like
merge(ObservableSource)except that if any of the mergedObservableSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedObservableSources have finished emitting items.
Even if multiple merged
ObservableSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of itsObservers once.- Scheduler:
mergeArrayDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
maxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrentlybufferSize- the number of items expected from each innerObservableSourceto be bufferedsources- the array ofObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- See Also:
-
mergeDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> mergeDelayError(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency) Flattens anIterableofObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from each of the returnedObservableSources without being interrupted by an error notification from one of them, while limiting the number of concurrent subscriptions to theseObservableSources.This behaves like
merge(ObservableSource)except that if any of the mergedObservableSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedObservableSources have finished emitting items.
Even if multiple merged
ObservableSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of itsObservers once.- Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- theIterableofObservableSourcesmaxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrently- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- See Also:
-
mergeDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> mergeDelayError(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Flattens anObservableSourcethat emitsObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from all of the emittedObservableSources without being interrupted by an error notification from one of them.This behaves like
merge(ObservableSource)except that if any of the mergedObservableSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedObservableSources have finished emitting items.
Even if multiple merged
ObservableSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of itsObservers once.- Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- anObservableSourcethat emitsObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
mergeDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> mergeDelayError(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int maxConcurrency) Flattens anObservableSourcethat emitsObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from all of the emittedObservableSources without being interrupted by an error notification from one of them, while limiting the number of concurrent subscriptions to theseObservableSources.This behaves like
merge(ObservableSource)except that if any of the mergedObservableSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedObservableSources have finished emitting items.
Even if multiple merged
ObservableSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of itsObservers once.- Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- anObservableSourcethat emitsObservableSourcesmaxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrently- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 2.0
- See Also:
-
mergeDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> mergeDelayError(@NonNull @NonNull ObservableSource<? extends @NonNull T> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T> source2) Flattens twoObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from each of theObservableSources without being interrupted by an error notification from one of them.This behaves like
merge(ObservableSource, ObservableSource)except that if any of the mergedObservableSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedObservableSources have finished emitting items.
Even if both merged
ObservableSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of itsObservers once.- Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
source1- anObservableSourceto be mergedsource2- anObservableSourceto be merged- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1orsource2isnull- See Also:
-
mergeDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> mergeDelayError(@NonNull @NonNull ObservableSource<? extends @NonNull T> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T> source3) Flattens threeObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from all of theObservableSources without being interrupted by an error notification from one of them.This behaves like
merge(ObservableSource, ObservableSource, ObservableSource)except that if any of the mergedObservableSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedObservableSources have finished emitting items.
Even if multiple merged
ObservableSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of itsObservers once.- Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
source1- anObservableSourceto be mergedsource2- anObservableSourceto be mergedsource3- anObservableSourceto be merged- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2orsource3isnull- See Also:
-
mergeDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> mergeDelayError(@NonNull @NonNull ObservableSource<? extends @NonNull T> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T> source4) Flattens fourObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from all of theObservableSources without being interrupted by an error notification from one of them.This behaves like
merge(ObservableSource, ObservableSource, ObservableSource, ObservableSource)except that if any of the mergedObservableSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedObservableSources have finished emitting items.
Even if multiple merged
ObservableSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of itsObservers once.- Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
source1- anObservableSourceto be mergedsource2- anObservableSourceto be mergedsource3- anObservableSourceto be mergedsource4- anObservableSourceto be merged- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3orsource4isnull- See Also:
-
mergeArrayDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull @SafeVarargs public static <@NonNull T> @NonNull Observable<T> mergeArrayDelayError(@NonNull @NonNull ObservableSource<? extends @NonNull T>... sources) Flattens an array ofObservableSources into oneObservable, in a way that allows anObserverto receive all successfully emitted items from each of theObservableSources without being interrupted by an error notification from one of them.This behaves like
merge(ObservableSource)except that if any of the mergedObservableSources notify of an error viaonError,mergeDelayErrorwill refrain from propagating that error notification until all of the mergedObservableSources have finished emitting items.
Even if multiple merged
ObservableSources sendonErrornotifications,mergeDelayErrorwill only invoke theonErrormethod of itsObservers once.- Scheduler:
mergeArrayDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- the array ofObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
never
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> never()Returns anObservablethat never sends any items or notifications to anObserver.
The returned
Observableis useful primarily for testing purposes.- Scheduler:
neverdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of items (not) emitted by theObservable- Returns:
- the shared
Observableinstance - See Also:
-
range
@CheckReturnValue @SchedulerSupport("none") @NonNull public static @NonNull Observable<Integer> range(int start, int count) Returns anObservablethat emits a sequence ofIntegers within a specified range.
- Scheduler:
rangedoes not operate by default on a particularScheduler.
- Parameters:
start- the value of the firstIntegerin the sequencecount- the number of sequentialIntegers to generate- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- ifcountis negative, or ifstart+count− 1 exceedsInteger.MAX_VALUE- See Also:
-
rangeLong
@CheckReturnValue @SchedulerSupport("none") @NonNull public static @NonNull Observable<Long> rangeLong(long start, long count) Returns anObservablethat emits a sequence ofLongs within a specified range.
- Scheduler:
rangeLongdoes not operate by default on a particularScheduler.
- Parameters:
start- the value of the firstLongin the sequencecount- the number of sequentialLongs to generate- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- ifcountis negative, or ifstart+count− 1 exceedsLong.MAX_VALUE- See Also:
-
sequenceEqual
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<Boolean> sequenceEqual(@NonNull @NonNull ObservableSource<? extends @NonNull T> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T> source2) Returns aSinglethat emits aBooleanvalue that indicates whether twoObservableSourcesequences are the same by comparing the items emitted by eachObservableSourcepairwise.
- Scheduler:
sequenceEqualdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of items emitted by eachObservableSource- Parameters:
source1- the firstObservableSourceto comparesource2- the secondObservableSourceto compare- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsource1orsource2isnull- See Also:
-
sequenceEqual
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<Boolean> sequenceEqual(@NonNull @NonNull ObservableSource<? extends @NonNull T> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull @NonNull BiPredicate<? super @NonNull T, ? super @NonNull T> isEqual) Returns aSinglethat emits aBooleanvalue that indicates whether twoObservableSourcesequences are the same by comparing the items emitted by eachObservableSourcepairwise based on the results of a specified equality function.
- Scheduler:
sequenceEqualdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of items emitted by eachObservableSource- Parameters:
source1- the firstObservableSourceto comparesource2- the secondObservableSourceto compareisEqual- a function used to compare items emitted by eachObservableSource- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsource1,source2orisEqualisnull- See Also:
-
sequenceEqual
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<Boolean> sequenceEqual(@NonNull @NonNull ObservableSource<? extends @NonNull T> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T> source2, @NonNull @NonNull BiPredicate<? super @NonNull T, ? super @NonNull T> isEqual, int bufferSize) Returns aSinglethat emits aBooleanvalue that indicates whether twoObservableSourcesequences are the same by comparing the items emitted by eachObservableSourcepairwise based on the results of a specified equality function.
- Scheduler:
sequenceEqualdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of items emitted by eachObservableSource- Parameters:
source1- the firstObservableSourceto comparesource2- the secondObservableSourceto compareisEqual- a function used to compare items emitted by eachObservableSourcebufferSize- the number of items expected from the first and second sourceObservableSourceto be buffered- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsource1,source2orisEqualisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
sequenceEqual
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<Boolean> sequenceEqual(@NonNull @NonNull ObservableSource<? extends @NonNull T> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T> source2, int bufferSize) Returns aSinglethat emits aBooleanvalue that indicates whether twoObservableSourcesequences are the same by comparing the items emitted by eachObservableSourcepairwise.
- Scheduler:
sequenceEqualdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of items emitted by eachObservableSource- Parameters:
source1- the firstObservableSourceto comparesource2- the secondObservableSourceto comparebufferSize- the number of items expected from the first and second sourceObservableSourceto be buffered- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsource1orsource2isnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
switchOnNext
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> switchOnNext(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int bufferSize) Converts anObservableSourcethat emitsObservableSources into anObservablethat emits the items emitted by the most recently emitted of thoseObservableSources.
switchOnNextsubscribes to anObservableSourcethat emitsObservableSources. Each time it observes one of these emittedObservableSources, theObservableSourcereturned byswitchOnNextbegins emitting the items emitted by thatObservableSource. When a new innerObservableSourceis emitted,switchOnNextstops emitting items from the earlier-emittedObservableSourceand begins emitting items from the new one.The resulting
Observablecompletes if both the outerObservableSourceand the last innerObservableSource, if any, complete. If the outerObservableSourcesignals anonError, the innerObservableSourceis disposed and the error delivered in-sequence.- Scheduler:
switchOnNextdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the item type- Parameters:
sources- theObservableSourcethat emitsObservableSourcesbufferSize- the expected number of items to cache from the innerObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
switchOnNext
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> switchOnNext(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Converts anObservableSourcethat emitsObservableSources into anObservablethat emits the items emitted by the most recently emitted of thoseObservableSources.
switchOnNextsubscribes to anObservableSourcethat emitsObservableSources. Each time it observes one of these emittedObservableSources, theObservableSourcereturned byswitchOnNextbegins emitting the items emitted by thatObservableSource. When a new innerObservableSourceis emitted,switchOnNextstops emitting items from the earlier-emittedObservableSourceand begins emitting items from the new one.The resulting
Observablecompletes if both the outerObservableSourceand the last innerObservableSource, if any, complete. If the outerObservableSourcesignals anonError, the innerObservableSourceis disposed and the error delivered in-sequence.- Scheduler:
switchOnNextdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the item type- Parameters:
sources- theObservableSourcethat emitsObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
switchOnNextDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> switchOnNextDelayError(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources) Converts anObservableSourcethat emitsObservableSources into anObservablethat emits the items emitted by the most recently emitted of thoseObservableSources and delays any exception until allObservableSources terminate.
switchOnNextsubscribes to anObservableSourcethat emitsObservableSources. Each time it observes one of these emittedObservableSources, theObservableSourcereturned byswitchOnNextbegins emitting the items emitted by thatObservableSource. When a new innerObservableSourceis emitted,switchOnNextstops emitting items from the earlier-emittedObservableSourceand begins emitting items from the new one.The resulting
Observablecompletes if both the mainObservableSourceand the last innerObservableSource, if any, complete. If the mainObservableSourcesignals anonError, the termination of the last innerObservableSourcewill emit that error as is or wrapped into aCompositeExceptionalong with the other possible errors the former innerObservableSources signaled.- Scheduler:
switchOnNextDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the item type- Parameters:
sources- theObservableSourcethat emitsObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.0
- See Also:
-
switchOnNextDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> switchOnNextDelayError(@NonNull @NonNull ObservableSource<? extends ObservableSource<? extends @NonNull T>> sources, int bufferSize) Converts anObservableSourcethat emitsObservableSources into anObservablethat emits the items emitted by the most recently emitted of thoseObservableSources and delays any exception until allObservableSources terminate.
switchOnNextsubscribes to anObservableSourcethat emitsObservableSources. Each time it observes one of these emittedObservableSources, theObservableSourcereturned byswitchOnNextbegins emitting the items emitted by thatObservableSource. When a new innerObservableSourceis emitted,switchOnNextstops emitting items from the earlier-emittedObservableSourceand begins emitting items from the new one.The resulting
Observablecompletes if both the mainObservableSourceand the last innerObservableSource, if any, complete. If the mainObservableSourcesignals anonError, the termination of the last innerObservableSourcewill emit that error as is or wrapped into aCompositeExceptionalong with the other possible errors the former innerObservableSources signaled.- Scheduler:
switchOnNextDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the item type- Parameters:
sources- theObservableSourcethat emitsObservableSourcesbufferSize- the expected number of items to cache from the innerObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifbufferSizeis non-positive- Since:
- 2.0
- See Also:
-
timer
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public static @NonNull Observable<Long> timer(long delay, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits0Lafter a specified delay, and then completes.
- Scheduler:
timeroperates by default on thecomputationScheduler.
- Parameters:
delay- the initial delay before emitting a single0Lunit- time units to use fordelay- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
timer
@CheckReturnValue @SchedulerSupport("custom") @NonNull public static @NonNull Observable<Long> timer(long delay, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits0Lafter a specified delay, on a specifiedScheduler, and then completes.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
delay- the initial delay before emitting a single 0Lunit- time units to use fordelayscheduler- theSchedulerto use for scheduling the item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
unsafeCreate
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> unsafeCreate(@NonNull @NonNull ObservableSource<@NonNull T> onSubscribe) Create anObservableby wrapping anObservableSourcewhich has to be implemented according to theObservablespecification derived from the Reactive Streams specification by handling disposal correctly; no safeguards are provided by theObservableitself.- Scheduler:
unsafeCreateby default doesn't operate on any particularScheduler.
- Type Parameters:
T- the value type emitted- Parameters:
onSubscribe- theObservableSourceinstance to wrap- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonSubscribeisnullIllegalArgumentException- if theonSubscribeis already anObservable, usewrap(ObservableSource)in this case- See Also:
-
using
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T, @NonNull D> @NonNull Observable<T> using(@NonNull @NonNull Supplier<? extends @NonNull D> resourceSupplier, @NonNull @NonNull Function<? super @NonNull D, ? extends ObservableSource<? extends @NonNull T>> sourceSupplier, @NonNull @NonNull Consumer<? super @NonNull D> resourceCleanup) Constructs anObservablethat creates a dependent resource object, anObservableSourcewith that resource and calls the providedresourceDisposerfunction if this inner source terminates or the downstream disposes the flow.
- Scheduler:
usingdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the element type of the generatedObservableD- the type of the resource associated with the output sequence- Parameters:
resourceSupplier- the factory function to create a resource object that depends on theObservableSourcesourceSupplier- the factory function to create anObservableSourceresourceCleanup- the function that will dispose of the resource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifresourceSupplier,sourceSupplierorresourceCleanupisnull- See Also:
-
using
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T, @NonNull D> @NonNull Observable<T> using(@NonNull @NonNull Supplier<? extends @NonNull D> resourceSupplier, @NonNull @NonNull Function<? super @NonNull D, ? extends ObservableSource<? extends @NonNull T>> sourceSupplier, @NonNull @NonNull Consumer<? super @NonNull D> resourceCleanup, boolean eager) Constructs anObservablethat creates a dependent resource object, anObservableSourcewith that resource and calls the provideddisposerfunction if this inner source terminates or the downstream disposes the flow; doing it before these end-states have been reached ifeager == true, after otherwise.
- Scheduler:
usingdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the element type of the generatedObservableSourceD- the type of the resource associated with the output sequence- Parameters:
resourceSupplier- the factory function to create a resource object that depends on theObservableSourcesourceSupplier- the factory function to create anObservableSourceresourceCleanup- the function that will dispose of the resourceeager- Iftrue, the resource disposal will happen either on adispose()call before the upstream is disposed or just before the emission of a terminal event (onCompleteoronError). Iffalse, the resource disposal will happen either on adispose()call after the upstream is disposed or just after the emission of a terminal event (onCompleteoronError).- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifresourceSupplier,sourceSupplierandresourceCleanupisnull- Since:
- 2.0
- See Also:
-
wrap
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<T> wrap(@NonNull @NonNull ObservableSource<@NonNull T> source) Wraps anObservableSourceinto anObservableif not already anObservable.- Scheduler:
wrapdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
source- theObservableSourceinstance to wrap or cast toObservable- Returns:
- the new
Observableinstance or the same as the source - Throws:
NullPointerException- ifsourceisnull
-
zip
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T, @NonNull R> @NonNull Observable<R> zip(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, @NonNull @NonNull Function<? super Object[], ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by anIterableof otherObservableSources.zipapplies this function in strict sequence, so the first item emitted by the resultingObservablewill be the result of the function applied to the first item emitted by each of theObservableSources; the second item emitted by the resultingObservablewill be the result of the function applied to the second item emitted by each of thoseObservableSources; and so forth.The resulting
Observable<R>returned fromzipwill invokeonNextas many times as the number ofonNextinvocations of theObservableSourcethat emits the fewest items.The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:zip(Arrays.asList(range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2)), (a) -> a)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.Note on method signature: since Java doesn't allow creating a generic array with
new T[], the implementation of this operator has to create anObject[]instead. Unfortunately, aFunction<Integer[], R>passed to the method would trigger aClassCastException.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value typeR- the zipped result type- Parameters:
sources- anIterableof sourceObservableSourceszipper- a function that, when applied to an item emitted by each of theObservableSources, results in an item that will be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesorzipperisnull- See Also:
-
zip
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T, @NonNull R> @NonNull Observable<R> zip(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<? extends @NonNull T>> sources, @NonNull @NonNull Function<? super Object[], ? extends @NonNull R> zipper, boolean delayError, int bufferSize) Returns anObservablethat emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by anIterableof otherObservableSources.zipapplies this function in strict sequence, so the first item emitted by the resultingObservablewill be the result of the function applied to the first item emitted by each of theObservableSources; the second item emitted by the resultingObservablewill be the result of the function applied to the second item emitted by each of thoseObservableSources; and so forth.The resulting
Observable<R>returned fromzipwill invokeonNextas many times as the number ofonNextinvocations of theObservableSourcethat emits the fewest items.The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:zip(Arrays.asList(range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2)), (a) -> a)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.Note on method signature: since Java doesn't allow creating a generic array with
new T[], the implementation of this operator has to create anObject[]instead. Unfortunately, aFunction<Integer[], R>passed to the method would trigger aClassCastException.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common source value typeR- the zipped result type- Parameters:
sources- anIterableof sourceObservableSourceszipper- a function that, when applied to an item emitted by each of theObservableSources, results in an item that will be emitted by the resultingObservabledelayError- delay errors signaled by any of theObservableSourceuntil allObservableSources terminatebufferSize- the number of elements expected from each sourceObservableSourceto be buffered- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesorzipperisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
zip
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T1, @NonNull T2, @NonNull R> @NonNull Observable<R> zip(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull BiFunction<? super @NonNull T1, ? super @NonNull T2, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of two items emitted, in sequence, by two otherObservableSources.
zipapplies this function in strict sequence, so the first item emitted by the resultingObservablewill be the result of the function applied to the first item emitted byo1and the first item emitted byo2; the second item emitted by the resultingObservablewill be the result of the function applied to the second item emitted byo1and the second item emitted byo2; and so forth.The resulting
Observable<R>returned fromzipwill invokeonNextas many times as the number ofonNextinvocations of theObservableSourcethat emits the fewest items.The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:zip(range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2), (a, b) -> a + b)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the value type of the first sourceT2- the value type of the second sourceR- the zipped result type- Parameters:
source1- the first sourceObservableSourcesource2- a second sourceObservableSourcezipper- a function that, when applied to an item emitted by each of theObservableSources, results in an item that will be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2orzipperisnull- See Also:
-
zip
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T1, @NonNull T2, @NonNull R> @NonNull Observable<R> zip(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull BiFunction<? super @NonNull T1, ? super @NonNull T2, ? extends @NonNull R> zipper, boolean delayError) Returns anObservablethat emits the results of a specified combiner function applied to combinations of two items emitted, in sequence, by two otherObservableSources.
zipapplies this function in strict sequence, so the first item emitted by the resultingObservablewill be the result of the function applied to the first item emitted byo1and the first item emitted byo2; the second item emitted by the resultingObservablewill be the result of the function applied to the second item emitted byo1and the second item emitted byo2; and so forth.The resulting
Observable<R>returned fromzipwill invokeonNextas many times as the number ofonNextinvocations of theObservableSourcethat emits the fewest items.The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:zip(range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2), (a, b) -> a + b)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the value type of the first sourceT2- the value type of the second sourceR- the zipped result type- Parameters:
source1- the first sourceObservableSourcesource2- a second sourceObservableSourcezipper- a function that, when applied to an item emitted by each of theObservableSources, results in an item that will be emitted by the resultingObservabledelayError- delay errors from any of theObservableSources till the other terminates- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2orzipperisnull- See Also:
-
zip
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T1, @NonNull T2, @NonNull R> @NonNull Observable<R> zip(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull BiFunction<? super @NonNull T1, ? super @NonNull T2, ? extends @NonNull R> zipper, boolean delayError, int bufferSize) Returns anObservablethat emits the results of a specified combiner function applied to combinations of two items emitted, in sequence, by two otherObservableSources.
zipapplies this function in strict sequence, so the first item emitted by the resultingObservablewill be the result of the function applied to the first item emitted byo1and the first item emitted byo2; the second item emitted by the resultingObservablewill be the result of the function applied to the second item emitted byo1and the second item emitted byo2; and so forth.The resulting
Observable<R>returned fromzipwill invokeonNextas many times as the number ofonNextinvocations of theObservableSourcethat emits the fewest items.The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:zip(range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2), (a, b) -> a + b)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the value type of the first sourceT2- the value type of the second sourceR- the zipped result type- Parameters:
source1- the first sourceObservableSourcesource2- a second sourceObservableSourcezipper- a function that, when applied to an item emitted by each of theObservableSources, results in an item that will be emitted by the resultingObservabledelayError- delay errors from any of theObservableSources till the other terminatesbufferSize- the number of elements expected from each sourceObservableSourceto be buffered- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2orzipperisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
zip
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull R> @NonNull Observable<R> zip(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull Function3<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of three items emitted, in sequence, by three otherObservableSources.
zipapplies this function in strict sequence, so the first item emitted by the resultingObservablewill be the result of the function applied to the first item emitted byo1, the first item emitted byo2, and the first item emitted byo3; the second item emitted by the resultingObservablewill be the result of the function applied to the second item emitted byo1, the second item emitted byo2, and the second item emitted byo3; and so forth.The resulting
Observable<R>returned fromzipwill invokeonNextas many times as the number ofonNextinvocations of theObservableSourcethat emits the fewest items.The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:zip(range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2), ..., (a, b, c) -> a + b)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the value type of the first sourceT2- the value type of the second sourceT3- the value type of the third sourceR- the zipped result type- Parameters:
source1- the first sourceObservableSourcesource2- a second sourceObservableSourcesource3- a third sourceObservableSourcezipper- a function that, when applied to an item emitted by each of theObservableSources, results in an item that will be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3orzipperisnull- See Also:
-
zip
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull R> @NonNull Observable<R> zip(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull @NonNull Function4<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of four items emitted, in sequence, by four otherObservableSources.
zipapplies this function in strict sequence, so the first item emitted by the resultingObservablewill be the result of the function applied to the first item emitted byo1, the first item emitted byo2, the first item emitted byo3, and the first item emitted by04; the second item emitted by the resultingObservablewill be the result of the function applied to the second item emitted by each of thoseObservableSources; and so forth.The resulting
Observable<R>returned fromzipwill invokeonNextas many times as the number ofonNextinvocations of theObservableSourcethat emits the fewest items.The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:zip(range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2), ..., (a, b, c, d) -> a + b)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the value type of the first sourceT2- the value type of the second sourceT3- the value type of the third sourceT4- the value type of the fourth sourceR- the zipped result type- Parameters:
source1- the first sourceObservableSourcesource2- a second sourceObservableSourcesource3- a third sourceObservableSourcesource4- a fourth sourceObservableSourcezipper- a function that, when applied to an item emitted by each of theObservableSources, results in an item that will be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4orzipperisnull- See Also:
-
zip
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull R> @NonNull Observable<R> zip(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull @NonNull Function5<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of five items emitted, in sequence, by five otherObservableSources.
zipapplies this function in strict sequence, so the first item emitted by the resultingObservablewill be the result of the function applied to the first item emitted byo1, the first item emitted byo2, the first item emitted byo3, the first item emitted byo4, and the first item emitted byo5; the second item emitted by the resultingObservablewill be the result of the function applied to the second item emitted by each of thoseObservableSources; and so forth.The resulting
Observable<R>returned fromzipwill invokeonNextas many times as the number ofonNextinvocations of theObservableSourcethat emits the fewest items.The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:zip(range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2), ..., (a, b, c, d, e) -> a + b)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the value type of the first sourceT2- the value type of the second sourceT3- the value type of the third sourceT4- the value type of the fourth sourceT5- the value type of the fifth sourceR- the zipped result type- Parameters:
source1- the first sourceObservableSourcesource2- a second sourceObservableSourcesource3- a third sourceObservableSourcesource4- a fourth sourceObservableSourcesource5- a fifth sourceObservableSourcezipper- a function that, when applied to an item emitted by each of theObservableSources, results in an item that will be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5orzipperisnull- See Also:
-
zip
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull R> @NonNull Observable<R> zip(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull @NonNull Function6<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of six items emitted, in sequence, by six otherObservableSources.
zipapplies this function in strict sequence, so the first item emitted by the resultingObservablewill be the result of the function applied to the first item emitted by each sourceObservableSource, the second item emitted by the resultingObservablewill be the result of the function applied to the second item emitted by each of thoseObservableSources, and so forth.The resulting
Observable<R>returned fromzipwill invokeonNextas many times as the number ofonNextinvocations of theObservableSourcethat emits the fewest items.The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:zip(range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2), ..., (a, b, c, d, e, f) -> a + b)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the value type of the first sourceT2- the value type of the second sourceT3- the value type of the third sourceT4- the value type of the fourth sourceT5- the value type of the fifth sourceT6- the value type of the sixth sourceR- the zipped result type- Parameters:
source1- the first sourceObservableSourcesource2- a second sourceObservableSourcesource3- a third sourceObservableSourcesource4- a fourth sourceObservableSourcesource5- a fifth sourceObservableSourcesource6- a sixth sourceObservableSourcezipper- a function that, when applied to an item emitted by each of theObservableSources, results in an item that will be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5,source6orzipperisnull- See Also:
-
zip
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull R> @NonNull Observable<R> zip(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull @NonNull ObservableSource<? extends @NonNull T7> source7, @NonNull @NonNull Function7<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of seven items emitted, in sequence, by seven otherObservableSources.
zipapplies this function in strict sequence, so the first item emitted by the resultingObservablewill be the result of the function applied to the first item emitted by each sourceObservableSource, the second item emitted by the resultingObservablewill be the result of the function applied to the second item emitted by each of thoseObservableSources, and so forth.The resulting
Observable<R>returned fromzipwill invokeonNextas many times as the number ofonNextinvocations of theObservableSourcethat emits the fewest items.The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:zip(range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2), ..., (a, b, c, d, e, f, g) -> a + b)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the value type of the first sourceT2- the value type of the second sourceT3- the value type of the third sourceT4- the value type of the fourth sourceT5- the value type of the fifth sourceT6- the value type of the sixth sourceT7- the value type of the seventh sourceR- the zipped result type- Parameters:
source1- the first sourceObservableSourcesource2- a second sourceObservableSourcesource3- a third sourceObservableSourcesource4- a fourth sourceObservableSourcesource5- a fifth sourceObservableSourcesource6- a sixth sourceObservableSourcesource7- a seventh sourceObservableSourcezipper- a function that, when applied to an item emitted by each of theObservableSources, results in an item that will be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5,source6,source7orzipperisnull- See Also:
-
zip
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull T8, @NonNull R> @NonNull Observable<R> zip(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull @NonNull ObservableSource<? extends @NonNull T7> source7, @NonNull @NonNull ObservableSource<? extends @NonNull T8> source8, @NonNull @NonNull Function8<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? super @NonNull T8, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of eight items emitted, in sequence, by eight otherObservableSources.
zipapplies this function in strict sequence, so the first item emitted by the resultingObservablewill be the result of the function applied to the first item emitted by each sourceObservableSource, the second item emitted by the resultingObservablewill be the result of the function applied to the second item emitted by each of thoseObservableSources, and so forth.The resulting
Observable<R>returned fromzipwill invokeonNextas many times as the number ofonNextinvocations of theObservableSourcethat emits the fewest items.The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:zip(range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2), ..., (a, b, c, d, e, f, g, h) -> a + b)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the value type of the first sourceT2- the value type of the second sourceT3- the value type of the third sourceT4- the value type of the fourth sourceT5- the value type of the fifth sourceT6- the value type of the sixth sourceT7- the value type of the seventh sourceT8- the value type of the eighth sourceR- the zipped result type- Parameters:
source1- the first sourceObservableSourcesource2- a second sourceObservableSourcesource3- a third sourceObservableSourcesource4- a fourth sourceObservableSourcesource5- a fifth sourceObservableSourcesource6- a sixth sourceObservableSourcesource7- a seventh sourceObservableSourcesource8- an eighth sourceObservableSourcezipper- a function that, when applied to an item emitted by each of theObservableSources, results in an item that will be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5,source6,source7,source8orzipperisnull- See Also:
-
zip
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull T8, @NonNull T9, @NonNull R> @NonNull Observable<R> zip(@NonNull @NonNull ObservableSource<? extends @NonNull T1> source1, @NonNull @NonNull ObservableSource<? extends @NonNull T2> source2, @NonNull @NonNull ObservableSource<? extends @NonNull T3> source3, @NonNull @NonNull ObservableSource<? extends @NonNull T4> source4, @NonNull @NonNull ObservableSource<? extends @NonNull T5> source5, @NonNull @NonNull ObservableSource<? extends @NonNull T6> source6, @NonNull @NonNull ObservableSource<? extends @NonNull T7> source7, @NonNull @NonNull ObservableSource<? extends @NonNull T8> source8, @NonNull @NonNull ObservableSource<? extends @NonNull T9> source9, @NonNull @NonNull Function9<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? super @NonNull T8, ? super @NonNull T9, ? extends @NonNull R> zipper) Returns anObservablethat emits the results of a specified combiner function applied to combinations of nine items emitted, in sequence, by nine otherObservableSources.
zipapplies this function in strict sequence, so the first item emitted by the resultingObservablewill be the result of the function applied to the first item emitted by each sourceObservableSource, the second item emitted by the resultingObservablewill be the result of the function applied to the second item emitted by each of thoseObservableSources, and so forth.The resulting
Observable<R>returned fromzipwill invokeonNextas many times as the number ofonNextinvocations of theObservableSourcethat emits the fewest items.The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:zip(range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2), ..., (a, b, c, d, e, f, g, h, i) -> a + b)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the value type of the first sourceT2- the value type of the second sourceT3- the value type of the third sourceT4- the value type of the fourth sourceT5- the value type of the fifth sourceT6- the value type of the sixth sourceT7- the value type of the seventh sourceT8- the value type of the eighth sourceT9- the value type of the ninth sourceR- the zipped result type- Parameters:
source1- the first sourceObservableSourcesource2- a second sourceObservableSourcesource3- a third sourceObservableSourcesource4- a fourth sourceObservableSourcesource5- a fifth sourceObservableSourcesource6- a sixth sourceObservableSourcesource7- a seventh sourceObservableSourcesource8- an eighth sourceObservableSourcesource9- a ninth sourceObservableSourcezipper- a function that, when applied to an item emitted by each of theObservableSources, results in an item that will be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4,source5,source6,source7,source8,source9orzipperisnull- See Also:
-
zipArray
@CheckReturnValue @SchedulerSupport("none") @SafeVarargs @NonNull public static <@NonNull T, @NonNull R> @NonNull Observable<R> zipArray(@NonNull @NonNull Function<? super Object[], ? extends @NonNull R> zipper, boolean delayError, int bufferSize, @NonNull @NonNull ObservableSource<? extends @NonNull T>... sources) Returns anObservablethat emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by an array of otherObservableSources.zipapplies this function in strict sequence, so the first item emitted by the resultingObservablewill be the result of the function applied to the first item emitted by each of theObservableSources; the second item emitted by the resultingObservablewill be the result of the function applied to the second item emitted by each of thoseObservableSources; and so forth.The resulting
Observable<R>returned fromzipwill invokeonNextas many times as the number ofonNextinvocations of theObservableSourcethat emits the fewest items.The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:zip(new ObservableSource[]{range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2)}, (a) -> a)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.Note on method signature: since Java doesn't allow creating a generic array with
new T[], the implementation of this operator has to create anObject[]instead. Unfortunately, aFunction<Integer[], R>passed to the method would trigger aClassCastException.
- Scheduler:
zipArraydoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element typeR- the result type- Parameters:
zipper- a function that, when applied to an item emitted by each of theObservableSources, results in an item that will be emitted by the resultingObservabledelayError- delay errors signaled by any of theObservableSourceuntil allObservableSources terminatebufferSize- the number of elements expected from each sourceObservableSourceto be bufferedsources- an array of sourceObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesorzipperisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
all
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<Boolean> all(@NonNull @NonNull Predicate<? super @NonNull T> predicate) Returns aSinglethat emits aBooleanthat indicates whether all of the items emitted by the currentObservablesatisfy a condition.
- Scheduler:
alldoes not operate by default on a particularScheduler.
- Parameters:
predicate- a function that evaluates an item and returns aBoolean- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifpredicateisnull- See Also:
-
ambWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> ambWith(@NonNull @NonNull ObservableSource<? extends @NonNull T> other) Mirrors the currentObservableor the otherObservableSourceprovided of which the first either emits an item or sends a termination notification.
When the current
Observablesignals an item or terminates first, the subscription to the otherObservableSourceis disposed. If the otherObservableSourcesignals an item or terminates first, the subscription to the currentObservableis disposed.- Scheduler:
ambWithdoes not operate by default on a particularScheduler.- Error handling:
-
If the losing
ObservableSourcesignals an error, the error is routed to the global error handler viaRxJavaPlugins.onError(Throwable).
- Parameters:
other- anObservableSourcecompeting to react first. A subscription to this provided source will occur after subscribing to the current source.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- See Also:
-
any
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<Boolean> any(@NonNull @NonNull Predicate<? super @NonNull T> predicate) Returns aSinglethat emitstrueif any item emitted by the currentObservablesatisfies a specified condition, otherwisefalse. Note: this always emitsfalseif the currentObservableis empty.
In Rx.Net this is the
anyObserverbut we renamed it in RxJava to better match Java naming idioms.- Scheduler:
anydoes not operate by default on a particularScheduler.
- Parameters:
predicate- the condition to test items emitted by the currentObservable- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifpredicateisnull- See Also:
-
blockingFirst
Returns the first item emitted by the currentObservable, or throwsNoSuchElementExceptionif it emits no items.
- Scheduler:
blockingFirstdoes not operate by default on a particularScheduler.- Error handling:
- If the source signals an error, the operator wraps a checked
ExceptionintoRuntimeExceptionand throws that. Otherwise,RuntimeExceptions andErrors are rethrown as they are.
- Returns:
- the first item emitted by the current
Observable - Throws:
NoSuchElementException- if the currentObservableemits no items- See Also:
-
blockingFirst
@CheckReturnValue @SchedulerSupport("none") @NonNull public final T blockingFirst(@NonNull @NonNull T defaultItem) Returns the first item emitted by the currentObservable, or a default value if it emits no items.
- Scheduler:
blockingFirstdoes not operate by default on a particularScheduler.- Error handling:
- If the source signals an error, the operator wraps a checked
ExceptionintoRuntimeExceptionand throws that. Otherwise,RuntimeExceptions andErrors are rethrown as they are.
- Parameters:
defaultItem- a default value to return if the currentObservableemits no items- Returns:
- the first item emitted by the current
Observable, or the default value if it emits no items - Throws:
NullPointerException- ifdefaultItemisnull- See Also:
-
blockingForEach
@SchedulerSupport("none") public final void blockingForEach(@NonNull @NonNull Consumer<? super @NonNull T> onNext) Consumes the currentObservablein a blocking fashion and invokes the givenConsumerwith each upstream item on the current thread until the upstream terminates.
Note: the method will only return if the upstream terminates or the current thread is interrupted.
This method executes the
Consumeron the current thread whilesubscribe(Consumer)executes the consumer on the original caller thread of the sequence.- Scheduler:
blockingForEachdoes not operate by default on a particularScheduler.- Error handling:
- If the source signals an error, the operator wraps a checked
ExceptionintoRuntimeExceptionand throws that. Otherwise,RuntimeExceptions andErrors are rethrown as they are.
- Parameters:
onNext- theConsumerto invoke for each item emitted by theObservable- Throws:
NullPointerException- ifonNextisnullRuntimeException- if an error occurs- See Also:
-
blockingForEach
@SchedulerSupport("none") public final void blockingForEach(@NonNull @NonNull Consumer<? super @NonNull T> onNext, int capacityHint) Consumes the currentObservablein a blocking fashion and invokes the givenConsumerwith each upstream item on the current thread until the upstream terminates.
Note: the method will only return if the upstream terminates or the current thread is interrupted.
This method executes the
Consumeron the current thread whilesubscribe(Consumer)executes the consumer on the original caller thread of the sequence.- Scheduler:
blockingForEachdoes not operate by default on a particularScheduler.- Error handling:
- If the source signals an error, the operator wraps a checked
ExceptionintoRuntimeExceptionand throws that. Otherwise,RuntimeExceptions andErrors are rethrown as they are.
- Parameters:
onNext- theConsumerto invoke for each item emitted by theObservablecapacityHint- the number of items expected to be buffered (allows reducing buffer reallocations)- Throws:
NullPointerException- ifonNextisnullIllegalArgumentException- ifcapacityHintis non-positiveRuntimeException- if an error occurs;Errors andRuntimeExceptions are rethrown as they are, checkedExceptions are wrapped intoRuntimeExceptions- See Also:
-
blockingIterable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Iterable<T> blockingIterable()Exposes the currentObservableas anIterablewhich, when iterated, subscribes to the currentObservableand blocks until the currentObservableemits items or terminates.
- Scheduler:
blockingIterabledoes not operate by default on a particularScheduler.
- Returns:
- the new
Iterableinstance - See Also:
-
blockingIterable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Iterable<T> blockingIterable(int capacityHint) Exposes the currentObservableas anIterablewhich, when iterated, subscribes to the currentObservableand blocks until the currentObservableemits items or terminates.
- Scheduler:
blockingIterabledoes not operate by default on a particularScheduler.
- Parameters:
capacityHint- the expected number of items to be buffered- Returns:
- the new
Iterableinstance - Throws:
IllegalArgumentException- ifcapacityHintis non-positive- See Also:
-
blockingLast
Returns the last item emitted by the currentObservable, or throwsNoSuchElementExceptionif the currentObservableemits no items.
- Scheduler:
blockingLastdoes not operate by default on a particularScheduler.- Error handling:
- If the source signals an error, the operator wraps a checked
ExceptionintoRuntimeExceptionand throws that. Otherwise,RuntimeExceptions andErrors are rethrown as they are.
- Returns:
- the last item emitted by the current
Observable - Throws:
NoSuchElementException- if the currentObservableemits no items- See Also:
-
blockingLast
@CheckReturnValue @SchedulerSupport("none") @NonNull public final T blockingLast(@NonNull @NonNull T defaultItem) Returns the last item emitted by the currentObservable, or a default value if it emits no items.
- Scheduler:
blockingLastdoes not operate by default on a particularScheduler.- Error handling:
- If the source signals an error, the operator wraps a checked
ExceptionintoRuntimeExceptionand throws that. Otherwise,RuntimeExceptions andErrors are rethrown as they are.
- Parameters:
defaultItem- a default value to return if the currentObservableemits no items- Returns:
- the last item emitted by the
Observable, or the default value if it emits no items - Throws:
NullPointerException- ifdefaultItemisnull- See Also:
-
blockingLatest
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Iterable<T> blockingLatest()Returns anIterablethat returns the latest item emitted by the currentObservable, waiting if necessary for one to become available.
If the current
Observableproduces items faster thanIterator.nexttakes them,onNextevents might be skipped, butonErrororonCompleteevents are not.Note also that an
onNextdirectly followed byonCompletemight hide theonNextevent.- Scheduler:
blockingLatestdoes not operate by default on a particularScheduler.
- Returns:
- the new
Iterableinstance - See Also:
-
blockingMostRecent
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Iterable<T> blockingMostRecent(@NonNull @NonNull T initialItem) Returns anIterablethat always returns the item most recently emitted by the currentObservable.
- Scheduler:
blockingMostRecentdoes not operate by default on a particularScheduler.
- Parameters:
initialItem- the initial value that theIterablesequence will yield if the currentObservablehas not yet emitted an item- Returns:
- the new
Iterableinstance - Throws:
NullPointerException- ifinitialItemisnull- See Also:
-
blockingNext
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Iterable<T> blockingNext()Returns anIterablethat blocks until the currentObservableemits another item, then returns that item.
- Scheduler:
blockingNextdoes not operate by default on a particularScheduler.
- Returns:
- the new
Iterableinstance - See Also:
-
blockingSingle
If the currentObservablecompletes after emitting a single item, return that item, otherwise throw aNoSuchElementException.
- Scheduler:
blockingSingledoes not operate by default on a particularScheduler.- Error handling:
- If the source signals an error, the operator wraps a checked
ExceptionintoRuntimeExceptionand throws that. Otherwise,RuntimeExceptions andErrors are rethrown as they are.
- Returns:
- the single item emitted by the current
Observable - See Also:
-
blockingSingle
@CheckReturnValue @SchedulerSupport("none") @NonNull public final T blockingSingle(@NonNull @NonNull T defaultItem) If the currentObservablecompletes after emitting a single item, return that item; if it emits more than one item, throw anIllegalArgumentException; if it emits no items, return a default value.
- Scheduler:
blockingSingledoes not operate by default on a particularScheduler.- Error handling:
- If the source signals an error, the operator wraps a checked
ExceptionintoRuntimeExceptionand throws that. Otherwise,RuntimeExceptions andErrors are rethrown as they are.
- Parameters:
defaultItem- a default value to return if the currentObservableemits no items- Returns:
- the single item emitted by the current
Observable, or the default value if it emits no items - Throws:
NullPointerException- ifdefaultItemisnull- See Also:
-
toFuture
Returns aFuturerepresenting the only value emitted by the currentObservable.
If the
Observableemits more than one item,Futurewill receive anIndexOutOfBoundsException. If theObservableis empty,Futurewill receive anNoSuchElementException. TheObservablesource has to terminate in order for the returnedFutureto terminate as well.If the
Observablemay emit more than one item, useObservable.toList().toFuture().- Scheduler:
toFuturedoes not operate by default on a particularScheduler.
- Returns:
- the new
Futureinstance - See Also:
-
blockingSubscribe
Runs the currentObservableto a terminal event, ignoring any values and rethrowing any exception.
Note that calling this method will block the caller thread until the upstream terminates normally or with an error. Therefore, calling this method from special threads such as the Android Main Thread or the Swing Event Dispatch Thread is not recommended.
- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.
- Since:
- 2.0
- See Also:
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Consumer<? super @NonNull T> onNext) Subscribes to the source and calls the given callbacks on the current thread.
If the
Observableemits an error, it is wrapped into anOnErrorNotImplementedExceptionand routed to theRxJavaPlugins.onError(Throwable)handler. Using the overloadsblockingSubscribe(Consumer, Consumer)orblockingSubscribe(Consumer, Consumer, Action)instead is recommended.Note that calling this method will block the caller thread until the upstream terminates normally or with an error. Therefore, calling this method from special threads such as the Android Main Thread or the Swing Event Dispatch Thread is not recommended.
- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.
- Parameters:
onNext- the callback action for each source value- Throws:
NullPointerException- ifonNextisnull- Since:
- 2.0
- See Also:
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Consumer<? super @NonNull T> onNext, @NonNull @NonNull Consumer<? super Throwable> onError) Subscribes to the source and calls the given callbacks on the current thread.
Note that calling this method will block the caller thread until the upstream terminates normally or with an error. Therefore, calling this method from special threads such as the Android Main Thread or the Swing Event Dispatch Thread is not recommended.
- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.
- Parameters:
onNext- the callback action for each source valueonError- the callback action for an error event- Throws:
NullPointerException- ifonNextoronErrorisnull- Since:
- 2.0
- See Also:
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Consumer<? super @NonNull T> onNext, @NonNull @NonNull Consumer<? super Throwable> onError, @NonNull @NonNull Action onComplete) Subscribes to the source and calls the given callbacks on the current thread.
Note that calling this method will block the caller thread until the upstream terminates normally or with an error. Therefore, calling this method from special threads such as the Android Main Thread or the Swing Event Dispatch Thread is not recommended.
- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.
- Parameters:
onNext- the callback action for each source valueonError- the callback action for an error eventonComplete- the callback action for the completion event.- Throws:
NullPointerException- ifonNext,onErrororonCompleteisnull- Since:
- 2.0
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Observer<? super @NonNull T> observer) Subscribes to the source and calls theObservermethods on the current thread.Note that calling this method will block the caller thread until the upstream terminates normally, with an error or the
Observerdisposes theDisposableit receives viaObserver.onSubscribe(Disposable). Therefore, calling this method from special threads such as the Android Main Thread or the Swing Event Dispatch Thread is not recommended.- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.
- Parameters:
observer- theObserverinstance to forward events and calls to in the current thread- Throws:
NullPointerException- ifobserverisnull- Since:
- 2.0
-
buffer
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<@NonNull List<T>> buffer(int count) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping buffers, each containingcountitems. When the currentObservablecompletes, the resultingObservableemits the current buffer and propagates the notification from the currentObservable. Note that if the currentObservableissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- This version of
bufferdoes not operate by default on a particularScheduler.
- Parameters:
count- the maximum number of items in each buffer before it should be emitted- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- ifcountis non-positive- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<@NonNull List<T>> buffer(int count, int skip) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservableemits buffers everyskipitems, each containingcountitems. When the currentObservablecompletes, the resultingObservableemits the current buffer and propagates the notification from the currentObservable. Note that if the currentObservableissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- This version of
bufferdoes not operate by default on a particularScheduler.
- Parameters:
count- the maximum size of each buffer before it should be emittedskip- how many items emitted by the currentObservableshould be skipped before starting a new buffer. Note that whenskipandcountare equal, this is the same operation asbuffer(int).- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- ifcountorskipis non-positive- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U extends Collection<? super @NonNull T>> @NonNull Observable<U> buffer(int count, int skip, @NonNull @NonNull Supplier<@NonNull U> bufferSupplier) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservableemits buffers everyskipitems, each containingcountitems. When the currentObservablecompletes, the resultingObservableemits the current buffer and propagates the notification from the currentObservable. Note that if the currentObservableissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- This version of
bufferdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the collection subclass type to buffer into- Parameters:
count- the maximum size of each buffer before it should be emittedskip- how many items emitted by the currentObservableshould be skipped before starting a new buffer. Note that whenskipandcountare equal, this is the same operation asbuffer(int).bufferSupplier- a factory function that returns an instance of the collection subclass to be used and returned as the buffer- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifbufferSupplierisnullIllegalArgumentException- ifcountorskipis non-positive- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U extends Collection<? super @NonNull T>> @NonNull Observable<U> buffer(int count, @NonNull @NonNull Supplier<@NonNull U> bufferSupplier) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping buffers, each containingcountitems. When the currentObservablecompletes, the resultingObservableemits the current buffer and propagates the notification from the currentObservable. Note that if the currentObservableissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- This version of
bufferdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the collection subclass type to buffer into- Parameters:
count- the maximum number of items in each buffer before it should be emittedbufferSupplier- a factory function that returns an instance of the collection subclass to be used and returned as the buffer- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifbufferSupplierisnullIllegalArgumentException- ifcountis non-positive- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<@NonNull List<T>> buffer(long timespan, long timeskip, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservablestarts a new buffer periodically, as determined by thetimeskipargument. It emits each buffer after a fixed timespan, specified by thetimespanargument. When the currentObservablecompletes, the resultingObservableemits the current buffer and propagates the notification from the currentObservable. Note that if the currentObservableissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- This version of
bufferoperates by default on thecomputationScheduler.
- Parameters:
timespan- the period of time each buffer collects items before it is emittedtimeskip- the period of time after which a new buffer will be createdunit- the unit of time that applies to thetimespanandtimeskiparguments- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<@NonNull List<T>> buffer(long timespan, long timeskip, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservablestarts a new buffer periodically, as determined by thetimeskipargument, and on the specifiedscheduler. It emits each buffer after a fixed timespan, specified by thetimespanargument. When the currentObservablecompletes, the resultingObservableemits the current buffer and propagates the notification from the currentObservable. Note that if the currentObservableissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timespan- the period of time each buffer collects items before it is emittedtimeskip- the period of time after which a new buffer will be createdunit- the unit of time that applies to thetimespanandtimeskipargumentsscheduler- theSchedulerto use when determining the end and start of a buffer- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final <@NonNull U extends Collection<? super @NonNull T>> @NonNull Observable<U> buffer(long timespan, long timeskip, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, @NonNull @NonNull Supplier<@NonNull U> bufferSupplier) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservablestarts a new buffer periodically, as determined by thetimeskipargument, and on the specifiedscheduler. It emits each buffer after a fixed timespan, specified by thetimespanargument. When the currentObservablecompletes, the resultingObservableemits the current buffer and propagates the notification from the currentObservable. Note that if the currentObservableissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Type Parameters:
U- the collection subclass type to buffer into- Parameters:
timespan- the period of time each buffer collects items before it is emittedtimeskip- the period of time after which a new buffer will be createdunit- the unit of time that applies to thetimespanandtimeskipargumentsscheduler- theSchedulerto use when determining the end and start of a bufferbufferSupplier- a factory function that returns an instance of the collection subclass to be used and returned as the buffer- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunit,schedulerorbufferSupplierisnull- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<@NonNull List<T>> buffer(long timespan, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping buffers, each of a fixed duration specified by thetimespanargument. When the currentObservablecompletes, the resultingObservableemits the current buffer and propagates the notification from the currentObservable. Note that if the currentObservableissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- This version of
bufferoperates by default on thecomputationScheduler.
- Parameters:
timespan- the period of time each buffer collects items before it is emitted and replaced with a new bufferunit- the unit of time that applies to thetimespanargument- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<@NonNull List<T>> buffer(long timespan, @NonNull @NonNull TimeUnit unit, int count) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping buffers, each of a fixed duration specified by thetimespanargument or a maximum size specified by thecountargument (whichever is reached first). When the currentObservablecompletes, the resultingObservableemits the current buffer and propagates the notification from the currentObservable. Note that if the currentObservableissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- This version of
bufferoperates by default on thecomputationScheduler.
- Parameters:
timespan- the period of time each buffer collects items before it is emitted and replaced with a new bufferunit- the unit of time which applies to thetimespanargumentcount- the maximum size of each buffer before it is emitted- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnullIllegalArgumentException- ifcountis non-positive- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<@NonNull List<T>> buffer(long timespan, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, int count) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping buffers, each of a fixed duration specified by thetimespanargument as measured on the specifiedscheduler, or a maximum size specified by thecountargument (whichever is reached first). When the currentObservablecompletes, the resultingObservableemits the current buffer and propagates the notification from the currentObservable. Note that if the currentObservableissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timespan- the period of time each buffer collects items before it is emitted and replaced with a new bufferunit- the unit of time which applies to thetimespanargumentscheduler- theSchedulerto use when determining the end and start of a buffercount- the maximum size of each buffer before it is emitted- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnullIllegalArgumentException- ifcountis non-positive- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final <@NonNull U extends Collection<? super @NonNull T>> @NonNull Observable<U> buffer(long timespan, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, int count, @NonNull @NonNull Supplier<@NonNull U> bufferSupplier, boolean restartTimerOnMaxSize) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping buffers, each of a fixed duration specified by thetimespanargument as measured on the specifiedscheduler, or a maximum size specified by thecountargument (whichever is reached first). When the currentObservablecompletes, the resultingObservableemits the current buffer and propagates the notification from the currentObservable. Note that if the currentObservableissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Type Parameters:
U- the collection subclass type to buffer into- Parameters:
timespan- the period of time each buffer collects items before it is emitted and replaced with a new bufferunit- the unit of time which applies to thetimespanargumentscheduler- theSchedulerto use when determining the end and start of a buffercount- the maximum size of each buffer before it is emittedbufferSupplier- a factory function that returns an instance of the collection subclass to be used and returned as the bufferrestartTimerOnMaxSize- iftrue, the time window is restarted when the max capacity of the current buffer is reached- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunit,schedulerorbufferSupplierisnullIllegalArgumentException- ifcountis non-positive- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<@NonNull List<T>> buffer(long timespan, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping buffers, each of a fixed duration specified by thetimespanargument and on the specifiedscheduler. When the currentObservablecompletes, the resultingObservableemits the current buffer and propagates the notification from the currentObservable. Note that if the currentObservableissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timespan- the period of time each buffer collects items before it is emitted and replaced with a new bufferunit- the unit of time which applies to thetimespanargumentscheduler- theSchedulerto use when determining the end and start of a buffer- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull TOpening, @NonNull TClosing> @NonNull Observable<@NonNull List<T>> buffer(@NonNull @NonNull ObservableSource<? extends @NonNull TOpening> openingIndicator, @NonNull @NonNull Function<? super @NonNull TOpening, ? extends ObservableSource<? extends @NonNull TClosing>> closingIndicator) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservableemits buffers that it creates when the specifiedopeningIndicatorObservableSourceemits an item, and closes when theObservableSourcereturned fromclosingIndicatoremits an item. If any of the currentObservable,openingIndicatororclosingIndicatorissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- This version of
bufferdoes not operate by default on a particularScheduler.
- Type Parameters:
TOpening- the element type of the buffer-openingObservableSourceTClosing- the element type of the individual buffer-closingObservableSources- Parameters:
openingIndicator- theObservableSourcethat, when it emits an item, causes a new buffer to be createdclosingIndicator- theFunctionthat is used to produce anObservableSourcefor every buffer created. When this indicatorObservableSourceemits an item, the associated buffer is emitted.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifopeningIndicatororclosingIndicatorisnull- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull TOpening, @NonNull TClosing, @NonNull U extends Collection<? super @NonNull T>> @NonNull Observable<U> buffer(@NonNull @NonNull ObservableSource<? extends @NonNull TOpening> openingIndicator, @NonNull @NonNull Function<? super @NonNull TOpening, ? extends ObservableSource<? extends @NonNull TClosing>> closingIndicator, @NonNull @NonNull Supplier<@NonNull U> bufferSupplier) Returns anObservablethat emits buffers of items it collects from the currentObservable. The resultingObservableemits buffers that it creates when the specifiedopeningIndicatorObservableSourceemits an item, and closes when theObservableSourcereturned fromclosingIndicatoremits an item. If any of the currentObservable,openingIndicatororclosingIndicatorissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.
- Scheduler:
- This version of
bufferdoes not operate by default on a particularScheduler.
- Type Parameters:
TOpening- the element type of the buffer-openingObservableSourceTClosing- the element type of the individual buffer-closingObservableSourcesU- the collection subclass type to buffer into- Parameters:
openingIndicator- theObservableSourcethat, when it emits an item, causes a new buffer to be createdclosingIndicator- theFunctionthat is used to produce anObservableSourcefor every buffer created. When this indicatorObservableSourceemits an item, the associated buffer is emitted.bufferSupplier- a factory function that returns an instance of the collection subclass to be used and returned as the buffer- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifopeningIndicator,closingIndicatororbufferSupplierisnull- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull B> @NonNull Observable<@NonNull List<T>> buffer(@NonNull @NonNull ObservableSource<@NonNull B> boundaryIndicator) Returns anObservablethat emits non-overlapping buffered items from the currentObservableeach time the specified boundaryObservableSourceemits an item.
Completion of either the source or the boundary
ObservableSourcecauses the returnedObservableSourceto emit the latest buffer and complete. If either the currentObservableor the boundaryObservableSourceissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.- Scheduler:
- This version of
bufferdoes not operate by default on a particularScheduler.
- Type Parameters:
B- the boundary value type (ignored)- Parameters:
boundaryIndicator- the boundaryObservableSource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifboundaryIndicatorisnull- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull B> @NonNull Observable<@NonNull List<T>> buffer(@NonNull @NonNull ObservableSource<@NonNull B> boundaryIndicator, int initialCapacity) Returns anObservablethat emits non-overlapping buffered items from the currentObservableeach time the specified boundaryObservableSourceemits an item.
Completion of either the source or the boundary
ObservableSourcecauses the returnedObservableSourceto emit the latest buffer and complete. If either the currentObservableor the boundaryObservableSourceissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.- Scheduler:
- This version of
bufferdoes not operate by default on a particularScheduler.
- Type Parameters:
B- the boundary value type (ignored)- Parameters:
boundaryIndicator- the boundaryObservableSourceinitialCapacity- the initial capacity of each buffer chunk- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifboundaryIndicatorisnullIllegalArgumentException- ifinitialCapacityis non-positive- See Also:
-
buffer
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull B, @NonNull U extends Collection<? super @NonNull T>> @NonNull Observable<U> buffer(@NonNull @NonNull ObservableSource<@NonNull B> boundaryIndicator, @NonNull @NonNull Supplier<@NonNull U> bufferSupplier) Returns anObservablethat emits non-overlapping buffered items from the currentObservableeach time the specified boundaryObservableSourceemits an item.
Completion of either the source or the boundary
ObservableSourcecauses the returnedObservableSourceto emit the latest buffer and complete. If either the currentObservableor the boundaryObservableSourceissues anonErrornotification the event is passed on immediately without first emitting the buffer it is in the process of assembling.- Scheduler:
- This version of
bufferdoes not operate by default on a particularScheduler.
- Type Parameters:
B- the boundary value type (ignored)U- the collection subclass type to buffer into- Parameters:
boundaryIndicator- the boundaryObservableSourcebufferSupplier- a factory function that returns an instance of the collection subclass to be used and returned as the buffer- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifboundaryIndicatororbufferSupplierisnull- See Also:
-
cache
Returns anObservablethat subscribes to the currentObservablelazily, caches all of its events and replays them, in the same order as received, to all the downstream observers.
This is useful when you want an
Observableto cache responses and you can't control the subscribe/dispose behavior of all theObservers.The operator subscribes only when the first downstream observer subscribes and maintains a single subscription towards the current
Observable. In contrast, the operator family ofreplay()that return aConnectableObservablerequire an explicit call toConnectableObservable.connect().Note: You sacrifice the ability to dispose the origin when you use the
cacheoperator so be careful not to use this operator onObservables that emit an infinite or very large number of items that will use up memory. A possible workaround is to applytakeUntilwith a predicate or another source before (and perhaps after) the application ofcache().
Since the operator doesn't allow clearing the cached values either, the possible workaround is to forget all references to it viaAtomicBoolean shouldStop = new AtomicBoolean(); source.takeUntil(v -> shouldStop.get()) .cache() .takeUntil(v -> shouldStop.get()) .subscribe(...);onTerminateDetach()applied along with the previous workaround:AtomicBoolean shouldStop = new AtomicBoolean(); source.takeUntil(v -> shouldStop.get()) .onTerminateDetach() .cache() .takeUntil(v -> shouldStop.get()) .onTerminateDetach() .subscribe(...);- Scheduler:
cachedoes not operate by default on a particularScheduler.
- Returns:
- the new
Observableinstance - See Also:
-
cacheWithInitialCapacity
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> cacheWithInitialCapacity(int initialCapacity) Returns anObservablethat subscribes to the currentObservablelazily, caches all of its events and replays them, in the same order as received, to all the downstream observers.
This is useful when you want an
Observableto cache responses and you can't control the subscribe/dispose behavior of all theObservers.The operator subscribes only when the first downstream observer subscribes and maintains a single subscription towards the current
Observable. In contrast, the operator family ofreplay()that return aConnectableObservablerequire an explicit call toConnectableObservable.connect().Note: You sacrifice the ability to dispose the origin when you use the
cacheoperator so be careful not to use this operator onObservables that emit an infinite or very large number of items that will use up memory. A possible workaround is to apply `takeUntil` with a predicate or another source before (and perhaps after) the application ofcache().
Since the operator doesn't allow clearing the cached values either, the possible workaround is to forget all references to it viaAtomicBoolean shouldStop = new AtomicBoolean(); source.takeUntil(v -> shouldStop.get()) .cache() .takeUntil(v -> shouldStop.get()) .subscribe(...);onTerminateDetach()applied along with the previous workaround:AtomicBoolean shouldStop = new AtomicBoolean(); source.takeUntil(v -> shouldStop.get()) .onTerminateDetach() .cache() .takeUntil(v -> shouldStop.get()) .onTerminateDetach() .subscribe(...);- Scheduler:
cacheWithInitialCapacitydoes not operate by default on a particularScheduler.
Note: The capacity hint is not an upper bound on cache size. For that, consider
replay(int)in combination withConnectableObservable.autoConnect()or similar.- Parameters:
initialCapacity- hint for number of items to cache (for optimizing underlying data structure)- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- ifinitialCapacityis non-positive- See Also:
-
cast
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U> @NonNull Observable<U> cast(@NonNull @NonNull Class<@NonNull U> clazz) Returns anObservablethat emits the upstream items while they can be cast viaClass.cast(Object)until the upstream terminates, or until the upstream signals an item which can't be cast, resulting in aClassCastExceptionto be signaled to the downstream.
- Scheduler:
castdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the output value type cast to- Parameters:
clazz- the target class to use to try and cast the upstream items into- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifclazzisnull- See Also:
-
collect
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U> @NonNull Single<U> collect(@NonNull @NonNull Supplier<? extends @NonNull U> initialItemSupplier, @NonNull @NonNull BiConsumer<? super @NonNull U, ? super @NonNull T> collector) Collects items emitted by the finite sourceObservableinto a single mutable data structure and returns aSinglethat emits this structure.
This is a simplified version of
reducethat does not need to return the state on each pass.Note that this operator requires the upstream to signal
onCompletefor the accumulator object to be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
collectdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the accumulator and output type- Parameters:
initialItemSupplier- the mutable data structure that will collect the itemscollector- a function that accepts thestateand an emitted item, and modifies the accumulator accordingly accordingly- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifinitialItemSupplierorcollectorisnull- See Also:
-
collectInto
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U> @NonNull Single<U> collectInto(@NonNull @NonNull U initialItem, @NonNull @NonNull BiConsumer<? super @NonNull U, ? super @NonNull T> collector) Collects items emitted by the finite sourceObservableinto a single mutable data structure and returns aSinglethat emits this structure.
This is a simplified version of
reducethat does not need to return the state on each pass.Note that this operator requires the upstream to signal
onCompletefor the accumulator object to be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
collectIntodoes not operate by default on a particularScheduler.
- Type Parameters:
U- the accumulator and output type- Parameters:
initialItem- the mutable data structure that will collect the itemscollector- a function that accepts thestateand an emitted item, and modifies the accumulator accordingly accordingly- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifinitialItemorcollectorisnull- See Also:
-
compose
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> compose(@NonNull @NonNull ObservableTransformer<? super @NonNull T, ? extends @NonNull R> composer) Transform the currentObservableby applying a particularObservableTransformerfunction to it.This method operates on the
Observableitself whereaslift(ObservableOperator)operates on theObservableSource'sObservers.If the operator you are creating is designed to act on the individual items emitted by the current
Observable, uselift(ObservableOperator). If your operator is designed to transform the currentObservableas a whole (for instance, by applying a particular set of existing RxJava operators to it) usecompose.- Scheduler:
composedoes not operate by default on a particularScheduler.
- Type Parameters:
R- the value type of the outputObservableSource- Parameters:
composer- implements the function that transforms the currentObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifcomposerisnull- See Also:
-
concatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper) Returns a newObservablethat emits items resulting from applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then emitting the items that result from concatenating those returnedObservableSources.
Note that there is no guarantee where the given
mapperfunction will be executed; it could be on the subscribing thread, on the upstream thread signaling the new item to be mapped or on the thread where the inner source terminates. To ensure themapperfunction is confined to a known thread, use theconcatMap(Function, int, Scheduler)overload.- Scheduler:
concatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the type of the innerObservableSourcesources and thus the output type- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns anObservableSource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
concatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, int bufferSize) Returns a newObservablethat emits items resulting from applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then emitting the items that result from concatenating those returnedObservableSources.
Note that there is no guarantee where the given
mapperfunction will be executed; it could be on the subscribing thread, on the upstream thread signaling the new item to be mapped or on the thread where the inner source terminates. To ensure themapperfunction is confined to a known thread, use theconcatMap(Function, int, Scheduler)overload.- Scheduler:
concatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the type of the innerObservableSourcesources and thus the output type- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns anObservableSourcebufferSize- the number of elements expected from the currentObservableto be buffered- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
concatMap
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, int bufferSize, @NonNull @NonNull Scheduler scheduler) Returns a newObservablethat emits items resulting from applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then emitting the items that result from concatenating those returnedObservableSources.
The difference between
concatMap(Function, int)and this operator is that this operator guarantees themapperfunction is executed on the specified scheduler.- Scheduler:
concatMapexecutes the givenmapperfunction on the providedScheduler.
- Type Parameters:
R- the type of the innerObservableSourcesources and thus the output type- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns anObservableSourcebufferSize- the number of elements expected from the currentObservableto be bufferedscheduler- the scheduler where themapperfunction will be executed- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperorschedulerisnullIllegalArgumentException- ifbufferSizeis non-positive- Since:
- 3.0.0
- See Also:
-
concatMapDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper) Maps each of the items into anObservableSource, subscribes to them one after the other, one at a time and emits their values in order while delaying any error from either this or any of the innerObservableSources till all of them terminate.
Note that there is no guarantee where the given
mapperfunction will be executed; it could be on the subscribing thread, on the upstream thread signaling the new item to be mapped or on the thread where the inner source terminates. To ensure themapperfunction is confined to a known thread, use theconcatMapDelayError(Function, boolean, int, Scheduler)overload.- Scheduler:
concatMapDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- the function that maps the items of the currentObservableinto the innerObservableSources.- Returns:
- the new
Observableinstance with the concatenation behavior - Throws:
NullPointerException- ifmapperisnull- See Also:
-
concatMapDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean tillTheEnd, int bufferSize) Maps each of the items into anObservableSource, subscribes to them one after the other, one at a time and emits their values in order while delaying any error from either this or any of the innerObservableSources till all of them terminate.
Note that there is no guarantee where the given
mapperfunction will be executed; it could be on the subscribing thread, on the upstream thread signaling the new item to be mapped or on the thread where the inner source terminates. To ensure themapperfunction is confined to a known thread, use theconcatMapDelayError(Function, boolean, int, Scheduler)overload.- Scheduler:
concatMapDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- the function that maps the items of the currentObservableinto the innerObservableSources.tillTheEnd- iftrue, all errors from the outer and innerObservableSourcesources are delayed until the end, iffalse, an error from the main source is signaled when the currentObservablesource terminatesbufferSize- the number of elements expected from the currentObservableto be buffered- Returns:
- the new
Observableinstance with the concatenation behavior - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
concatMapDelayError
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean tillTheEnd, int bufferSize, @NonNull @NonNull Scheduler scheduler) Maps each of the items into anObservableSource, subscribes to them one after the other, one at a time and emits their values in order while delaying any error from either this or any of the innerObservableSources till all of them terminate.
- Scheduler:
concatMapDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- the function that maps the items of the currentObservableinto the innerObservableSources.tillTheEnd- iftrue, all errors from the outer and innerObservableSourcesources are delayed until the end, iffalse, an error from the main source is signaled when the currentObservablesource terminatesbufferSize- the number of elements expected from the currentObservableto be bufferedscheduler- the scheduler where themapperfunction will be executed- Returns:
- the new
Observableinstance with the concatenation behavior - Throws:
NullPointerException- ifmapperorschedulerisnullIllegalArgumentException- ifbufferSizeis non-positive- Since:
- 3.0.0
- See Also:
-
concatMapEager
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapEager(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper) Maps a sequence of values intoObservableSources and concatenates theseObservableSources eagerly into a singleObservablesequence.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the current
Observables. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.
- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
R- the value type- Parameters:
mapper- the function that maps a sequence of values into a sequence ofObservableSources that will be eagerly concatenated- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.0
-
concatMapEager
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapEager(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, int maxConcurrency, int bufferSize) Maps a sequence of values intoObservableSources and concatenates theseObservableSources eagerly into a singleObservablesequence.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the current
Observables. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.
- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
R- the value type- Parameters:
mapper- the function that maps a sequence of values into a sequence ofObservableSources that will be eagerly concatenatedmaxConcurrency- the maximum number of concurrent subscribedObservableSourcesbufferSize- hints about the number of expected items from each innerObservableSource, must be positive- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- Since:
- 2.0
-
concatMapEagerDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapEagerDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean tillTheEnd) Maps a sequence of values intoObservableSources and concatenates theseObservableSources eagerly into a singleObservablesequence.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the current
Observables. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.
- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
R- the value type- Parameters:
mapper- the function that maps a sequence of values into a sequence ofObservableSources that will be eagerly concatenatedtillTheEnd- iftrue, all errors from the outer and innerObservableSourcesources are delayed until the end, iffalse, an error from the main source is signaled when the currentObservablesource terminates- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.0
-
concatMapEagerDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapEagerDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean tillTheEnd, int maxConcurrency, int bufferSize) Maps a sequence of values intoObservableSources and concatenates theseObservableSources eagerly into a singleObservablesequence.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the current
Observables. The operator buffers the values emitted by theseObservableSources and then drains them in order, each one after the previous one completes.
- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
R- the value type- Parameters:
mapper- the function that maps a sequence of values into a sequence ofObservableSources that will be eagerly concatenatedtillTheEnd- iftrue, exceptions from the currentObservableand all the innerObservableSources are delayed until all of them terminate, iffalse, exception from the currentObservableis delayed until the currently runningObservableSourceterminatesmaxConcurrency- the maximum number of concurrent subscribedObservableSourcesbufferSize- the number of elements expected from the currentObservableand each innerObservableSourceto be buffered- Returns:
- the new
Observableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- Since:
- 2.0
-
concatMapCompletable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable concatMapCompletable(@NonNull @NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Maps each element of the currentObservableintoCompletableSources, subscribes to them one at a time in order and waits until the upstream and allCompletableSources complete.
- Scheduler:
concatMapCompletabledoes not operate by default on a particularScheduler.
History: 2.1.6 - experimental
- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns aCompletableSource- Returns:
- the new
Completableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
-
concatMapCompletable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable concatMapCompletable(@NonNull @NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper, int capacityHint) Maps each element of the currentObservableintoCompletableSources, subscribes to them one at a time in order and waits until the upstream and allCompletableSources complete.
- Scheduler:
concatMapCompletabledoes not operate by default on a particularScheduler.
History: 2.1.6 - experimental
- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns aCompletableSourcecapacityHint- the number of upstream items expected to be buffered until the currentCompletableSource, mapped from the current item, completes.- Returns:
- the new
Completableinstance - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifcapacityHintis non-positive- Since:
- 2.2
-
concatMapCompletableDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable concatMapCompletableDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Maps the upstream items intoCompletableSources and subscribes to them one after the other terminates, delaying all errors till both the currentObservableand all innerCompletableSources terminate.
- Scheduler:
concatMapCompletableDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Parameters:
mapper- the function called with the upstream item and should return aCompletableSourceto become the next source to be subscribed to- Returns:
- the new
Completableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
concatMapCompletableDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable concatMapCompletableDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper, boolean tillTheEnd) Maps the upstream items intoCompletableSources and subscribes to them one after the other terminates, optionally delaying all errors till both the currentObservableand all innerCompletableSources terminate.
- Scheduler:
concatMapCompletableDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Parameters:
mapper- the function called with the upstream item and should return aCompletableSourceto become the next source to be subscribed totillTheEnd- Iftrue, errors from the currentObservableor any of the innerCompletableSources are delayed until all of them terminate. Iffalse, an error from the currentObservableis delayed until the current innerCompletableSourceterminates and only then is it emitted to the downstream.- Returns:
- the new
Completableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
concatMapCompletableDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable concatMapCompletableDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper, boolean tillTheEnd, int bufferSize) Maps the upstream items intoCompletableSources and subscribes to them one after the other terminates, optionally delaying all errors till both the currentObservableand all innerCompletableSources terminate.
- Scheduler:
concatMapCompletableDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Parameters:
mapper- the function called with the upstream item and should return aCompletableSourceto become the next source to be subscribed totillTheEnd- Iftrue, errors from the currentObservableor any of the innerCompletableSources are delayed until all of them terminate. Iffalse, an error from the currentObservableis delayed until the current innerCompletableSourceterminates and only then is it emitted to the downstream.bufferSize- The number of upstream items expected to be buffered so that fresh items are ready to be mapped when a previousCompletableSourceterminates.- Returns:
- the new
Completableinstance - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifbufferSizeis non-positive- Since:
- 2.2
- See Also:
-
concatMapIterable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U> @NonNull Observable<U> concatMapIterable(@NonNull @NonNull Function<? super @NonNull T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper) Returns anObservablethat concatenate each item emitted by the currentObservablewith the values in anIterablecorresponding to that item that is generated by a selector.
- Scheduler:
concatMapIterabledoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of item emitted by the resultingObservable- Parameters:
mapper- a function that returns anIterablesequence of values for when given an item emitted by the currentObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
concatMapMaybe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapMaybe(@NonNull @NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper) Maps the upstream items intoMaybeSources and subscribes to them one after the other succeeds or completes, emits their success value if available or terminates immediately if either the currentObservableor the current innerMaybeSourcefail.
- Scheduler:
concatMapMaybedoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Type Parameters:
R- the result type of the innerMaybeSources- Parameters:
mapper- the function called with the upstream item and should return aMaybeSourceto become the next source to be subscribed to- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
concatMapMaybe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapMaybe(@NonNull @NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper, int bufferSize) Maps the upstream items intoMaybeSources and subscribes to them one after the other succeeds or completes, emits their success value if available or terminates immediately if either the currentObservableor the current innerMaybeSourcefail.
- Scheduler:
concatMapMaybedoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Type Parameters:
R- the result type of the innerMaybeSources- Parameters:
mapper- the function called with the upstream item and should return aMaybeSourceto become the next source to be subscribed tobufferSize- The number of upstream items expected to be buffered so that fresh items are ready to be mapped when a previousMaybeSourceterminates.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifbufferSizeis non-positive- Since:
- 2.2
- See Also:
-
concatMapMaybeDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapMaybeDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper) Maps the upstream items intoMaybeSources and subscribes to them one after the other terminates, emits their success value if available and delaying all errors till both the currentObservableand all innerMaybeSources terminate.
- Scheduler:
concatMapMaybeDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Type Parameters:
R- the result type of the innerMaybeSources- Parameters:
mapper- the function called with the upstream item and should return aMaybeSourceto become the next source to be subscribed to- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
concatMapMaybeDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapMaybeDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper, boolean tillTheEnd) Maps the upstream items intoMaybeSources and subscribes to them one after the other terminates, emits their success value if available and optionally delaying all errors till both the currentObservableand all innerMaybeSources terminate.
- Scheduler:
concatMapMaybeDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Type Parameters:
R- the result type of the innerMaybeSources- Parameters:
mapper- the function called with the upstream item and should return aMaybeSourceto become the next source to be subscribed totillTheEnd- Iftrue, errors from the currentObservableor any of the innerMaybeSources are delayed until all of them terminate. Iffalse, an error from the currentObservableis delayed until the current innerMaybeSourceterminates and only then is it emitted to the downstream.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
concatMapMaybeDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapMaybeDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper, boolean tillTheEnd, int bufferSize) Maps the upstream items intoMaybeSources and subscribes to them one after the other terminates, emits their success value if available and optionally delaying all errors till both the currentObservableand all innerMaybeSources terminate.
- Scheduler:
concatMapMaybeDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Type Parameters:
R- the result type of the innerMaybeSources- Parameters:
mapper- the function called with the upstream item and should return aMaybeSourceto become the next source to be subscribed totillTheEnd- Iftrue, errors from the currentObservableor any of the innerMaybeSources are delayed until all of them terminate. Iffalse, an error from the currentObservableis delayed until the current innerMaybeSourceterminates and only then is it emitted to the downstream.bufferSize- The number of upstream items expected to be buffered so that fresh items are ready to be mapped when a previousMaybeSourceterminates.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifbufferSizeis non-positive- Since:
- 2.2
- See Also:
-
concatMapSingle
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapSingle(@NonNull @NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Maps the upstream items intoSingleSources and subscribes to them one after the other succeeds, emits their success values or terminates immediately if either the currentObservableor the current innerSingleSourcefail.
- Scheduler:
concatMapSingledoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Type Parameters:
R- the result type of the innerSingleSources- Parameters:
mapper- the function called with the upstream item and should return aSingleSourceto become the next source to be subscribed to- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
concatMapSingle
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapSingle(@NonNull @NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper, int bufferSize) Maps the upstream items intoSingleSources and subscribes to them one after the other succeeds, emits their success values or terminates immediately if either the currentObservableor the current innerSingleSourcefail.
- Scheduler:
concatMapSingledoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Type Parameters:
R- the result type of the innerSingleSources- Parameters:
mapper- the function called with the upstream item and should return aSingleSourceto become the next source to be subscribed tobufferSize- The number of upstream items expected to be buffered so that fresh items are ready to be mapped when a previousSingleSourceterminates.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifbufferSizeis non-positive- Since:
- 2.2
- See Also:
-
concatMapSingleDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapSingleDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Maps the upstream items intoSingleSources and subscribes to them one after the other succeeds or fails, emits their success values and delays all errors till both the currentObservableand all innerSingleSources terminate.
- Scheduler:
concatMapSingleDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Type Parameters:
R- the result type of the innerSingleSources- Parameters:
mapper- the function called with the upstream item and should return aSingleSourceto become the next source to be subscribed to- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
concatMapSingleDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapSingleDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper, boolean tillTheEnd) Maps the upstream items intoSingleSources and subscribes to them one after the other succeeds or fails, emits their success values and optionally delays all errors till both the currentObservableand all innerSingleSources terminate.
- Scheduler:
concatMapSingleDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Type Parameters:
R- the result type of the innerSingleSources- Parameters:
mapper- the function called with the upstream item and should return aSingleSourceto become the next source to be subscribed totillTheEnd- Iftrue, errors from the currentObservableor any of the innerSingleSources are delayed until all of them terminate. Iffalse, an error from the currentObservableis delayed until the current innerSingleSourceterminates and only then is it emitted to the downstream.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
concatMapSingleDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapSingleDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper, boolean tillTheEnd, int bufferSize) Maps the upstream items intoSingleSources and subscribes to them one after the other succeeds or fails, emits their success values and optionally delays errors till both the currentObservableand all innerSingleSources terminate.
- Scheduler:
concatMapSingleDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Type Parameters:
R- the result type of the innerSingleSources- Parameters:
mapper- the function called with the upstream item and should return aSingleSourceto become the next source to be subscribed totillTheEnd- Iftrue, errors from the currentObservableor any of the innerSingleSources are delayed until all of them terminate. Iffalse, an error from the currentObservableis delayed until the current innerSingleSourceterminates and only then is it emitted to the downstream.bufferSize- The number of upstream items expected to be buffered so that fresh items are ready to be mapped when a previousSingleSourceterminates.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifbufferSizeis non-positive- Since:
- 2.2
- See Also:
-
concatWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> concatWith(@NonNull @NonNull ObservableSource<? extends @NonNull T> other) Returns anObservablethat first emits the items emitted from the currentObservable, then items from theotherObservableSourcewithout interleaving them.
- Scheduler:
concatWithdoes not operate by default on a particularScheduler.
- Parameters:
other- anObservableSourceto be concatenated after the current- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- See Also:
-
concatWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> concatWith(@NonNull @NonNull SingleSource<? extends @NonNull T> other) Returns anObservablethat emits the items from the currentObservablefollowed by the success item or error event of theotherSingleSource.
- Scheduler:
concatWithdoes not operate by default on a particularScheduler.
History: 2.1.10 - experimental
- Parameters:
other- theSingleSourcewhose signal should be emitted after the currentObservablecompletes normally.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 2.2
-
concatWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> concatWith(@NonNull @NonNull MaybeSource<? extends @NonNull T> other) Returns anObservablethat emits the items from the currentObservablefollowed by the success item or terminal events of the otherMaybeSource.
- Scheduler:
concatWithdoes not operate by default on a particularScheduler.
History: 2.1.10 - experimental
- Parameters:
other- theMaybeSourcewhose signal should be emitted after the currentObservablecompletes normally.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 2.2
-
concatWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> concatWith(@NonNull @NonNull CompletableSource other) Returns anObservablethat emits items from the currentObservableand when it completes normally, the otherCompletableSourceis subscribed to and the returnedObservableemits its terminal events.
- Scheduler:
concatWithdoes not operate by default on a particularScheduler.
History: 2.1.10 - experimental
- Parameters:
other- theCompletableSourceto subscribe to once the currentObservablecompletes normally- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 2.2
-
contains
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<Boolean> contains(@NonNull @NonNull Object item) Returns aSinglethat emits aBooleanthat indicates whether the currentObservableemitted a specified item.
- Scheduler:
containsdoes not operate by default on a particularScheduler.
- Parameters:
item- the item to search for in the emissions from the currentObservable- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifitemisnull- See Also:
-
count
-
debounce
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U> @NonNull Observable<T> debounce(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull U>> debounceIndicator) Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by another item within a computed debounce duration denoted by an item emission or completion from a generated innerObservableSourcefor that original item.
The delivery of the item happens on the thread of the first
onNextoronCompletesignal of the generatedObservableSourcesequence, which if takes too long, a newer item may arrive from the upstream, causing the generated sequence to get disposed, which may also interrupt any downstream blocking operation (yielding anInterruptedException). It is recommended processing items that may take long time to be moved to another thread viaobserveOn(Scheduler)applied afterdebounceitself.- Scheduler:
- This version of
debouncedoes not operate by default on a particularScheduler.
- Type Parameters:
U- the debounce value type (ignored)- Parameters:
debounceIndicator- function to return a sequence that indicates the throttle duration for each item via its own emission or completion- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifdebounceIndicatorisnull- See Also:
-
debounce
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> debounce(long timeout, @NonNull @NonNull TimeUnit unit) Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by newer items before a timeout value expires. The timer resets on each emission.Note: If items keep being emitted by the current
Observablefaster than the timeout then no items will be emitted by the resultingObservable.
Delivery of the item after the grace period happens on the
computationScheduler'sWorkerwhich if takes too long, a newer item may arrive from the upstream, causing theWorker's task to get disposed, which may also interrupt any downstream blocking operation (yielding anInterruptedException). It is recommended processing items that may take long time to be moved to another thread viaobserveOn(Scheduler)applied afterdebounceitself.- Scheduler:
debounceoperates by default on thecomputationScheduler.
- Parameters:
timeout- the length of the window of time that must pass after the emission of an item from the currentObservablein which theObservableemits no items in order for the item to be emitted by the resultingObservableunit- the unit of time for the specifiedtimeout- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
debounce
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> debounce(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by newer items before a timeout value expires on a specifiedScheduler. The timer resets on each emission.Note: If items keep being emitted by the current
Observablefaster than the timeout then no items will be emitted by the resultingObservable.
Delivery of the item after the grace period happens on the given
Scheduler'sWorkerwhich if takes too long, a newer item may arrive from the upstream, causing theWorker's task to get disposed, which may also interrupt any downstream blocking operation (yielding anInterruptedException). It is recommended processing items that may take long time to be moved to another thread viaobserveOn(Scheduler)applied afterdebounceitself.- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timeout- the time each item has to be "the most recent" of those emitted by the currentObservableto ensure that it's not droppedunit- the unit of time for the specifiedtimeoutscheduler- theSchedulerto use internally to manage the timers that handle the timeout for each item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
debounce
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> debounce(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, @NonNull @NonNull Consumer<? super @NonNull T> onDropped) Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by newer items before a timeout value expires on a specifiedScheduler. The timer resets on each emission.Note: If items keep being emitted by the current
Observablefaster than the timeout then no items will be emitted by the resultingObservable.
Delivery of the item after the grace period happens on the given
Scheduler'sWorkerwhich if takes too long, a newer item may arrive from the upstream, causing theWorker's task to get disposed, which may also interrupt any downstream blocking operation (yielding anInterruptedException). It is recommended processing items that may take long time to be moved to another thread viaobserveOn(Scheduler)applied afterdebounceitself.- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timeout- the time each item has to be "the most recent" of those emitted by the currentObservableto ensure that it's not droppedunit- the unit of time for the specifiedtimeoutscheduler- theSchedulerto use internally to manage the timers that handle the timeout for each itemonDropped- called with the current entry when it has been replaced by a new one- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull} oronDroppedisnull- Since:
- 3.1.6 - Experimental
- See Also:
-
defaultIfEmpty
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> defaultIfEmpty(@NonNull @NonNull T defaultItem) Returns anObservablethat emits the items emitted by the currentObservableor a specified default item if the currentObservableis empty.
- Scheduler:
defaultIfEmptydoes not operate by default on a particularScheduler.
- Parameters:
defaultItem- the item to emit if the currentObservableemits no items- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifdefaultItemisnull- See Also:
-
delay
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U> @NonNull Observable<T> delay(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull U>> itemDelayIndicator) Returns anObservablethat delays the emissions of the currentObservablevia a per-item derivedObservableSource's item emission or termination, on a per source item basis.
Note: the resulting
Observablewill immediately propagate anyonErrornotification from the currentObservable.- Scheduler:
- This version of
delaydoes not operate by default on a particularScheduler.
- Type Parameters:
U- the item delay value type (ignored)- Parameters:
itemDelayIndicator- a function that returns anObservableSourcefor each item emitted by the currentObservable, which is then used to delay the emission of that item by the resultingObservableuntil theObservableSourcereturned fromitemDelayemits an item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitemDelayIndicatorisnull- See Also:
-
delay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> delay(long time, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits the items emitted by the currentObservableshifted forward in time by a specified delay. An error notification from the currentObservableis not delayed.
- Scheduler:
- This version of
delayoperates by default on thecomputationScheduler.
- Parameters:
time- the delay to shift the source byunit- theTimeUnitin whichperiodis defined- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
delay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> delay(long time, @NonNull @NonNull TimeUnit unit, boolean delayError) Returns anObservablethat emits the items emitted by the currentObservableshifted forward in time by a specified delay. IfdelayErroristrue, error notifications will also be delayed.
- Scheduler:
- This version of
delayoperates by default on thecomputationScheduler.
- Parameters:
time- the delay to shift the source byunit- theTimeUnitin whichperiodis defineddelayError- iftrue, the upstream exception is signaled with the given delay, after all preceding normal elements, iffalse, the upstream exception is signaled immediately- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
delay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> delay(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits the items emitted by the currentObservableshifted forward in time by a specified delay. An error notification from the currentObservableis not delayed.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
time- the delay to shift the source byunit- the time unit ofdelayscheduler- theSchedulerto use for delaying- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
delay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> delay(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean delayError) Returns anObservablethat emits the items emitted by the currentObservableshifted forward in time by a specified delay. IfdelayErroristrue, error notifications will also be delayed.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
time- the delay to shift the source byunit- the time unit ofdelayscheduler- theSchedulerto use for delayingdelayError- iftrue, the upstream exception is signaled with the given delay, after all preceding normal elements, iffalse, the upstream exception is signaled immediately- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
delay
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull V> @NonNull Observable<T> delay(@NonNull @NonNull ObservableSource<@NonNull U> subscriptionIndicator, @NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull V>> itemDelayIndicator) Returns anObservablethat delays the subscription to and emissions from the currentObservableviaObservableSources for the subscription itself and on a per-item basis.
Note: the resulting
Observablewill immediately propagate anyonErrornotification from the currentObservable.- Scheduler:
- This version of
delaydoes not operate by default on a particularScheduler.
- Type Parameters:
U- the subscription delay value type (ignored)V- the item delay value type (ignored)- Parameters:
subscriptionIndicator- a function that returns anObservableSourcethat triggers the subscription to the currentObservableonce it emits any itemitemDelayIndicator- a function that returns anObservableSourcefor each item emitted by the currentObservable, which is then used to delay the emission of that item by the resultingObservableuntil theObservableSourcereturned fromitemDelayemits an item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsubscriptionIndicatororitemDelayIndicatorisnull- See Also:
-
delaySubscription
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U> @NonNull Observable<T> delaySubscription(@NonNull @NonNull ObservableSource<@NonNull U> subscriptionIndicator) Returns anObservablethat delays the subscription to the currentObservableuntil the otherObservableSourceemits an element or completes normally.
- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
U- the value type of the otherObservable, irrelevant- Parameters:
subscriptionIndicator- the otherObservableSourcethat should trigger the subscription to the currentObservable.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsubscriptionIndicatorisnull- Since:
- 2.0
-
delaySubscription
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> delaySubscription(long time, @NonNull @NonNull TimeUnit unit) Returns anObservablethat delays the subscription to the currentObservableby a given amount of time.
- Scheduler:
- This version of
delaySubscriptionoperates by default on thecomputationScheduler.
- Parameters:
time- the time to delay the subscriptionunit- the time unit ofdelay- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
delaySubscription
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> delaySubscription(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat delays the subscription to the currentObservableby a given amount of time, both waiting and subscribing on a givenScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
time- the time to delay the subscriptionunit- the time unit ofdelayscheduler- theScheduleron which the waiting and subscription will happen- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
dematerialize
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> dematerialize(@NonNull @NonNull Function<? super @NonNull T, Notification<@NonNull R>> selector) Returns anObservablethat reverses the effect ofmaterializeby transforming theNotificationobjects extracted from the source items via a selector function into their respectiveObserversignal types.
The intended use of the
selectorfunction is to perform a type-safe identity mapping (see example) on a source that is already of typeNotification<T>. The Java language doesn't allow limiting instance methods to a certain generic argument shape, therefore, a function is used to ensure the conversion remains type safe.When the upstream signals an
onErrororonCompleteitem, the returnedObservabledisposes of the flow and terminates with that type of terminal event:
If the upstream signalsObservable.just(createOnNext(1), createOnComplete(), createOnNext(2)) .doOnDispose(() -> System.out.println("Disposed!")); .dematerialize(notification -> notification) .test() .assertResult(1);onErrororonCompletedirectly, the flow is terminated with the same event.
If this behavior is not desired, the completion can be suppressed by applyingObservable.just(createOnNext(1), createOnNext(2)) .dematerialize(notification -> notification) .test() .assertResult(1, 2);concatWith(ObservableSource)with anever()source.- Scheduler:
dematerializedoes not operate by default on a particularScheduler.
History: 2.2.4 - experimental
- Type Parameters:
R- the output value type- Parameters:
selector- function that returns the upstream item and should return aNotificationto signal the correspondingObserverevent to the downstream.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifselectorisnull- Since:
- 3.0.0
- See Also:
-
distinct
Returns anObservablethat emits all items emitted by the currentObservablethat are distinct based onObject.equals(Object)comparison.
It is recommended the elements' class
Tin the flow overrides the defaultObject.equals()andObject.hashCode()to provide meaningful comparison between items as the default Java implementation only considers reference equivalence.By default,
distinct()uses an internalHashSetperObserverto remember previously seen items and usesSet.add(Object)returningfalseas the indicator for duplicates.Note that this internal
HashSetmay grow unbounded as items won't be removed from it by the operator. Therefore, using very long or infinite upstream (with very distinct elements) may lead toOutOfMemoryError.Customizing the retention policy can happen only by providing a custom
Collectionimplementation to thedistinct(Function, Supplier)overload.- Scheduler:
distinctdoes not operate by default on a particularScheduler.
- Returns:
- the new
Observableinstance - See Also:
-
distinct
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K> @NonNull Observable<T> distinct(@NonNull @NonNull Function<? super @NonNull T, @NonNull K> keySelector) Returns anObservablethat emits all items emitted by the currentObservablethat are distinct according to a key selector function and based onObject.equals(Object)comparison of the objects returned by the key selector function.
It is recommended the keys' class
Koverrides the defaultObject.equals()andObject.hashCode()to provide meaningful comparison between the key objects as the default Java implementation only considers reference equivalence.By default,
distinct()uses an internalHashSetperObserverto remember previously seen keys and usesSet.add(Object)returningfalseas the indicator for duplicates.Note that this internal
HashSetmay grow unbounded as keys won't be removed from it by the operator. Therefore, using very long or infinite upstream (with very distinct keys) may lead toOutOfMemoryError.Customizing the retention policy can happen only by providing a custom
Collectionimplementation to thedistinct(Function, Supplier)overload.- Scheduler:
distinctdoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key type- Parameters:
keySelector- a function that projects an emitted item to a key value that is used to decide whether an item is distinct from another one or not- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifkeySelectorisnull- See Also:
-
distinct
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K> @NonNull Observable<T> distinct(@NonNull @NonNull Function<? super @NonNull T, @NonNull K> keySelector, @NonNull @NonNull Supplier<? extends Collection<? super @NonNull K>> collectionSupplier) Returns anObservablethat emits all items emitted by the currentObservablethat are distinct according to a key selector function and based onObject.equals(Object)comparison of the objects returned by the key selector function.
It is recommended the keys' class
Koverrides the defaultObject.equals()andObject.hashCode()to provide meaningful comparison between the key objects as the default Java implementation only considers reference equivalence.- Scheduler:
distinctdoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key type- Parameters:
keySelector- a function that projects an emitted item to a key value that is used to decide whether an item is distinct from another one or notcollectionSupplier- function called for each individualObserverto return aCollectionsubtype for holding the extracted keys and whoseadd()method's return indicates uniqueness.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifkeySelectororcollectionSupplierisnull- See Also:
-
distinctUntilChanged
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> distinctUntilChanged()Returns anObservablethat emits all items emitted by the currentObservablethat are distinct from their immediate predecessors based onObject.equals(Object)comparison.
It is recommended the elements' class
Tin the flow overrides the defaultObject.equals()to provide meaningful comparison between items as the default Java implementation only considers reference equivalence. Alternatively, use thedistinctUntilChanged(BiPredicate)overload and provide a comparison function in case the classTcan't be overridden with customequals()or the comparison itself should happen on different terms or properties of the classT.Note that the operator always retains the latest item from upstream regardless of the comparison result and uses it in the next comparison with the next upstream item.
Note that if element type
Tin the flow is mutable, the comparison of the previous and current item may yield unexpected results if the items are mutated externally. Common cases are mutableCharSequences orLists where the objects will actually have the same references when they are modified anddistinctUntilChangedwill evaluate subsequent items as same. To avoid such situation, it is recommended that mutable data is converted to an immutable one, for example usingmap(CharSequence::toString)ormap(list -> Collections.unmodifiableList(new ArrayList<>(list))).- Scheduler:
distinctUntilChangeddoes not operate by default on a particularScheduler.
- Returns:
- the new
Observableinstance - See Also:
-
distinctUntilChanged
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K> @NonNull Observable<T> distinctUntilChanged(@NonNull @NonNull Function<? super @NonNull T, @NonNull K> keySelector) Returns anObservablethat emits all items emitted by the currentObservablethat are distinct from their immediate predecessors, according to a key selector function and based onObject.equals(Object)comparison of those objects returned by the key selector function.
It is recommended the keys' class
Koverrides the defaultObject.equals()to provide meaningful comparison between the key objects as the default Java implementation only considers reference equivalence. Alternatively, use thedistinctUntilChanged(BiPredicate)overload and provide a comparison function in case the classKcan't be overridden with customequals()or the comparison itself should happen on different terms or properties of the item classT(for which the keys can be derived via a similar selector).Note that the operator always retains the latest key from upstream regardless of the comparison result and uses it in the next comparison with the next key derived from the next upstream item.
Note that if element type
Tin the flow is mutable, the comparison of the previous and current item may yield unexpected results if the items are mutated externally. Common cases are mutableCharSequences orLists where the objects will actually have the same references when they are modified anddistinctUntilChangedwill evaluate subsequent items as same. To avoid such situation, it is recommended that mutable data is converted to an immutable one, for example usingmap(CharSequence::toString)ormap(list -> Collections.unmodifiableList(new ArrayList<>(list))).- Scheduler:
distinctUntilChangeddoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key type- Parameters:
keySelector- a function that projects an emitted item to a key value that is used to decide whether an item is distinct from another one or not- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifkeySelectorisnull- See Also:
-
distinctUntilChanged
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> distinctUntilChanged(@NonNull @NonNull BiPredicate<? super @NonNull T, ? super @NonNull T> comparer) Returns anObservablethat emits all items emitted by the currentObservablethat are distinct from their immediate predecessors when compared with each other via the provided comparator function.
Note that the operator always retains the latest item from upstream regardless of the comparison result and uses it in the next comparison with the next upstream item.
Note that if element type
Tin the flow is mutable, the comparison of the previous and current item may yield unexpected results if the items are mutated externally. Common cases are mutableCharSequences orLists where the objects will actually have the same references when they are modified anddistinctUntilChangedwill evaluate subsequent items as same. To avoid such situation, it is recommended that mutable data is converted to an immutable one, for example usingmap(CharSequence::toString)ormap(list -> Collections.unmodifiableList(new ArrayList<>(list))).- Scheduler:
distinctUntilChangeddoes not operate by default on a particularScheduler.
- Parameters:
comparer- the function that receives the previous item and the current item and is expected to returntrueif the two are equal, thus skipping the current value.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifcomparerisnull- Since:
- 2.0
- See Also:
-
doAfterNext
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> doAfterNext(@NonNull @NonNull Consumer<? super @NonNull T> onAfterNext) Calls the specifiedConsumerwith the current item after this item has been emitted to the downstream.Note that the
onAfterNextaction is shared between subscriptions and as such should be thread-safe.
- Scheduler:
doAfterNextdoes not operate by default on a particularScheduler.- Operator-fusion:
- This operator supports boundary-limited synchronous or asynchronous queue-fusion.
History: 2.0.1 - experimental
- Parameters:
onAfterNext- theConsumerthat will be called after emitting an item from upstream to the downstream- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonAfterNextisnull- Since:
- 2.1
-
doAfterTerminate
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> doAfterTerminate(@NonNull @NonNull Action onAfterTerminate) Registers anActionto be called when the currentObservableinvokes eitheronCompleteoronError.
- Scheduler:
doAfterTerminatedoes not operate by default on a particularScheduler.
- Parameters:
onAfterTerminate- anActionto be invoked after the currentObservablefinishes- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonAfterTerminateisnull- See Also:
-
doFinally
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> doFinally(@NonNull @NonNull Action onFinally) Calls the specified action after the currentObservablesignalsonErrororonCompletedor gets disposed by the downstream.In case of a race between a terminal event and a dispose call, the provided
onFinallyaction is executed once per subscription.Note that the
onFinallyaction is shared between subscriptions and as such should be thread-safe.
- Scheduler:
doFinallydoes not operate by default on a particularScheduler.- Operator-fusion:
- This operator supports boundary-limited synchronous or asynchronous queue-fusion.
History: 2.0.1 - experimental
- Parameters:
onFinally- the action called when the currentObservableterminates or gets disposed- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonFinallyisnull- Since:
- 2.1
-
doOnDispose
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> doOnDispose(@NonNull @NonNull Action onDispose) Calls the given sharedActionif the downstream disposes the sequence.The action is shared between subscriptions and thus may be called concurrently from multiple threads; the action must be thread safe.
If the action throws a runtime exception, that exception is rethrown by the
dispose()call, sometimes as aCompositeExceptionif there were multiple exceptions along the way.
- Scheduler:
doOnDisposedoes not operate by default on a particularScheduler.
- Parameters:
onDispose- the action that gets called when the currentObservable'sDisposableis disposed- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonDisposeisnull- See Also:
-
doOnComplete
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> doOnComplete(@NonNull @NonNull Action onComplete) Returns anObservablethat invokes anActionwhen the currentObservablecallsonComplete.
- Scheduler:
doOnCompletedoes not operate by default on a particularScheduler.
- Parameters:
onComplete- the action to invoke when the currentObservablecallsonComplete- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonCompleteisnull- See Also:
-
doOnEach
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> doOnEach(@NonNull @NonNull Consumer<? super Notification<@NonNull T>> onNotification) Returns anObservablethat invokes aConsumerwith the appropriateNotificationobject when the currentObservablesignals an item or terminates.
- Scheduler:
doOnEachdoes not operate by default on a particularScheduler.
- Parameters:
onNotification- the action to invoke for each item emitted by the currentObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonNotificationisnull- See Also:
-
doOnEach
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> doOnEach(@NonNull @NonNull Observer<? super @NonNull T> observer) Returns anObservablethat forwards the items and terminal events of the currentObservableto itsObservers and to the given sharedObserverinstance.In case the
onErrorof the supplied observer throws, the downstream will receive a composite exception containing the original exception and the exception thrown byonError. If either theonNextor theonCompletemethod of the supplied observer throws, the downstream will be terminated and will receive this thrown exception.
- Scheduler:
doOnEachdoes not operate by default on a particularScheduler.
- Parameters:
observer- the observer to be notified aboutonNext,onErrorandonCompleteevents on its respective methods before the actual downstreamObservergets notified.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifobserverisnull- See Also:
-
doOnError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> doOnError(@NonNull @NonNull Consumer<? super Throwable> onError) Calls the givenConsumerwith the errorThrowableif the currentObservablefailed before forwarding it to the downstream.In case the
onErroraction throws, the downstream will receive a composite exception containing the original exception and the exception thrown byonError.
- Scheduler:
doOnErrordoes not operate by default on a particularScheduler.
- Parameters:
onError- the action to invoke if the currentObservablecallsonError- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonErrorisnull- See Also:
-
doOnLifecycle
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> doOnLifecycle(@NonNull @NonNull Consumer<? super Disposable> onSubscribe, @NonNull @NonNull Action onDispose) Calls the appropriateonXXXmethod (shared between allObservers) for the lifecycle events of the sequence (subscription, disposal).
- Scheduler:
doOnLifecycledoes not operate by default on a particularScheduler.
- Parameters:
onSubscribe- aConsumercalled with theDisposablesent viaObserver.onSubscribe(Disposable)onDispose- called when the downstream disposes theDisposableviadispose()- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonSubscribeoronDisposeisnull- See Also:
-
doOnNext
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> doOnNext(@NonNull @NonNull Consumer<? super @NonNull T> onNext) Calls the givenConsumerwith the value emitted by the currentObservablebefore forwarding it to the downstream.
- Scheduler:
doOnNextdoes not operate by default on a particularScheduler.
- Parameters:
onNext- the action to invoke when the currentObservablecallsonNext- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonNextisnull- See Also:
-
doOnSubscribe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> doOnSubscribe(@NonNull @NonNull Consumer<? super Disposable> onSubscribe) Returns anObservableso that it invokes the givenConsumerwhen the currentObservableis subscribed from itsObservers. Each subscription will result in an invocation of the given action except when the currentObservableis reference counted, in which case the currentObservablewill invoke the given action for the first subscription.
- Scheduler:
doOnSubscribedoes not operate by default on a particularScheduler.
- Parameters:
onSubscribe- theConsumerthat gets called when anObserversubscribes to the currentObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonSubscribeisnull- See Also:
-
doOnTerminate
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> doOnTerminate(@NonNull @NonNull Action onTerminate) Returns anObservableso that it invokes an action when the currentObservablecallsonCompleteoronError.
This differs from
doAfterTerminatein that this happens before theonCompleteoronErrornotification.- Scheduler:
doOnTerminatedoes not operate by default on a particularScheduler.
- Parameters:
onTerminate- the action to invoke when the currentObservablecallsonCompleteoronError- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonTerminateisnull- See Also:
-
elementAt
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> elementAt(long index) Returns aMaybethat emits the single item at a specified index in a sequence of emissions from the currentObservableor completes if the currentObservablesignals fewer elements than index.
- Scheduler:
elementAtdoes not operate by default on a particularScheduler.
- Parameters:
index- the zero-based index of the item to retrieve- Returns:
- the new
Maybeinstance - Throws:
IndexOutOfBoundsException- ifindexis negative- See Also:
-
elementAt
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> elementAt(long index, @NonNull @NonNull T defaultItem) Returns aSinglethat emits the item found at a specified index in a sequence of emissions from the currentObservable, or a default item if that index is out of range.
- Scheduler:
elementAtdoes not operate by default on a particularScheduler.
- Parameters:
index- the zero-based index of the item to retrievedefaultItem- the default item- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifdefaultItemisnullIndexOutOfBoundsException- ifindexis negative- See Also:
-
elementAtOrError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> elementAtOrError(long index) Returns aSinglethat emits the item found at a specified index in a sequence of emissions from the currentObservableor signals aNoSuchElementExceptionif the currentObservablesignals fewer elements than index.
- Scheduler:
elementAtOrErrordoes not operate by default on a particularScheduler.
- Parameters:
index- the zero-based index of the item to retrieve- Returns:
- the new
Singleinstance - Throws:
IndexOutOfBoundsException- ifindexis negative- See Also:
-
filter
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> filter(@NonNull @NonNull Predicate<? super @NonNull T> predicate) Filters items emitted by the currentObservableby only emitting those that satisfy a specifiedPredicate.
- Scheduler:
filterdoes not operate by default on a particularScheduler.
- Parameters:
predicate- a function that evaluates each item emitted by the currentObservable, returningtrueif it passes the filter- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifpredicateisnull- See Also:
-
firstElement
-
first
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> first(@NonNull @NonNull T defaultItem) Returns aSinglethat emits only the very first item emitted by the currentObservable, or a default item if the currentObservablecompletes without emitting any items.
- Scheduler:
firstdoes not operate by default on a particularScheduler.
- Parameters:
defaultItem- the default item to emit if the currentObservabledoesn't emit anything- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifdefaultItemisnull- See Also:
-
firstOrError
Returns aSinglethat emits only the very first item emitted by the currentObservableor signals aNoSuchElementExceptionif the currentObservableis empty.
- Scheduler:
firstOrErrordoes not operate by default on a particularScheduler.
- Returns:
- the new
Singleinstance - See Also:
-
flatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper) Returns anObservablethat emits items based on applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then merging those returnedObservableSources and emitting the results of this merger.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the value type of the innerObservableSources and the output type- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns anObservableSource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
flatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean delayErrors) Returns anObservablethat emits items based on applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then merging those returnedObservableSources and emitting the results of this merger.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the value type of the innerObservableSources and the output type- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns anObservableSourcedelayErrors- iftrue, exceptions from the currentObservableand all innerObservableSources are delayed until all of them terminate iffalse, the first one signaling an exception will terminate the whole sequence immediately- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
flatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean delayErrors, int maxConcurrency) Returns anObservablethat emits items based on applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then merging those returnedObservableSources and emitting the results of this merger, while limiting the maximum number of concurrent subscriptions to theseObservableSources.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the value type of the innerObservableSources and the output type- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns anObservableSourcedelayErrors- iftrue, exceptions from the currentObservableand all innerObservableSources are delayed until all of them terminate iffalse, the first one signaling an exception will terminate the whole sequence immediatelymaxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrently- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 2.0
- See Also:
-
flatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, boolean delayErrors, int maxConcurrency, int bufferSize) Returns anObservablethat emits items based on applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then merging those returnedObservableSources and emitting the results of this merger, while limiting the maximum number of concurrent subscriptions to theseObservableSources.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the value type of the innerObservableSources and the output type- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns anObservableSourcedelayErrors- iftrue, exceptions from the currentObservableand all innerObservableSources are delayed until all of them terminate iffalse, the first one signaling an exception will terminate the whole sequence immediatelymaxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrentlybufferSize- the number of elements expected from each innerObservableSourceto be buffered- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- Since:
- 2.0
- See Also:
-
flatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> onNextMapper, @NonNull @NonNull Function<? super Throwable, ? extends ObservableSource<? extends @NonNull R>> onErrorMapper, @NonNull @NonNull Supplier<? extends ObservableSource<? extends @NonNull R>> onCompleteSupplier) Returns anObservablethat applies a function to each item emitted or notification raised by the currentObservableand then flattens theObservableSources returned from these functions and emits the resulting items.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result type- Parameters:
onNextMapper- a function that returns anObservableSourceto merge for each item emitted by the currentObservableonErrorMapper- a function that returns anObservableSourceto merge for anonErrornotification from the currentObservableonCompleteSupplier- a function that returns anObservableSourceto merge for anonCompletenotification from the currentObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonNextMapperoronErrorMapperoronCompleteSupplierisnull- See Also:
-
flatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> onNextMapper, @NonNull @NonNull Function<Throwable, ? extends ObservableSource<? extends @NonNull R>> onErrorMapper, @NonNull @NonNull Supplier<? extends ObservableSource<? extends @NonNull R>> onCompleteSupplier, int maxConcurrency) Returns anObservablethat applies a function to each item emitted or notification raised by the currentObservableand then flattens theObservableSources returned from these functions and emits the resulting items, while limiting the maximum number of concurrent subscriptions to theseObservableSources.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result type- Parameters:
onNextMapper- a function that returns anObservableSourceto merge for each item emitted by the currentObservableonErrorMapper- a function that returns anObservableSourceto merge for anonErrornotification from the currentObservableonCompleteSupplier- a function that returns anObservableSourceto merge for anonCompletenotification from the currentObservablemaxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrently- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifonNextMapperoronErrorMapperoronCompleteSupplierisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 2.0
- See Also:
-
flatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, int maxConcurrency) Returns anObservablethat emits items based on applying a function that you supply to each item emitted by the currentObservable, where that function returns anObservableSource, and then merging those returnedObservableSources and emitting the results of this merger, while limiting the maximum number of concurrent subscriptions to theseObservableSources.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the value type of the innerObservableSources and the output type- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns anObservableSourcemaxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrently- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 2.0
- See Also:
-
flatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull R> @NonNull Observable<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull U>> mapper, @NonNull @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> combiner) Returns anObservablethat emits the results of a specified function to the pair of values emitted by the currentObservableand the mapped innerObservableSource.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted by the collectionObservableSourceR- the type of items emitted by the resultingObservable- Parameters:
mapper- a function that returns anObservableSourcefor each item emitted by the currentObservablecombiner- a function that combines one item emitted by each of the source and collectionObservableSources and returns an item to be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperorcombinerisnull- See Also:
-
flatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull R> @NonNull Observable<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull U>> mapper, @NonNull @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> combiner, boolean delayErrors) Returns anObservablethat emits the results of a specified function to the pair of values emitted by the currentObservableand the mapped innerObservableSource.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted by the collectionObservableSourceR- the type of items emitted by the resultingObservable- Parameters:
mapper- a function that returns anObservableSourcefor each item emitted by the currentObservablecombiner- a function that combines one item emitted by each of the source and collectionObservableSources and returns an item to be emitted by the resultingObservabledelayErrors- iftrue, exceptions from the currentObservableand all innerObservableSources are delayed until all of them terminate iffalse, the first one signaling an exception will terminate the whole sequence immediately- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperorcombinerisnull- See Also:
-
flatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull R> @NonNull Observable<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull U>> mapper, @NonNull @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> combiner, boolean delayErrors, int maxConcurrency) Returns anObservablethat emits the results of a specified function to the pair of values emitted by the currentObservableand the mapped innerObservableSource, while limiting the maximum number of concurrent subscriptions to theseObservableSources.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted by the collectionObservableSourceR- the type of items emitted by the resultingObservable- Parameters:
mapper- a function that returns anObservableSourcefor each item emitted by the currentObservablecombiner- a function that combines one item emitted by each of the source and collectionObservableSources and returns an item to be emitted by the resultingObservabledelayErrors- iftrue, exceptions from the currentObservableand all innerObservableSources are delayed until all of them terminate iffalse, the first one signaling an exception will terminate the whole sequence immediatelymaxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrently- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperorcombinerisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 2.0
- See Also:
-
flatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull R> @NonNull Observable<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull U>> mapper, @NonNull @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> combiner, boolean delayErrors, int maxConcurrency, int bufferSize) Returns anObservablethat emits the results of a specified function to the pair of values emitted by the currentObservableand the mapped innerObservableSource, while limiting the maximum number of concurrent subscriptions to theseObservableSources.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted by the collectionObservableSourceR- the type of items emitted by the resultingObservable- Parameters:
mapper- a function that returns anObservableSourcefor each item emitted by the currentObservablecombiner- a function that combines one item emitted by each of the source and collectionObservableSources and returns an item to be emitted by the resultingObservabledelayErrors- iftrue, exceptions from the currentObservableand all innerObservableSources are delayed until all of them terminate iffalse, the first one signaling an exception will terminate the whole sequence immediatelymaxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrentlybufferSize- the number of elements expected from the innerObservableSourceto be buffered- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperorcombinerisnullIllegalArgumentException- ifmaxConcurrencyorbufferSizeis non-positive- Since:
- 2.0
- See Also:
-
flatMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull R> @NonNull Observable<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull U>> mapper, @NonNull @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> combiner, int maxConcurrency) Returns anObservablethat emits the results of a specified function to the pair of values emitted by the currentObservableand the mapped innerObservableSource, while limiting the maximum number of concurrent subscriptions to theseObservableSources.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted by the collectionObservableSourceR- the type of items emitted by the resultingObservable- Parameters:
mapper- a function that returns anObservableSourcefor each item emitted by the currentObservablecombiner- a function that combines one item emitted by each of the source and collectionObservableSources and returns an item to be emitted by the resultingObservablemaxConcurrency- the maximum number ofObservableSources that may be subscribed to concurrently- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperorcombinerisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 2.0
- See Also:
-
flatMapCompletable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable flatMapCompletable(@NonNull @NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Maps each element of the currentObservableintoCompletableSources, subscribes to them and waits until the upstream and allCompletableSources complete.
- Scheduler:
flatMapCompletabledoes not operate by default on a particularScheduler.
- Parameters:
mapper- the function that received each source value and transforms them intoCompletableSources.- Returns:
- the new
Completableinstance - Throws:
NullPointerException- ifmapperisnull
-
flatMapCompletable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable flatMapCompletable(@NonNull @NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper, boolean delayErrors) Maps each element of the currentObservableintoCompletableSources, subscribes to them and waits until the upstream and allCompletableSources complete, optionally delaying all errors.
- Scheduler:
flatMapCompletabledoes not operate by default on a particularScheduler.
- Parameters:
mapper- the function that received each source value and transforms them intoCompletableSources.delayErrors- iftrue, errors from the upstream and innerCompletableSources are delayed until all of them terminate.- Returns:
- the new
Completableinstance - Throws:
NullPointerException- ifmapperisnull
-
flatMapIterable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U> @NonNull Observable<U> flatMapIterable(@NonNull @NonNull Function<? super @NonNull T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper) MergesIterables generated by a mapperFunctionfor each individual item emitted by the currentObservableinto a singleObservablesequence.
- Scheduler:
flatMapIterabledoes not operate by default on a particularScheduler.
- Type Parameters:
U- the output type and the element type of theIterables- Parameters:
mapper- a function that returns anIterablesequence of values for when given an item emitted by the currentObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
flatMapIterable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull V> @NonNull Observable<V> flatMapIterable(@NonNull @NonNull Function<? super @NonNull T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper, @NonNull @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull V> combiner) MergesIterables generated by a mapperFunctionfor each individual item emitted by the currentObservableinto a singleObservablesequence where the resulting items will be the combination of the original item and each inner item of the respectiveIterableas returned by theresultSelectorBiFunction.
- Scheduler:
flatMapIterabledoes not operate by default on a particularScheduler.
- Type Parameters:
U- the element type of theIterablesV- the output type as determined by theresultSelectorfunction- Parameters:
mapper- a function that returns anIterablesequence of values for each item emitted by the currentObservablecombiner- a function that returns an item based on the item emitted by the currentObservableand the next item of theIterablereturned for that original item by themapper- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperorcombinerisnull- See Also:
-
flatMapMaybe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flatMapMaybe(@NonNull @NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper) Maps each element of the currentObservableintoMaybeSources, subscribes to all of them and merges theironSuccessvalues, in no particular order, into a singleObservablesequence.
- Scheduler:
flatMapMaybedoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- the function that received each source value and transforms them intoMaybeSources.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull
-
flatMapMaybe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flatMapMaybe(@NonNull @NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper, boolean delayErrors) Maps each element of the currentObservableintoMaybeSources, subscribes to them and merges theironSuccessvalues, in no particular order, into a singleObservablesequence, optionally delaying all errors.
- Scheduler:
flatMapMaybedoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- the function that received each source value and transforms them intoMaybeSources.delayErrors- iftrue, errors from the upstream and innerMaybeSources are delayed until all of them terminate.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull
-
flatMapSingle
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flatMapSingle(@NonNull @NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Maps each element of the currentObservableintoSingleSources, subscribes to all of them and merges theironSuccessvalues, in no particular order, into a singleObservablesequence.
- Scheduler:
flatMapSingledoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- the function that received each source value and transforms them intoSingleSources.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull
-
flatMapSingle
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flatMapSingle(@NonNull @NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper, boolean delayErrors) Maps each element of the currentObservableintoSingleSources, subscribes to them and merges theironSuccessvalues, in no particular order, into a singleObservablesequence, optionally delaying all errors.
- Scheduler:
flatMapSingledoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- the function that received each source value and transforms them intoSingleSources.delayErrors- iftrue, errors from the upstream and innerSingleSources are delayed until each of them terminates.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull
-
forEach
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Disposable forEach(@NonNull @NonNull Consumer<? super @NonNull T> onNext) Subscribes to theObservableSourceand calls aConsumerfor each item of the currentObservableon its emission thread.
Alias to
subscribe(Consumer)- Scheduler:
forEachdoes not operate by default on a particularScheduler.
- Parameters:
onNext- theConsumerto execute for each item.- Returns:
- a
Disposablethat allows disposing the sequence if the currentObservableruns asynchronously - Throws:
NullPointerException- ifonNextisnull- See Also:
-
forEachWhile
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Disposable forEachWhile(@NonNull @NonNull Predicate<? super @NonNull T> onNext) Subscribes to theObservableSourceand calls aPredicatefor each item of the currentObservable, on its emission thread, until the predicate returnsfalse.
If the
Observableemits an error, it is wrapped into anOnErrorNotImplementedExceptionand routed to theRxJavaPlugins.onError(Throwable)handler.- Scheduler:
forEachWhiledoes not operate by default on a particularScheduler.
- Parameters:
onNext- thePredicateto execute for each item.- Returns:
- a
Disposablethat allows disposing the sequence if the currentObservableruns asynchronously - Throws:
NullPointerException- ifonNextisnull- See Also:
-
forEachWhile
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Disposable forEachWhile(@NonNull @NonNull Predicate<? super @NonNull T> onNext, @NonNull @NonNull Consumer<? super Throwable> onError) Subscribes to theObservableSourceand calls aPredicatefor each item or aConsumerwith the error of the currentObservable, on their original emission threads, until the predicate returnsfalse.- Scheduler:
forEachWhiledoes not operate by default on a particularScheduler.
- Parameters:
onNext- thePredicateto execute for each item.onError- theConsumerto execute when an error is emitted.- Returns:
- a
Disposablethat allows disposing the sequence if the currentObservableruns asynchronously - Throws:
NullPointerException- ifonNextoronErrorisnull- See Also:
-
forEachWhile
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Disposable forEachWhile(@NonNull @NonNull Predicate<? super @NonNull T> onNext, @NonNull @NonNull Consumer<? super Throwable> onError, @NonNull @NonNull Action onComplete) Subscribes to theObservableSourceand calls aPredicatefor each item, aConsumerwith the error or anActionupon completion of the currentObservable, on their original emission threads, until the predicate returnsfalse.- Scheduler:
forEachWhiledoes not operate by default on a particularScheduler.
- Parameters:
onNext- thePredicateto execute for each item.onError- theConsumerto execute when an error is emitted.onComplete- theActionto execute when completion is signaled.- Returns:
- a
Disposablethat allows disposing the sequence if the currentObservableruns asynchronously - Throws:
NullPointerException- ifonNextoronErrororonCompleteisnull- See Also:
-
groupBy
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K> @NonNull Observable<GroupedObservable<K,T>> groupBy(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector) Groups the items emitted by the currentObservableaccording to a specified criterion, and emits these grouped items asGroupedObservables.
Each emitted
GroupedObservableallows only a singleObserverto subscribe to it during its lifetime and if thisObservercallsdispose()before the source terminates, the next emission by the source having the same key will trigger a newGroupedObservableemission.Note: A
GroupedObservablewill cache the items it is to emit until such time as it is subscribed to. For this reason, in order to avoid memory leaks, you should not simply ignore thoseGroupedObservables that do not concern you. Instead, you can signal to them that they may discard their buffers by applying an operator likeignoreElements()to them.Note also that ignoring groups or subscribing later (i.e., on another thread) will result in so-called group abandonment where a group will only contain one element and the group will be re-created over and over as new upstream items trigger a new group. The behavior is a trade-off between no-dataloss, upstream cancellation and excessive group creation.
- Scheduler:
groupBydoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key type- Parameters:
keySelector- a function that extracts the key for each item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifkeySelectorisnull- See Also:
-
groupBy
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K> @NonNull Observable<GroupedObservable<K,T>> groupBy(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, boolean delayError) Groups the items emitted by the currentObservableaccording to a specified criterion, and emits these grouped items asGroupedObservables.
Each emitted
GroupedObservableallows only a singleObserverto subscribe to it during its lifetime and if thisObservercallsdispose()before the source terminates, the next emission by the source having the same key will trigger a newGroupedObservableemission.Note: A
GroupedObservablewill cache the items it is to emit until such time as it is subscribed to. For this reason, in order to avoid memory leaks, you should not simply ignore thoseGroupedObservables that do not concern you. Instead, you can signal to them that they may discard their buffers by applying an operator likeignoreElements()to them.Note also that ignoring groups or subscribing later (i.e., on another thread) will result in so-called group abandonment where a group will only contain one element and the group will be re-created over and over as new upstream items trigger a new group. The behavior is a trade-off between no-dataloss, upstream cancellation and excessive group creation.
- Scheduler:
groupBydoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key type- Parameters:
keySelector- a function that extracts the key for each itemdelayError- iftrue, the exception from the currentObservableis delayed in each group until that specific group emitted the normal values; iffalse, the exception bypasses values in the groups and is reported immediately.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifkeySelectorisnull- See Also:
-
groupBy
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K, @NonNull V> @NonNull Observable<GroupedObservable<K,V>> groupBy(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, Function<? super @NonNull T, ? extends @NonNull V> valueSelector) Groups the items emitted by the currentObservableaccording to a specified criterion, and emits these grouped items asGroupedObservables.
Each emitted
GroupedObservableallows only a singleObserverto subscribe to it during its lifetime and if thisObservercallsdispose()before the source terminates, the next emission by the source having the same key will trigger a newGroupedObservableemission.Note: A
GroupedObservablewill cache the items it is to emit until such time as it is subscribed to. For this reason, in order to avoid memory leaks, you should not simply ignore thoseGroupedObservables that do not concern you. Instead, you can signal to them that they may discard their buffers by applying an operator likeignoreElements()to them.Note also that ignoring groups or subscribing later (i.e., on another thread) will result in so-called group abandonment where a group will only contain one element and the group will be re-created over and over as new upstream items trigger a new group. The behavior is a trade-off between no-dataloss, upstream cancellation and excessive group creation.
- Scheduler:
groupBydoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key typeV- the element type- Parameters:
keySelector- a function that extracts the key for each itemvalueSelector- a function that extracts the return element for each item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifkeySelectororvalueSelectorisnull- See Also:
-
groupBy
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K, @NonNull V> @NonNull Observable<GroupedObservable<K,V>> groupBy(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, @NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull V> valueSelector, boolean delayError) Groups the items emitted by the currentObservableaccording to a specified criterion, and emits these grouped items asGroupedObservables.
Each emitted
GroupedObservableallows only a singleObserverto subscribe to it during its lifetime and if thisObservercallsdispose()before the source terminates, the next emission by the source having the same key will trigger a newGroupedObservableemission.Note: A
GroupedObservablewill cache the items it is to emit until such time as it is subscribed to. For this reason, in order to avoid memory leaks, you should not simply ignore thoseGroupedObservables that do not concern you. Instead, you can signal to them that they may discard their buffers by applying an operator likeignoreElements()to them.Note also that ignoring groups or subscribing later (i.e., on another thread) will result in so-called group abandonment where a group will only contain one element and the group will be re-created over and over as new upstream items trigger a new group. The behavior is a trade-off between no-dataloss, upstream cancellation and excessive group creation.
- Scheduler:
groupBydoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key typeV- the element type- Parameters:
keySelector- a function that extracts the key for each itemvalueSelector- a function that extracts the return element for each itemdelayError- iftrue, the exception from the currentObservableis delayed in each group until that specific group emitted the normal values; iffalse, the exception bypasses values in the groups and is reported immediately.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifkeySelectororvalueSelectorisnull- See Also:
-
groupBy
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K, @NonNull V> @NonNull Observable<GroupedObservable<K,V>> groupBy(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, @NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull V> valueSelector, boolean delayError, int bufferSize) Groups the items emitted by the currentObservableaccording to a specified criterion, and emits these grouped items asGroupedObservables.
Each emitted
GroupedObservableallows only a singleObserverto subscribe to it during its lifetime and if thisObservercallsdispose()before the source terminates, the next emission by the source having the same key will trigger a newGroupedObservableemission.Note: A
GroupedObservablewill cache the items it is to emit until such time as it is subscribed to. For this reason, in order to avoid memory leaks, you should not simply ignore thoseGroupedObservables that do not concern you. Instead, you can signal to them that they may discard their buffers by applying an operator likeignoreElements()to them.Note also that ignoring groups or subscribing later (i.e., on another thread) will result in so-called group abandonment where a group will only contain one element and the group will be re-created over and over as new upstream items trigger a new group. The behavior is a trade-off between no-dataloss, upstream cancellation and excessive group creation.
- Scheduler:
groupBydoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key typeV- the element type- Parameters:
keySelector- a function that extracts the key for each itemvalueSelector- a function that extracts the return element for each itemdelayError- iftrue, the exception from the currentObservableis delayed in each group until that specific group emitted the normal values; iffalse, the exception bypasses values in the groups and is reported immediately.bufferSize- the hint for how manyGroupedObservables and element in eachGroupedObservableshould be buffered- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifkeySelectororvalueSelectorisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
groupJoin
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull TRight, @NonNull TLeftEnd, @NonNull TRightEnd, @NonNull R> @NonNull Observable<R> groupJoin(@NonNull @NonNull ObservableSource<? extends @NonNull TRight> other, @NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull TLeftEnd>> leftEnd, @NonNull @NonNull Function<? super @NonNull TRight, ? extends ObservableSource<@NonNull TRightEnd>> rightEnd, @NonNull @NonNull BiFunction<? super @NonNull T, ? super Observable<@NonNull TRight>, ? extends @NonNull R> resultSelector) Returns anObservablethat correlates twoObservableSources when they overlap in time and groups the results.There are no guarantees in what order the items get combined when multiple items from one or both source
ObservableSources overlap.
- Scheduler:
groupJoindoes not operate by default on a particularScheduler.
- Type Parameters:
TRight- the value type of the rightObservableSourcesourceTLeftEnd- the element type of the left durationObservableSourcesTRightEnd- the element type of the right durationObservableSourcesR- the result type- Parameters:
other- the otherObservableSourceto correlate items from the currentObservablewithleftEnd- a function that returns anObservableSourcewhose emissions indicate the duration of the values of the currentObservablerightEnd- a function that returns anObservableSourcewhose emissions indicate the duration of the values of therightObservableSourceresultSelector- a function that takes an item emitted by eachObservableSourceand returns the value to be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifother,leftEnd,rightEndorresultSelectorisnull- See Also:
-
hide
Hides the identity of the currentObservableand itsDisposable.Allows hiding extra features such as
Subject'sObservermethods or preventing certain identity-based optimizations (fusion).
- Scheduler:
hidedoes not operate by default on a particularScheduler.
- Returns:
- the new
Observableinstance - Since:
- 2.0
-
ignoreElements
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable ignoreElements()Ignores all items emitted by the currentObservableand only callsonCompleteoronError.
- Scheduler:
ignoreElementsdoes not operate by default on a particularScheduler.
- Returns:
- the new
Completableinstance - See Also:
-
isEmpty
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<Boolean> isEmpty()Returns aSinglethat emitstrueif the currentObservableis empty, otherwisefalse.In Rx.Net this is negated as the
anyObserverbut we renamed this in RxJava to better match Java naming idioms.
- Scheduler:
isEmptydoes not operate by default on a particularScheduler.
- Returns:
- the new
Singleinstance - See Also:
-
join
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull TRight, @NonNull TLeftEnd, @NonNull TRightEnd, @NonNull R> @NonNull Observable<R> join(@NonNull @NonNull ObservableSource<? extends @NonNull TRight> other, @NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull TLeftEnd>> leftEnd, @NonNull @NonNull Function<? super @NonNull TRight, ? extends ObservableSource<@NonNull TRightEnd>> rightEnd, @NonNull @NonNull BiFunction<? super @NonNull T, ? super @NonNull TRight, ? extends @NonNull R> resultSelector) Correlates the items emitted by twoObservableSources based on overlapping durations.There are no guarantees in what order the items get combined when multiple items from one or both source
ObservableSources overlap.
- Scheduler:
joindoes not operate by default on a particularScheduler.
- Type Parameters:
TRight- the value type of the rightObservableSourcesourceTLeftEnd- the element type of the left durationObservableSourcesTRightEnd- the element type of the right durationObservableSourcesR- the result type- Parameters:
other- the secondObservableSourceto join items fromleftEnd- a function to select a duration for each item emitted by the currentObservable, used to determine overlaprightEnd- a function to select a duration for each item emitted by therightObservableSource, used to determine overlapresultSelector- a function that computes an item to be emitted by the resultingObservablefor any two overlapping items emitted by the twoObservableSources- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifother,leftEnd,rightEndorresultSelectorisnull- See Also:
-
lastElement
-
last
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> last(@NonNull @NonNull T defaultItem) Returns aSinglethat emits only the last item emitted by the currentObservable, or a default item if the currentObservablecompletes without emitting any items.
- Scheduler:
lastdoes not operate by default on a particularScheduler.
- Parameters:
defaultItem- the default item to emit if the currentObservableis empty- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifdefaultItemisnull- See Also:
-
lastOrError
Returns aSinglethat emits only the last item emitted by the currentObservableor signals aNoSuchElementExceptionif the currentObservableis empty.
- Scheduler:
lastOrErrordoes not operate by default on a particularScheduler.
- Returns:
- the new
Singleinstance - See Also:
-
lift
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> lift(@NonNull @NonNull ObservableOperator<? extends @NonNull R, ? super @NonNull T> lifter) This method requires advanced knowledge about building operators, please consider other standard composition methods first; Returns anObservablewhich, when subscribed to, invokes theapply(Observer)method of the providedObservableOperatorfor each individual downstreamObserverand allows the insertion of a custom operator by accessing the downstream'sObserverduring this subscription phase and providing a newObserver, containing the custom operator's intended business logic, that will be used in the subscription process going further upstream.Generally, such a new
Observerwill wrap the downstream'sObserverand forwards theonNext,onErrorandonCompleteevents from the upstream directly or according to the emission pattern the custom operator's business logic requires. In addition, such operator can intercept the flow control calls ofdisposeandisDisposedthat would have traveled upstream and perform additional actions depending on the same business logic requirements.Example:
// Step 1: Create the consumer type that will be returned by the ObservableOperator.apply(): public final class CustomObserver<T> implements Observer<T>, Disposable { // The downstream's Observer that will receive the onXXX events final Observer<? super String> downstream; // The connection to the upstream source that will call this class' onXXX methods Disposable upstream; // The constructor takes the downstream subscriber and usually any other parameters public CustomObserver(Observer<? super String> downstream) { this.downstream = downstream; } // In the subscription phase, the upstream sends a Disposable to this class // and subsequently this class has to send a Disposable to the downstream. // Note that relaying the upstream's Disposable directly is not allowed in RxJava @Override public void onSubscribe(Disposable d) { if (upstream != null) { d.dispose(); } else { upstream = d; downstream.onSubscribe(this); } } // The upstream calls this with the next item and the implementation's // responsibility is to emit an item to the downstream based on the intended // business logic, or if it can't do so for the particular item, // request more from the upstream @Override public void onNext(T item) { String str = item.toString(); if (str.length() < 2) { downstream.onNext(str); } // Observable doesn't support backpressure, therefore, there is no // need or opportunity to call upstream.request(1) if an item // is not produced to the downstream } // Some operators may handle the upstream's error while others // could just forward it to the downstream. @Override public void onError(Throwable throwable) { downstream.onError(throwable); } // When the upstream completes, usually the downstream should complete as well. @Override public void onComplete() { downstream.onComplete(); } // Some operators may use their own resources which should be cleaned up if // the downstream disposes the flow before it completed. Operators without // resources can simply forward the dispose to the upstream. // In some cases, a disposed flag may be set by this method so that other parts // of this class may detect the dispose and stop sending events // to the downstream. @Override public void dispose() { upstream.dispose(); } // Some operators may simply forward the call to the upstream while others // can return the disposed flag set in dispose(). @Override public boolean isDisposed() { return upstream.isDisposed(); } } // Step 2: Create a class that implements the ObservableOperator interface and // returns the custom consumer type from above in its apply() method. // Such class may define additional parameters to be submitted to // the custom consumer type. final class CustomOperator<T> implements ObservableOperator<String, T> { @Override public Observer<T> apply(Observer<? super String> downstream) { return new CustomObserver<T>(downstream); } } // Step 3: Apply the custom operator via lift() in a flow by creating an instance of it // or reusing an existing one. Observable.range(5, 10) .lift(new CustomOperator<Integer>()) .test() .assertResult("5", "6", "7", "8", "9");Creating custom operators can be complicated and it is recommended one consults the RxJava wiki: Writing operators page about the tools, requirements, rules, considerations and pitfalls of implementing them.
Note that implementing custom operators via this
lift()method adds slightly more overhead by requiring an additional allocation and indirection per assembled flows. Instead, extending the abstractObservableclass and creating anObservableTransformerwith it is recommended.Note also that it is not possible to stop the subscription phase in
lift()as theapply()method requires a non-nullObserverinstance to be returned, which is then unconditionally subscribed to the currentObservable. For example, if the operator decided there is no reason to subscribe to the upstream source because of some optimization possibility or a failure to prepare the operator, it still has to return anObserverthat should immediately dispose the upstream'sDisposablein itsonSubscribemethod. Again, using anObservableTransformerand extending theObservableis a better option assubscribeActual(Observer)can decide to not subscribe to its upstream after all.- Scheduler:
liftdoes not operate by default on a particularScheduler, however, theObservableOperatormay use aSchedulerto support its own asynchronous behavior.
- Type Parameters:
R- the output value type- Parameters:
lifter- theObservableOperatorthat receives the downstream'sObserverand should return anObserverwith custom behavior to be used as the consumer for the currentObservable.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- iflifterisnull- See Also:
-
map
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> map(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull R> mapper) Returns anObservablethat applies a specified function to each item emitted by the currentObservableand emits the results of these function applications.
- Scheduler:
mapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the output type- Parameters:
mapper- a function to apply to each item emitted by the currentObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
materialize
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<Notification<T>> materialize()Returns anObservablethat represents all of the emissions and notifications from the currentObservableinto emissions marked with their original types withinNotificationobjects.
- Scheduler:
materializedoes not operate by default on a particularScheduler.
- Returns:
- the new
Observableinstance - See Also:
-
mergeWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> mergeWith(@NonNull @NonNull ObservableSource<? extends @NonNull T> other) Flattens the currentObservableand anotherObservableSourceinto a singleObservablesequence, without any transformation.
You can combine items emitted by multiple
ObservableSources so that they appear as a singleObservableSource, by using themergeWithmethod.- Scheduler:
mergeWithdoes not operate by default on a particularScheduler.
- Parameters:
other- anObservableSourceto be merged- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- See Also:
-
mergeWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> mergeWith(@NonNull @NonNull SingleSource<? extends @NonNull T> other) Merges the sequence of items of the currentObservablewith the success value of the otherSingleSource.
The success value of the other
SingleSourcecan get interleaved at any point of the currentObservablesequence.- Scheduler:
mergeWithdoes not operate by default on a particularScheduler.
History: 2.1.10 - experimental
- Parameters:
other- theSingleSourcewhose success value to merge with- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 2.2
-
mergeWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> mergeWith(@NonNull @NonNull MaybeSource<? extends @NonNull T> other) Merges the sequence of items of the currentObservablewith the success value of the otherMaybeSourceor waits both to complete normally if theMaybeSourceis empty.
The success value of the other
MaybeSourcecan get interleaved at any point of the currentObservablesequence.- Scheduler:
mergeWithdoes not operate by default on a particularScheduler.
History: 2.1.10 - experimental
- Parameters:
other- theMaybeSourcewhich provides a success value to merge with or completes- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 2.2
-
mergeWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> mergeWith(@NonNull @NonNull CompletableSource other) Relays the items of the currentObservableand completes only when the otherCompletableSourcecompletes as well.
- Scheduler:
mergeWithdoes not operate by default on a particularScheduler.
History: 2.1.10 - experimental
- Parameters:
other- theCompletableSourceto await for completion- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 2.2
-
observeOn
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> observeOn(@NonNull @NonNull Scheduler scheduler) Returns anObservableto perform the currentObservable's emissions and notifications on a specifiedScheduler, asynchronously with an unbounded buffer withFlowable.bufferSize()"island size".Note that
onErrornotifications will cut ahead ofonNextnotifications on the emission thread ifScheduleris truly asynchronous. If strict event ordering is required, consider using theobserveOn(Scheduler, boolean)overload.
This operator keeps emitting as many signals as it can on the given
Scheduler's worker thread, which may result in a longer than expected occupation of this thread. In other terms, it does not allow per-signal fairness in case the worker runs on a shared underlying thread. If such fairness and signal/work interleaving is preferred, use the delay operator with zero time instead.- Scheduler:
- You specify which
Schedulerthis operator will use.
"Island size" indicates how large chunks the unbounded buffer allocates to store the excess elements waiting to be consumed on the other side of the asynchronous boundary.
- Parameters:
scheduler- theSchedulerto notifyObservers on- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifschedulerisnull- See Also:
-
observeOn
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> observeOn(@NonNull @NonNull Scheduler scheduler, boolean delayError) Returns anObservableto perform the currentObservable's emissions and notifications on a specifiedScheduler, asynchronously with an unbounded buffer withFlowable.bufferSize()"island size" and optionally delaysonErrornotifications.
This operator keeps emitting as many signals as it can on the given
Scheduler's worker thread, which may result in a longer than expected occupation of this thread. In other terms, it does not allow per-signal fairness in case the worker runs on a shared underlying thread. If such fairness and signal/work interleaving is preferred, use the delay operator with zero time instead.- Scheduler:
- You specify which
Schedulerthis operator will use.
"Island size" indicates how large chunks the unbounded buffer allocates to store the excess elements waiting to be consumed on the other side of the asynchronous boundary.
- Parameters:
scheduler- theSchedulerto notifyObservers ondelayError- indicates if theonErrornotification may not cut ahead ofonNextnotification on the other side of the scheduling boundary. Iftrue, a sequence ending inonErrorwill be replayed in the same order as was received from the currentObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifschedulerisnull- See Also:
-
observeOn
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> observeOn(@NonNull @NonNull Scheduler scheduler, boolean delayError, int bufferSize) Returns anObservableto perform the currentObservable's emissions and notifications on a specifiedScheduler, asynchronously with an unbounded buffer of configurable "island size" and optionally delaysonErrornotifications.
This operator keeps emitting as many signals as it can on the given
Scheduler's worker thread, which may result in a longer than expected occupation of this thread. In other terms, it does not allow per-signal fairness in case the worker runs on a shared underlying thread. If such fairness and signal/work interleaving is preferred, use the delay operator with zero time instead.- Scheduler:
- You specify which
Schedulerthis operator will use.
"Island size" indicates how large chunks the unbounded buffer allocates to store the excess elements waiting to be consumed on the other side of the asynchronous boundary. Values below 16 are not recommended in performance sensitive scenarios.
- Parameters:
scheduler- theSchedulerto notifyObservers ondelayError- indicates if theonErrornotification may not cut ahead ofonNextnotification on the other side of the scheduling boundary. Iftruea sequence ending inonErrorwill be replayed in the same order as was received from upstreambufferSize- the size of the buffer.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifschedulerisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
ofType
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U> @NonNull Observable<U> ofType(@NonNull @NonNull Class<@NonNull U> clazz) Filters the items emitted by the currentObservable, only emitting those of the specified type.
- Scheduler:
ofTypedoes not operate by default on a particularScheduler.
- Type Parameters:
U- the output type- Parameters:
clazz- the class type to filter the items emitted by the currentObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifclazzisnull- See Also:
-
onErrorComplete
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> onErrorComplete()Returns anObservableinstance that if the currentObservableemits an error, it will emit anonCompleteand swallow the throwable.
- Scheduler:
onErrorCompletedoes not operate by default on a particularScheduler.
- Returns:
- the new
Observableinstance - Since:
- 3.0.0
-
onErrorComplete
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Observable<T> onErrorComplete(@NonNull @NonNull Predicate<? super Throwable> predicate) Returns anObservableinstance that if the currentObservableemits an error and the predicate returnstrue, it will emit anonCompleteand swallow the throwable.
- Scheduler:
onErrorCompletedoes not operate by default on a particularScheduler.
- Parameters:
predicate- the predicate to call when anThrowableis emitted which should returntrueif theThrowableshould be swallowed and replaced with anonComplete.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifpredicateisnull- Since:
- 3.0.0
-
onErrorResumeNext
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> onErrorResumeNext(@NonNull @NonNull Function<? super Throwable, ? extends ObservableSource<? extends @NonNull T>> fallbackSupplier) Resumes the flow with anObservableSourcereturned for the failureThrowableof the currentObservableby a function instead of signaling the error viaonError.
By default, when an
ObservableSourceencounters an error that prevents it from emitting the expected item to itsObserver, theObservableSourceinvokes itsObserver'sonErrormethod, and then quits without invoking any more of itsObserver's methods. TheonErrorResumeNextmethod changes this behavior. If you pass a function that returns anObservableSource(resumeFunction) toonErrorResumeNext, if the originalObservableSourceencounters an error, instead of invoking itsObserver'sonErrormethod, it will instead relinquish control to theObservableSourcereturned fromresumeFunction, which will invoke theObserver'sonNextmethod if it is able to do so. In such a case, because noObservableSourcenecessarily invokesonError, theObservermay never know that an error happened.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorResumeNextdoes not operate by default on a particularScheduler.
- Parameters:
fallbackSupplier- a function that returns anObservableSourcethat will take over if the currentObservableencounters an error- Returns:
- the new
Observableinstance - Throws:
NullPointerException- iffallbackSupplierisnull- See Also:
-
onErrorResumeWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> onErrorResumeWith(@NonNull @NonNull ObservableSource<? extends @NonNull T> fallback) Resumes the flow with the givenObservableSourcewhen the currentObservablefails instead of signaling the error viaonError.
By default, when an
ObservableSourceencounters an error that prevents it from emitting the expected item to itsObserver, theObservableSourceinvokes itsObserver'sonErrormethod, and then quits without invoking any more of itsObserver's methods. TheonErrorResumeWithmethod changes this behavior. If you pass anotherObservableSource(next) to anObservableSource'sonErrorResumeWithmethod, if the originalObservableSourceencounters an error, instead of invoking itsObserver'sonErrormethod, it will instead relinquish control tonextwhich will invoke theObserver'sonNextmethod if it is able to do so. In such a case, because noObservableSourcenecessarily invokesonError, theObservermay never know that an error happened.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorResumeWithdoes not operate by default on a particularScheduler.
- Parameters:
fallback- the nextObservableSourcesource that will take over if the currentObservableencounters an error- Returns:
- the new
Observableinstance - Throws:
NullPointerException- iffallbackisnull- See Also:
-
onErrorReturn
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> onErrorReturn(@NonNull @NonNull Function<? super Throwable, ? extends @NonNull T> itemSupplier) Ends the flow with a last item returned by a function for theThrowableerror signaled by the currentObservableinstead of signaling the error viaonError.
By default, when an
ObservableSourceencounters an error that prevents it from emitting the expected item to itsObserver, theObservableSourceinvokes itsObserver'sonErrormethod, and then quits without invoking any more of itsObserver's methods. TheonErrorReturnmethod changes this behavior. If you pass a function (resumeFunction) to anObservableSource'sonErrorReturnmethod, if the originalObservableSourceencounters an error, instead of invoking itsObserver'sonErrormethod, it will instead emit the return value ofresumeFunction.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorReturndoes not operate by default on a particularScheduler.
- Parameters:
itemSupplier- a function that returns a single value that will be emitted along with a regularonCompletein case the currentObservablesignals anonErrorevent- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitemSupplierisnull- See Also:
-
onErrorReturnItem
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> onErrorReturnItem(@NonNull @NonNull T item) Ends the flow with the given last item when the currentObservablefails instead of signaling the error viaonError.
By default, when an
ObservableSourceencounters an error that prevents it from emitting the expected item to itsObserver, theObservableSourceinvokes itsObserver'sonErrormethod, and then quits without invoking any more of itsObserver's methods. TheonErrorReturnmethod changes this behavior. If you pass a function (resumeFunction) to anObservableSource'sonErrorReturnmethod, if the originalObservableSourceencounters an error, instead of invoking itsObserver'sonErrormethod, it will instead emit the return value ofresumeFunction.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorReturnItemdoes not operate by default on a particularScheduler.
- Parameters:
item- the value that is emitted along with a regularonCompletein case the currentObservablesignals an exception- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitemisnull- See Also:
-
onTerminateDetach
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> onTerminateDetach()Nulls out references to the upstream producer and downstreamObserverif the sequence is terminated or downstream callsdispose().
- Scheduler:
onTerminateDetachdoes not operate by default on a particularScheduler.
- Returns:
- the new
Observableinstance the sequence is terminated or downstream callsdispose() - Since:
- 2.0
-
publish
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull ConnectableObservable<T> publish()Returns aConnectableObservable, which is a variety ofObservableSourcethat waits until itsconnectmethod is called before it begins emitting items to thoseObservers that have subscribed to it.
- Scheduler:
publishdoes not operate by default on a particularScheduler.
- Returns:
- the new
ConnectableObservableinstance - See Also:
-
publish
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> publish(@NonNull @NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector) Returns anObservablethat emits the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservablesequence.
- Scheduler:
publishdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the type of items emitted by the resultingObservable- Parameters:
selector- a function that can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence.Observers to the given source will receive all notifications of the source from the time of the subscription forward.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifselectorisnull- See Also:
-
reduce
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> reduce(@NonNull @NonNull BiFunction<@NonNull T, @NonNull T, @NonNull T> reducer) Returns aMaybethat applies a specified accumulator function to the first item emitted by the currentObservable, then feeds the result of that function along with the second item emitted by the currentObservableinto the same function, and so on until all items have been emitted by the current and finiteObservable, and emits the final result from the final call to your function as its sole item.
This technique, which is called "reduce" here, is sometimes called "aggregate," "fold," "accumulate," "compress," or "inject" in other programming contexts. Groovy, for instance, has an
injectmethod that does a similar operation on lists.Note that this operator requires the upstream to signal
onCompletefor the accumulator object to be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
reducedoes not operate by default on a particularScheduler.
- Parameters:
reducer- an accumulator function to be invoked on each item emitted by the currentObservable, whose result will be used in the next accumulator call- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifreducerisnull- See Also:
-
reduce
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Single<R> reduce(@NonNull R seed, @NonNull @NonNull BiFunction<@NonNull R, ? super @NonNull T, @NonNull R> reducer) Returns aSinglethat applies a specified accumulator function to the first item emitted by the currentObservableand a specified seed value, then feeds the result of that function along with the second item emitted by the currentObservableinto the same function, and so on until all items have been emitted by the current and finiteObservable, emitting the final result from the final call to your function as its sole item.
This technique, which is called "reduce" here, is sometimes called "aggregate," "fold," "accumulate," "compress," or "inject" in other programming contexts. Groovy, for instance, has an
injectmethod that does a similar operation on lists.Note that the
seedis shared among all subscribers to the resultingObservableand may cause problems if it is mutable. To make sure each subscriber gets its own value, defer the application of this operator viadefer(Supplier):ObservableSource<T> source = ... Single.defer(() -> source.reduce(new ArrayList<>(), (list, item) -> list.add(item))); // alternatively, by using compose to stay fluent source.compose(o -> Observable.defer(() -> o.reduce(new ArrayList<>(), (list, item) -> list.add(item)).toObservable()) ).firstOrError(); // or, by using reduceWith instead of reduce source.reduceWith(() -> new ArrayList<>(), (list, item) -> list.add(item)));Note that this operator requires the upstream to signal
onCompletefor the accumulator object to be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
reducedoes not operate by default on a particularScheduler.
- Type Parameters:
R- the accumulator and output value type- Parameters:
seed- the initial (seed) accumulator valuereducer- an accumulator function to be invoked on each item emitted by the currentObservable, the result of which will be used in the next accumulator call- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifseedorreducerisnull- See Also:
-
reduceWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Single<R> reduceWith(@NonNull @NonNull Supplier<@NonNull R> seedSupplier, @NonNull @NonNull BiFunction<@NonNull R, ? super @NonNull T, @NonNull R> reducer) Returns aSinglethat applies a specified accumulator function to the first item emitted by the currentObservableand a seed value derived from calling a specifiedseedSupplier, then feeds the result of that function along with the second item emitted by the currentObservableinto the same function, and so on until all items have been emitted by the current and finiteObservable, emitting the final result from the final call to your function as its sole item.
This technique, which is called "reduce" here, is sometimes called "aggregate," "fold," "accumulate," "compress," or "inject" in other programming contexts. Groovy, for instance, has an
injectmethod that does a similar operation on lists.Note that this operator requires the upstream to signal
onCompletefor the accumulator object to be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
reduceWithdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the accumulator and output value type- Parameters:
seedSupplier- theSupplierthat provides the initial (seed) accumulator value for each individualObserverreducer- an accumulator function to be invoked on each item emitted by the currentObservable, the result of which will be used in the next accumulator call- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifseedSupplierorreducerisnull- See Also:
-
repeat
Returns anObservablethat repeats the sequence of items emitted by the currentObservableindefinitely.
- Scheduler:
repeatdoes not operate by default on a particularScheduler.
- Returns:
- the new
Observableinstance - See Also:
-
repeat
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> repeat(long times) Returns anObservablethat repeats the sequence of items emitted by the currentObservableat mostcounttimes.
- Scheduler:
repeatdoes not operate by default on a particularScheduler.
- Parameters:
times- the number of times the currentObservableitems are repeated, a count of 0 will yield an empty sequence- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- iftimesis negative- See Also:
-
repeatUntil
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> repeatUntil(@NonNull @NonNull BooleanSupplier stop) Returns anObservablethat repeats the sequence of items emitted by the currentObservableuntil the provided stop function returnstrue.
- Scheduler:
repeatUntildoes not operate by default on a particularScheduler.
- Parameters:
stop- a boolean supplier that is called when the currentObservablecompletes; if it returnstrue, the returnedObservablecompletes; if it returnsfalse, the currentObservableis resubscribed.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifstopisnull- See Also:
-
repeatWhen
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> repeatWhen(@NonNull @NonNull Function<? super Observable<Object>, ? extends ObservableSource<?>> handler) Returns anObservablethat emits the same values as the currentObservablewith the exception of anonComplete. AnonCompletenotification from the source will result in the emission of avoiditem to theObservableSourceprovided as an argument to thenotificationHandlerfunction. If thatObservableSourcecallsonCompleteoronErrorthenrepeatWhenwill callonCompleteoronErroron the child subscription. Otherwise, the currentObservablewill be resubscribed.
- Scheduler:
repeatWhendoes not operate by default on a particularScheduler.
- Parameters:
handler- receives anObservableSourceof notifications with which a user can complete or error, aborting the repeat.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifhandlerisnull- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull ConnectableObservable<T> replay()Returns aConnectableObservablethat shares a single subscription to the currentObservablethat will replay all of its items and notifications to any futureObserver. A connectableObservableresembles an ordinaryObservable, except that it does not begin emitting items when it is subscribed to, but only when itsconnectmethod is called.
- Scheduler:
- This version of
replaydoes not operate by default on a particularScheduler.
- Returns:
- the new
ConnectableObservableinstance - See Also:
-
replay
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> replay(@NonNull @NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector) Returns anObservablethat emits items that are the results of invoking a specified selector on the items emitted by aConnectableObservablethat shares a single subscription to the currentObservable.
- Scheduler:
- This version of
replaydoes not operate by default on a particularScheduler.
- Type Parameters:
R- the type of items emitted by the resultingObservable- Parameters:
selector- the selector function, which can use the multicasted sequence as many times as needed, without causing multiple subscriptions to the currentObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifselectorisnull- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> replay(@NonNull @NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, int bufferSize) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replayingbufferSizenotifications.Note that due to concurrency requirements,
replay(bufferSize)may hold strong references to more thanbufferSizesource emissions.
- Scheduler:
- This version of
replaydoes not operate by default on a particularScheduler.
- Type Parameters:
R- the type of items emitted by the resultingObservable- Parameters:
selector- the selector function, which can use the multicasted sequence as many times as needed, without causing multiple subscriptions to the currentObservablebufferSize- the buffer size that limits the number of items the connectableObservablecan replay- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifselectorisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> replay(@NonNull @NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, int bufferSize, boolean eagerTruncate) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replayingbufferSizenotifications.Note that due to concurrency requirements,
replay(bufferSize)may hold strong references to more thanbufferSizesource emissions.
- Scheduler:
- This version of
replaydoes not operate by default on a particularScheduler.
- Type Parameters:
R- the type of items emitted by the resultingObservable- Parameters:
selector- the selector function, which can use the multicasted sequence as many times as needed, without causing multiple subscriptions to the currentObservablebufferSize- the buffer size that limits the number of items the connectableObservablecan replayeagerTruncate- iftrue, whenever the internal buffer is truncated to the given bufferSize, the oldest item will be guaranteed dereferenced, thus avoiding unexpected retention- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifselectorisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final <@NonNull R> @NonNull Observable<R> replay(@NonNull @NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, int bufferSize, long time, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replaying no more thanbufferSizeitems that were emitted within a specified time window.Note that due to concurrency requirements,
replay(bufferSize)may hold strong references to more thanbufferSizesource emissions.
- Scheduler:
- This version of
replayoperates by default on thecomputationScheduler.
- Type Parameters:
R- the type of items emitted by the resultingObservable- Parameters:
selector- a selector function, which can use the multicasted sequence as many times as needed, without causing multiple subscriptions to the currentObservablebufferSize- the buffer size that limits the number of items the connectableObservablecan replaytime- the duration of the window in which the replayed items must have been emittedunit- the time unit oftime- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifselectororunitisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final <@NonNull R> @NonNull Observable<R> replay(@NonNull @NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, int bufferSize, long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replaying no more thanbufferSizeitems that were emitted within a specified time window.Note that due to concurrency requirements,
replay(bufferSize)may hold strong references to more thanbufferSizesource emissions.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Type Parameters:
R- the type of items emitted by the resultingObservable- Parameters:
selector- a selector function, which can use the multicasted sequence as many times as needed, without causing multiple subscriptions to the currentObservablebufferSize- the buffer size that limits the number of items the connectableObservablecan replaytime- the duration of the window in which the replayed items must have been emittedunit- the time unit oftimescheduler- theSchedulerthat is the time source for the window- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- ifbufferSizeis non-positiveNullPointerException- ifselector,unitorschedulerisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final <@NonNull R> @NonNull Observable<R> replay(@NonNull @NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, int bufferSize, long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean eagerTruncate) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replaying no more thanbufferSizeitems that were emitted within a specified time window.Note that due to concurrency requirements,
replay(bufferSize)may hold strong references to more thanbufferSizesource emissions.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Type Parameters:
R- the type of items emitted by the resultingObservable- Parameters:
selector- a selector function, which can use the multicasted sequence as many times as needed, without causing multiple subscriptions to the currentObservablebufferSize- the buffer size that limits the number of items the connectableObservablecan replaytime- the duration of the window in which the replayed items must have been emittedunit- the time unit oftimescheduler- theSchedulerthat is the time source for the windoweagerTruncate- iftrue, whenever the internal buffer is truncated to the given bufferSize/age, the oldest item will be guaranteed dereferenced, thus avoiding unexpected retention- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifselector,unitorschedulerisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final <@NonNull R> @NonNull Observable<R> replay(@NonNull @NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, long time, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replaying all items that were emitted within a specified time window.
- Scheduler:
- This version of
replayoperates by default on thecomputationScheduler.
- Type Parameters:
R- the type of items emitted by the resultingObservable- Parameters:
selector- a selector function, which can use the multicasted sequence as many times as needed, without causing multiple subscriptions to the currentObservabletime- the duration of the window in which the replayed items must have been emittedunit- the time unit oftime- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifselectororunitisnull- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final <@NonNull R> @NonNull Observable<R> replay(@NonNull @NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replaying all items that were emitted within a specified time window.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Type Parameters:
R- the type of items emitted by the resultingObservable- Parameters:
selector- a selector function, which can use the multicasted sequence as many times as needed, without causing multiple subscriptions to the currentObservabletime- the duration of the window in which the replayed items must have been emittedunit- the time unit oftimescheduler- the scheduler that is the time source for the window- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifselector,unitorschedulerisnull- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final <@NonNull R> @NonNull Observable<R> replay(@NonNull @NonNull Function<? super Observable<@NonNull T>, ? extends ObservableSource<@NonNull R>> selector, long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean eagerTruncate) Returns anObservablethat emits items that are the results of invoking a specified selector on items emitted by aConnectableObservablethat shares a single subscription to the currentObservable, replaying all items that were emitted within a specified time window.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Type Parameters:
R- the type of items emitted by the resultingObservable- Parameters:
selector- a selector function, which can use the multicasted sequence as many times as needed, without causing multiple subscriptions to the currentObservabletime- the duration of the window in which the replayed items must have been emittedunit- the time unit oftimescheduler- the scheduler that is the time source for the windoweagerTruncate- iftrue, whenever the internal buffer is truncated to the given age, the oldest item will be guaranteed dereferenced, thus avoiding unexpected retention- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifselector,unitorschedulerisnull- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull ConnectableObservable<T> replay(int bufferSize) Returns aConnectableObservablethat shares a single subscription to the currentObservablethat replays at mostbufferSizeitems emitted by the currentObservable. A connectableObservableresembles an ordinaryObservable, except that it does not begin emitting items when it is subscribed to, but only when itsconnectmethod is called.
Note that due to concurrency requirements,
replay(bufferSize)may hold strong references to more thanbufferSizesource emissions. To ensure no beyond-bufferSize items are referenced, use thereplay(int, boolean)overload witheagerTruncate = true.- Scheduler:
- This version of
replaydoes not operate by default on a particularScheduler.
- Parameters:
bufferSize- the buffer size that limits the number of items that can be replayed- Returns:
- the new
ConnectableObservableinstance - Throws:
IllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull ConnectableObservable<T> replay(int bufferSize, boolean eagerTruncate) Returns aConnectableObservablethat shares a single subscription to the currentObservablethat replays at mostbufferSizeitems emitted by the currentObservable. A connectableObservableresembles an ordinaryObservable, except that it does not begin emitting items when it is subscribed to, but only when itsconnectmethod is called.
Note that due to concurrency requirements,
replay(bufferSize)may hold strong references to more thanbufferSizesource emissions. To ensure no beyond-bufferSize items are referenced, seteagerTruncate = true.- Scheduler:
- This version of
replaydoes not operate by default on a particularScheduler.
- Parameters:
bufferSize- the buffer size that limits the number of items that can be replayedeagerTruncate- iftrue, whenever the internal buffer is truncated to the given bufferSize/age, the oldest item will be guaranteed dereferenced, thus avoiding unexpected retention- Returns:
- the new
ConnectableObservableinstance - Throws:
IllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull ConnectableObservable<T> replay(int bufferSize, long time, @NonNull @NonNull TimeUnit unit) Returns aConnectableObservablethat shares a single subscription to the currentObservableand replays at mostbufferSizeitems that were emitted during a specified time window. A connectableObservableresembles an ordinaryObservable, except that it does not begin emitting items when it is subscribed to, but only when itsconnectmethod is called.
Note that due to concurrency requirements,
replay(bufferSize)may hold strong references to more thanbufferSizesource emissions. To ensure no out-of-date or beyond-bufferSize items are referenced, use thereplay(int, long, TimeUnit, Scheduler, boolean)overload witheagerTruncate = true.- Scheduler:
- This version of
replayoperates by default on thecomputationScheduler.
- Parameters:
bufferSize- the buffer size that limits the number of items that can be replayedtime- the duration of the window in which the replayed items must have been emittedunit- the time unit oftime- Returns:
- the new
ConnectableObservableinstance - Throws:
NullPointerException- ifunitisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull ConnectableObservable<T> replay(int bufferSize, long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns aConnectableObservablethat shares a single subscription to the currentObservableand that replays a maximum ofbufferSizeitems that are emitted within a specified time window. A connectableObservableresembles an ordinaryObservable, except that it does not begin emitting items when it is subscribed to, but only when itsconnectmethod is called.Note that due to concurrency requirements,
replay(bufferSize)may hold strong references to more thanbufferSizesource emissions. To ensure no out-of-date or beyond-bufferSize items are referenced, use thereplay(int, long, TimeUnit, Scheduler, boolean)overload witheagerTruncate = true.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
bufferSize- the buffer size that limits the number of items that can be replayedtime- the duration of the window in which the replayed items must have been emittedunit- the time unit oftimescheduler- the scheduler that is used as a time source for the window- Returns:
- the new
ConnectableObservableinstance - Throws:
NullPointerException- ifunitorschedulerisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull ConnectableObservable<T> replay(int bufferSize, long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean eagerTruncate) Returns aConnectableObservablethat shares a single subscription to the currentObservableand that replays a maximum ofbufferSizeitems that are emitted within a specified time window. A connectableObservableresembles an ordinaryObservable, except that it does not begin emitting items when it is subscribed to, but only when itsconnectmethod is called.
Note that due to concurrency requirements,
replay(bufferSize)may hold strong references to more thanbufferSizesource emissions. To ensure no out-of-date or beyond-bufferSize items are referenced, seteagerTruncate = true.- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
bufferSize- the buffer size that limits the number of items that can be replayedtime- the duration of the window in which the replayed items must have been emittedunit- the time unit oftimescheduler- the scheduler that is used as a time source for the windoweagerTruncate- iftrue, whenever the internal buffer is truncated to the given bufferSize/age, the oldest item will be guaranteed dereferenced, thus avoiding unexpected retention- Returns:
- the new
ConnectableObservableinstance - Throws:
NullPointerException- ifunitorschedulerisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull ConnectableObservable<T> replay(long time, @NonNull @NonNull TimeUnit unit) Returns aConnectableObservablethat shares a single subscription to the currentObservableand replays all items emitted by the currentObservablewithin a specified time window. A connectableObservableresembles an ordinaryObservable, except that it does not begin emitting items when it is subscribed to, but only when itsconnectmethod is called.
- Scheduler:
- This version of
replayoperates by default on thecomputationScheduler.
- Parameters:
time- the duration of the window in which the replayed items must have been emittedunit- the time unit oftime- Returns:
- the new
ConnectableObservableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull ConnectableObservable<T> replay(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns aConnectableObservablethat shares a single subscription to the currentObservableand replays all items emitted by the currentObservablewithin a specified time window. A connectableObservableresembles an ordinaryObservable, except that it does not begin emitting items when it is subscribed to, but only when itsconnectmethod is called.
Note that the internal buffer may retain strong references to the oldest item. To ensure no out-of-date items are referenced, use the
replay(long, TimeUnit, Scheduler, boolean)overload witheagerTruncate = true.- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
time- the duration of the window in which the replayed items must have been emittedunit- the time unit oftimescheduler- theSchedulerthat is the time source for the window- Returns:
- the new
ConnectableObservableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
replay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull ConnectableObservable<T> replay(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean eagerTruncate) Returns aConnectableObservablethat shares a single subscription to the currentObservableand replays all items emitted by the currentObservablewithin a specified time window. A connectableObservableresembles an ordinaryObservable, except that it does not begin emitting items when it is subscribed to, but only when itsconnectmethod is called.
Note that the internal buffer may retain strong references to the oldest item. To ensure no out-of-date items are referenced, set
eagerTruncate = true.- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
time- the duration of the window in which the replayed items must have been emittedunit- the time unit oftimescheduler- theSchedulerthat is the time source for the windoweagerTruncate- iftrue, whenever the internal buffer is truncated to the given bufferSize/age, the oldest item will be guaranteed dereferenced, thus avoiding unexpected retention- Returns:
- the new
ConnectableObservableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
retry
Returns anObservablethat mirrors the currentObservable, resubscribing to it if it callsonError(infinite retry count).
If the current
ObservablecallsObserver.onError(Throwable), this method will resubscribe to the currentObservablerather than propagating theonErrorcall.Any and all items emitted by the current
Observablewill be emitted by the resultingObservable, even those emitted during failed subscriptions. For example, if the currentObservablefails at first but emits[1, 2]then succeeds the second time and emits[1, 2, 3, 4, 5]then the complete sequence of emissions and notifications would be[1, 2, 1, 2, 3, 4, 5, onComplete].- Scheduler:
retrydoes not operate by default on a particularScheduler.
- Returns:
- the new
Observableinstance - See Also:
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> retry(@NonNull @NonNull BiPredicate<? super Integer, ? super Throwable> predicate) Returns anObservablethat mirrors the currentObservable, resubscribing to it if it callsonErrorand the predicate returnstruefor that specific exception and retry count.
- Scheduler:
retrydoes not operate by default on a particularScheduler.
- Parameters:
predicate- the predicate that determines if a resubscription may happen in case of a specific exception and retry count- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifpredicateisnull- See Also:
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> retry(long times) Returns anObservablethat mirrors the currentObservable, resubscribing to it if it callsonErrorup to a specified number of retries.
If the current
ObservablecallsObserver.onError(Throwable), this method will resubscribe to the currentObservablefor a maximum ofcountresubscriptions rather than propagating theonErrorcall.Any and all items emitted by the current
Observablewill be emitted by the resultingObservable, even those emitted during failed subscriptions. For example, if the currentObservablefails at first but emits[1, 2]then succeeds the second time and emits[1, 2, 3, 4, 5]then the complete sequence of emissions and notifications would be[1, 2, 1, 2, 3, 4, 5, onComplete].- Scheduler:
retrydoes not operate by default on a particularScheduler.
- Parameters:
times- the number of times to resubscribe if the currentObservablefails- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- iftimesis negative- See Also:
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> retry(long times, @NonNull @NonNull Predicate<? super Throwable> predicate) Retries at most times or until the predicate returnsfalse, whichever happens first.
- Scheduler:
retrydoes not operate by default on a particularScheduler.
- Parameters:
times- the number of times to resubscribe if the currentObservablefailspredicate- the predicate called with the failureThrowableand should returntrueto trigger a retry.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifpredicateisnullIllegalArgumentException- iftimesis negative
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> retry(@NonNull @NonNull Predicate<? super Throwable> predicate) Retries the currentObservableif the predicate returnstrue.
- Scheduler:
retrydoes not operate by default on a particularScheduler.
- Parameters:
predicate- the predicate that receives the failureThrowableand should returntrueto trigger a retry.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifpredicateisnull
-
retryUntil
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> retryUntil(@NonNull @NonNull BooleanSupplier stop) Retries until the given stop function returnstrue.
- Scheduler:
retryUntildoes not operate by default on a particularScheduler.
- Parameters:
stop- the function that should returntrueto stop retrying- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifstopisnull
-
retryWhen
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> retryWhen(@NonNull @NonNull Function<? super Observable<Throwable>, ? extends ObservableSource<?>> handler) Returns anObservablethat emits the same values as the currentObservablewith the exception of anonError. AnonErrornotification from the source will result in the emission of aThrowableitem to theObservableprovided as an argument to thenotificationHandlerfunction. If thatObservablecallsonCompleteoronErrorthenretrywill callonCompleteoronErroron the child subscription. Otherwise, the currentObservablewill be resubscribed.
Example: This retries 3 times, each time incrementing the number of seconds it waits.
Output is:Observable.create((ObservableEmitter<? super String> s) -> { System.out.println("subscribing"); s.onError(new RuntimeException("always fails")); }).retryWhen(attempts -> { return attempts.zipWith(Observable.range(1, 3), (n, i) -> i).flatMap(i -> { System.out.println("delay retry by " + i + " second(s)"); return Observable.timer(i, TimeUnit.SECONDS); }); }).blockingForEach(System.out::println);subscribing delay retry by 1 second(s) subscribing delay retry by 2 second(s) subscribing delay retry by 3 second(s) subscribingNote that the inner
ObservableSourcereturned by the handler function should signal eitheronNext,onErrororonCompletein response to the receivedThrowableto indicate the operator should retry or terminate. If the upstream to the operator is asynchronous, signalingonNextfollowed byonCompleteimmediately may result in the sequence to be completed immediately. Similarly, if this innerObservableSourcesignalsonErrororonCompletewhile the upstream is active, the sequence is terminated with the same signal immediately.The following example demonstrates how to retry an asynchronous source with a delay:
Observable.timer(1, TimeUnit.SECONDS) .doOnSubscribe(s -> System.out.println("subscribing")) .map(v -> { throw new RuntimeException(); }) .retryWhen(errors -> { AtomicInteger counter = new AtomicInteger(); return errors .takeWhile(e -> counter.getAndIncrement() != 3) .flatMap(e -> { System.out.println("delay retry by " + counter.get() + " second(s)"); return Observable.timer(counter.get(), TimeUnit.SECONDS); }); }) .blockingSubscribe(System.out::println, System.out::println);- Scheduler:
retryWhendoes not operate by default on a particularScheduler.
- Parameters:
handler- receives anObservableof notifications with which a user can complete or error, aborting the retry- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifhandlerisnull- See Also:
-
safeSubscribe
@SchedulerSupport("none") public final void safeSubscribe(@NonNull @NonNull Observer<? super @NonNull T> observer) Subscribes to the currentObservableand wraps the givenObserverinto aSafeObserver(if not already aSafeObserver) that deals with exceptions thrown by a misbehavingObserver(that doesn't follow the Reactive Streams specification).- Scheduler:
safeSubscribedoes not operate by default on a particularScheduler.
- Parameters:
observer- the incomingObserverinstance- Throws:
NullPointerException- ifobserverisnull
-
sample
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> sample(long period, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits the most recently emitted item (if any) emitted by the currentObservablewithin periodic time intervals.
- Scheduler:
sampleoperates by default on thecomputationScheduler.
- Parameters:
period- the sampling rateunit- theTimeUnitin whichperiodis defined- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
sample
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> sample(long period, @NonNull @NonNull TimeUnit unit, boolean emitLast) Returns anObservablethat emits the most recently emitted item (if any) emitted by the currentObservablewithin periodic time intervals and optionally emit the very last upstream item when the upstream completes.
- Scheduler:
sampleoperates by default on thecomputationScheduler.
History: 2.0.5 - experimental
- Parameters:
period- the sampling rateunit- theTimeUnitin whichperiodis definedemitLast- iftrueand the upstream completes while there is still an unsampled item available, that item is emitted to downstream before completion iffalse, an unsampled last item is ignored.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 2.1
- See Also:
-
sample
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> sample(long period, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits the most recently emitted item (if any) emitted by the currentObservablewithin periodic time intervals, where the intervals are defined on a particularScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
period- the sampling rateunit- theTimeUnitin whichperiodis definedscheduler- theSchedulerto use when sampling- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
sample
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> sample(long period, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean emitLast) Returns anObservablethat emits the most recently emitted item (if any) emitted by the currentObservablewithin periodic time intervals, where the intervals are defined on a particularSchedulerand optionally emit the very last upstream item when the upstream completes.
- Scheduler:
- You specify which
Schedulerthis operator will use.
History: 2.0.5 - experimental
- Parameters:
period- the sampling rateunit- theTimeUnitin whichperiodis definedscheduler- theSchedulerto use when samplingemitLast- iftrueand the upstream completes while there is still an unsampled item available, that item is emitted to downstream before completion iffalse, an unsampled last item is ignored.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- Since:
- 2.1
- See Also:
-
sample
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> sample(long period, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean emitLast, @NonNull @NonNull Consumer<? super @NonNull T> onDropped) Returns anObservablethat emits the most recently emitted item (if any) emitted by the currentObservablewithin periodic time intervals, where the intervals are defined on a particularScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
period- the sampling rateunit- theTimeUnitin whichperiodis definedscheduler- theSchedulerto use when samplingemitLast- iftrueand the upstream completes while there is still an unsampled item available, that item is emitted to downstream before completion iffalse, an unsampled last item is ignored.onDropped- called with the current entry when it has been replaced by a new one- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnulloronDroppedisnull- Since:
- 3.1.6 - Experimental
- See Also:
-
sample
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U> @NonNull Observable<T> sample(@NonNull @NonNull ObservableSource<@NonNull U> sampler) Returns anObservablethat, when the specifiedsamplerObservableSourceemits an item or completes, emits the most recently emitted item (if any) emitted by the currentObservablesince the previous emission from thesamplerObservableSource.
- Scheduler:
- This version of
sampledoes not operate by default on a particularScheduler.
- Type Parameters:
U- the element type of the samplerObservableSource- Parameters:
sampler- theObservableSourceto use for sampling the currentObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsamplerisnull- See Also:
-
sample
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U> @NonNull Observable<T> sample(@NonNull @NonNull ObservableSource<@NonNull U> sampler, boolean emitLast) Returns anObservablethat, when the specifiedsamplerObservableSourceemits an item or completes, emits the most recently emitted item (if any) emitted by the currentObservablesince the previous emission from thesamplerObservableSourceand optionally emit the very last upstream item when the upstream or otherObservableSourcecomplete.
- Scheduler:
- This version of
sampledoes not operate by default on a particularScheduler.
History: 2.0.5 - experimental
- Type Parameters:
U- the element type of the samplerObservableSource- Parameters:
sampler- theObservableSourceto use for sampling the currentObservableemitLast- iftrueand the upstream completes while there is still an unsampled item available, that item is emitted to downstream before completion iffalse, an unsampled last item is ignored.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsamplerisnull- Since:
- 2.1
- See Also:
-
scan
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> scan(@NonNull @NonNull BiFunction<@NonNull T, @NonNull T, @NonNull T> accumulator) Returns anObservablethat emits the first value emitted by the currentObservable, then emits one value for each subsequent value emitted by the currentObservable. Each emission after the first is the result of applying the specified accumulator function to the previous emission and the corresponding value from the currentObservable.
This sort of function is sometimes called an accumulator.
- Scheduler:
scandoes not operate by default on a particularScheduler.
- Parameters:
accumulator- an accumulator function to be invoked on each item emitted by the currentObservable, whose result will be emitted toObservers viaonNextand used in the next accumulator call- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifaccumulatorisnull- See Also:
-
scan
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> scan(@NonNull @NonNull R initialValue, @NonNull @NonNull BiFunction<@NonNull R, ? super @NonNull T, @NonNull R> accumulator) Returns anObservablethat emits the provided initial (seed) value, then emits one value for each value emitted by the currentObservable. Each emission after the first is the result of applying the specified accumulator function to the previous emission and the corresponding value from the currentObservable.
This sort of function is sometimes called an accumulator.
Note that the
Observablethat results from this method will emitinitialValueas its first emitted item.Note that the
initialValueis shared among all subscribers to the resultingObservableand may cause problems if it is mutable. To make sure each subscriber gets its own value, defer the application of this operator viadefer(Supplier):ObservableSource<T> source = ... Observable.defer(() -> source.scan(new ArrayList<>(), (list, item) -> list.add(item))); // alternatively, by using compose to stay fluent source.compose(o -> Observable.defer(() -> o.scan(new ArrayList<>(), (list, item) -> list.add(item))) );- Scheduler:
scandoes not operate by default on a particularScheduler.
- Type Parameters:
R- the initial, accumulator and result type- Parameters:
initialValue- the initial (seed) accumulator itemaccumulator- an accumulator function to be invoked on each item emitted by the currentObservable, whose result will be emitted toObservers viaonNextand used in the next accumulator call- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifinitialValueoraccumulatorisnull- See Also:
-
scanWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> scanWith(@NonNull @NonNull Supplier<@NonNull R> seedSupplier, @NonNull @NonNull BiFunction<@NonNull R, ? super @NonNull T, @NonNull R> accumulator) Returns anObservablethat emits the provided initial (seed) value, then emits one value for each value emitted by the currentObservable. Each emission after the first is the result of applying the specified accumulator function to the previous emission and the corresponding value from the currentObservable.
This sort of function is sometimes called an accumulator.
Note that the
Observablethat results from this method will emit the value returned by theseedSupplieras its first item.- Scheduler:
scanWithdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the initial, accumulator and result type- Parameters:
seedSupplier- aSupplierthat returns the initial (seed) accumulator item for each individualObserveraccumulator- an accumulator function to be invoked on each item emitted by the currentObservable, whose result will be emitted toObservers viaonNextand used in the next accumulator call- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifseedSupplieroraccumulatorisnull- See Also:
-
serialize
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> serialize()Forces the currentObservable's emissions and notifications to be serialized and for it to obey theObservableSourcecontract in other ways.It is possible for an
Observableto invoke itsObservers' methods asynchronously, perhaps from different threads. This could make such anObservablepoorly-behaved, in that it might try to invokeonCompleteoronErrorbefore one of itsonNextinvocations, or it might callonNextfrom two different threads concurrently. You can force such anObservableto be well-behaved and sequential by applying theserializemethod to it.
- Scheduler:
serializedoes not operate by default on a particularScheduler.
- Returns:
- the new
Observableinstance - See Also:
-
singleElement
Returns aMaybethat completes if the currentObservableis empty or emits the single item emitted by the currentObservable, or signals anIllegalArgumentExceptionif the currentObservableemits more than one item.
- Scheduler:
singleElementdoes not operate by default on a particularScheduler.
- Returns:
- the new
Maybeinstance - See Also:
-
single
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> single(@NonNull @NonNull T defaultItem) Returns aSinglethat emits the single item emitted by the currentObservable, if the currentObservableemits only a single item, or a default item if the currentObservableemits no items. If the currentObservableemits more than one item, anIllegalArgumentExceptionis signaled instead.
- Scheduler:
singledoes not operate by default on a particularScheduler.
- Parameters:
defaultItem- a default value to emit if the currentObservableemits no item- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifdefaultItemisnull- See Also:
-
singleOrError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> singleOrError()Returns aSinglethat emits the single item emitted by the currentObservableif it emits only a single item, otherwise if the currentObservablecompletes without emitting any items or emits more than one item aNoSuchElementExceptionorIllegalArgumentExceptionwill be signaled respectively.
- Scheduler:
singleOrErrordoes not operate by default on a particularScheduler.
- Returns:
- the new
Singleinstance - See Also:
-
skip
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> skip(long count) Returns anObservablethat skips the firstcountitems emitted by the currentObservableand emits the remainder.
- Scheduler:
- This version of
skipdoes not operate by default on a particularScheduler.
- Parameters:
count- the number of items to skip- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- ifcountis negative- See Also:
-
skip
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> skip(long time, @NonNull @NonNull TimeUnit unit) Returns anObservablethat skips values emitted by the currentObservablebefore a specified time window elapses.
- Scheduler:
skipdoes not operate on any particular scheduler but uses the current time from thecomputationScheduler.
- Parameters:
time- the length of the time window to skipunit- the time unit oftime- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
skip
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> skip(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat skips values emitted by the currentObservablebefore a specified time window on a specifiedSchedulerelapses.
- Scheduler:
- You specify which
Schedulerthis operator will use for the timed skipping
- Parameters:
time- the length of the time window to skipunit- the time unit oftimescheduler- theScheduleron which the timed wait happens- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
skipLast
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> skipLast(int count) Returns anObservablethat drops a specified number of items from the end of the sequence emitted by the currentObservable.
This
Observeraccumulates a queue long enough to store the firstcountitems. As more items are received, items are taken from the front of the queue and emitted by the returnedObservable. This causes such items to be delayed.- Scheduler:
- This version of
skipLastdoes not operate by default on a particularScheduler.
- Parameters:
count- number of items to drop from the end of the source sequence- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- ifcountis negative- See Also:
-
skipLast
@CheckReturnValue @SchedulerSupport("io.reactivex:trampoline") @NonNull public final @NonNull Observable<T> skipLast(long time, @NonNull @NonNull TimeUnit unit) Returns anObservablethat drops items emitted by the currentObservableduring a specified time window before the source completes.
Note: this action will cache the latest items arriving in the specified time window.
- Scheduler:
skipLastdoes not operate on any particular scheduler but uses the current time from thetrampolineScheduler.
- Parameters:
time- the length of the time windowunit- the time unit oftime- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
skipLast
@CheckReturnValue @SchedulerSupport("io.reactivex:trampoline") @NonNull public final @NonNull Observable<T> skipLast(long time, @NonNull @NonNull TimeUnit unit, boolean delayError) Returns anObservablethat drops items emitted by the currentObservableduring a specified time window before the source completes.
Note: this action will cache the latest items arriving in the specified time window.
- Scheduler:
skipLastdoes not operate on any particular scheduler but uses the current time from thecomputationScheduler.
- Parameters:
time- the length of the time windowunit- the time unit oftimedelayError- iftrue, an exception signaled by the currentObservableis delayed until the regular elements are consumed by the downstream; iffalse, an exception is immediately signaled and all regular elements dropped- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
skipLast
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> skipLast(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat drops items emitted by the currentObservableduring a specified time window (defined on a specified scheduler) before the source completes.
Note: this action will cache the latest items arriving in the specified time window.
- Scheduler:
- You specify which
Schedulerthis operator will use for tracking the current time
- Parameters:
time- the length of the time windowunit- the time unit oftimescheduler- the scheduler used as the time source- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
skipLast
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> skipLast(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean delayError) Returns anObservablethat drops items emitted by the currentObservableduring a specified time window (defined on a specified scheduler) before the source completes.
Note: this action will cache the latest items arriving in the specified time window.
- Scheduler:
- You specify which
Schedulerthis operator will use to track the current time
- Parameters:
time- the length of the time windowunit- the time unit oftimescheduler- the scheduler used as the time sourcedelayError- iftrue, an exception signaled by the currentObservableis delayed until the regular elements are consumed by the downstream; iffalse, an exception is immediately signaled and all regular elements dropped- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
skipLast
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> skipLast(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean delayError, int bufferSize) Returns anObservablethat drops items emitted by the currentObservableduring a specified time window (defined on a specified scheduler) before the source completes.
Note: this action will cache the latest items arriving in the specified time window.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
time- the length of the time windowunit- the time unit oftimescheduler- the scheduler used as the time sourcedelayError- iftrue, an exception signaled by the currentObservableis delayed until the regular elements are consumed by the downstream; iffalse, an exception is immediately signaled and all regular elements droppedbufferSize- the hint about how many elements to expect to be skipped- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
skipUntil
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U> @NonNull Observable<T> skipUntil(@NonNull @NonNull ObservableSource<@NonNull U> other) Returns anObservablethat skips items emitted by the currentObservableuntil a secondObservableSourceemits an item.
- Scheduler:
skipUntildoes not operate by default on a particularScheduler.
- Type Parameters:
U- the element type of the otherObservableSource- Parameters:
other- the secondObservableSourcethat has to emit an item before the currentObservable's elements begin to be mirrored by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- See Also:
-
skipWhile
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> skipWhile(@NonNull @NonNull Predicate<? super @NonNull T> predicate) Returns anObservablethat skips all items emitted by the currentObservableas long as a specified condition holdstrue, but emits all further source items as soon as the condition becomesfalse.
- Scheduler:
skipWhiledoes not operate by default on a particularScheduler.
- Parameters:
predicate- a function to test each item emitted from the currentObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifpredicateisnull- See Also:
-
sorted
Returns anObservablethat emits the events emitted by the currentObservable, in a sorted order. Each item emitted by the currentObservablemust implementComparablewith respect to all other items in the sequence.
If any item emitted by the current
Observabledoes not implementComparablewith respect to all other items emitted by the currentObservable, no items will be emitted and the sequence is terminated with aClassCastException.Note that calling
sortedwith long, non-terminating or infinite sources might causeOutOfMemoryError- Scheduler:
sorteddoes not operate by default on a particularScheduler.
- Returns:
- the new
Observableinstance
-
sorted
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> sorted(@NonNull @NonNull Comparator<? super @NonNull T> comparator) Returns anObservablethat emits the events emitted by the currentObservable, in a sorted order based on a specified comparison function.Note that calling
sortedwith long, non-terminating or infinite sources might causeOutOfMemoryError- Scheduler:
sorteddoes not operate by default on a particularScheduler.
- Parameters:
comparator- a function that compares two items emitted by the currentObservableand returns anintthat indicates their sort order- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifcomparatorisnull
-
startWithIterable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> startWithIterable(@NonNull @NonNull Iterable<? extends @NonNull T> items) Returns anObservablethat emits the items in a specifiedIterablebefore it begins to emit items emitted by the currentObservable.
- Scheduler:
startWithIterabledoes not operate by default on a particularScheduler.
- Parameters:
items- anIterablethat contains the items you want the resultingObservableto emit first- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitemsisnull- Since:
- 3.0.0
- See Also:
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Observable<T> startWith(@NonNull @NonNull CompletableSource other) Returns anObservablewhich first runs the otherCompletableSourcethen the currentObservableif the other completed normally.
- Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherCompletableSourceto run first- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Observable<T> startWith(@NonNull @NonNull SingleSource<@NonNull T> other) Returns anObservablewhich first runs the otherSingleSourcethen the currentObservableif the other succeeded normally.
- Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherSingleSourceto run first- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Observable<T> startWith(@NonNull @NonNull MaybeSource<@NonNull T> other) Returns anObservablewhich first runs the otherMaybeSourcethen the currentObservableif the other succeeded or completed normally.
- Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherMaybeSourceto run first- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 3.0.0
-
startWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> startWith(@NonNull @NonNull ObservableSource<? extends @NonNull T> other) Returns anObservablethat emits the items in a specifiedObservableSourcebefore it begins to emit items emitted by the currentObservable.
- Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- anObservableSourcethat contains the items you want the modifiedObservableSourceto emit first- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- See Also:
-
startWithItem
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> startWithItem(@NonNull @NonNull T item) Returns anObservablethat emits a specified item before it begins to emit items emitted by the currentObservable.
- Scheduler:
startWithItemdoes not operate by default on a particularScheduler.
- Parameters:
item- the item to emit first- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitemisnull- Since:
- 3.0.0
- See Also:
-
startWithArray
@CheckReturnValue @SchedulerSupport("none") @SafeVarargs @NonNull public final @NonNull Observable<T> startWithArray(@NonNull @NonNull T... items) Returns anObservablethat emits the specified items before it begins to emit items emitted by the currentObservable.
- Scheduler:
startWithArraydoes not operate by default on a particularScheduler.
- Parameters:
items- the array of values to emit first- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitemsisnull- See Also:
-
subscribe
Subscribes to the currentObservableand ignoresonNextandonCompleteemissions.If the
Observableemits an error, it is wrapped into anOnErrorNotImplementedExceptionand routed to theRxJavaPlugins.onError(Throwable)handler.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Returns:
- the new
Disposableinstance that can be used to dispose the subscription at any time - See Also:
-
subscribe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onNext) Subscribes to the currentObservableand provides a callback to handle the items it emits.If the
Observableemits an error, it is wrapped into anOnErrorNotImplementedExceptionand routed to theRxJavaPlugins.onError(Throwable)handler.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
onNext- theConsumer<T>you have designed to accept emissions from the currentObservable- Returns:
- the new
Disposableinstance that can be used to dispose the subscription at any time - Throws:
NullPointerException- ifonNextisnull- See Also:
-
subscribe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onNext, @NonNull @NonNull Consumer<? super Throwable> onError) Subscribes to the currentObservableand provides callbacks to handle the items it emits and any error notification it signals.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
onNext- theConsumer<T>you have designed to accept emissions from the currentObservableonError- theConsumer<Throwable>you have designed to accept any error notification from the currentObservable- Returns:
- the new
Disposableinstance that can be used to dispose the subscription at any time - Throws:
NullPointerException- ifonNextoronErrorisnull- See Also:
-
subscribe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onNext, @NonNull @NonNull Consumer<? super Throwable> onError, @NonNull @NonNull Action onComplete) Subscribes to the currentObservableand provides callbacks to handle the items it emits and any error or completion notification it signals.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
onNext- theConsumer<T>you have designed to accept emissions from the currentObservableonError- theConsumer<Throwable>you have designed to accept any error notification from the currentObservableonComplete- theActionyou have designed to accept a completion notification from the currentObservable- Returns:
- the new
Disposableinstance that can be used to dispose the subscription at any time - Throws:
NullPointerException- ifonNext,onErrororonCompleteisnull- See Also:
-
subscribe
@SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onNext, @NonNull @NonNull Consumer<? super Throwable> onError, @NonNull @NonNull Action onComplete, @NonNull @NonNull DisposableContainer container) Wraps the given onXXX callbacks into aDisposableObserver, adds it to the givenDisposableContainerand ensures, that if the upstream terminates or this particularDisposableis disposed, theObserveris removed from the given container.The
Observerwill be removed after the callback for the terminal event has been invoked.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
onNext- the callback for upstream itemsonError- the callback for an upstream error if anyonComplete- the callback for the upstream completion if anycontainer- theDisposableContainer(such asCompositeDisposable) to add and remove the createdDisposableObserver- Returns:
- the
Disposablethat allows disposing the particular subscription. - Throws:
NullPointerException- ifonNext,onError,onCompleteorcontainerisnull- Since:
- 3.1.0
-
subscribe
@SchedulerSupport("none") public final void subscribe(@NonNull @NonNull Observer<? super @NonNull T> observer) Description copied from interface:ObservableSourceSubscribes the givenObserverto thisObservableSourceinstance.- Specified by:
subscribein interfaceObservableSource<T>- Parameters:
observer- theObserver, notnull
-
subscribeActual
Operator implementations (both source and intermediate) should implement this method that performs the necessary business logic and handles the incomingObservers.There is no need to call any of the plugin hooks on the current
Observableinstance or theObserver; all hooks and basic safeguards have been applied bysubscribe(Observer)before this method gets called.- Parameters:
observer- the incomingObserver, nevernull
-
subscribeWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull E extends Observer<? super @NonNull T>> E subscribeWith(@NonNull E observer) Subscribes a givenObserver(subclass) to the currentObservableand returns the givenObserverinstance as is.Usage example:
Observable<Integer> source = Observable.range(1, 10); CompositeDisposable composite = new CompositeDisposable(); DisposableObserver<Integer> ds = new DisposableObserver<>() { // ... }; composite.add(source.subscribeWith(ds));- Scheduler:
subscribeWithdoes not operate by default on a particularScheduler.
- Type Parameters:
E- the type of theObserverto use and return- Parameters:
observer- theObserver(subclass) to use and return, notnull- Returns:
- the input
observer - Throws:
NullPointerException- ifobserverisnull- Since:
- 2.0
-
subscribeOn
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> subscribeOn(@NonNull @NonNull Scheduler scheduler) Asynchronously subscribesObservers to the currentObservableon the specifiedScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
scheduler- theSchedulerto perform subscription actions on- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifschedulerisnull- See Also:
-
switchIfEmpty
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> switchIfEmpty(@NonNull @NonNull ObservableSource<? extends @NonNull T> other) Returns anObservablethat emits the items emitted by the currentObservableor the items of an alternateObservableSourceif the currentObservableis empty.
- Scheduler:
switchIfEmptydoes not operate by default on a particularScheduler.
- Parameters:
other- the alternateObservableSourceto subscribe to if the source does not emit any items- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 1.1.0
-
switchMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> switchMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper) Returns a newObservableby applying a function that you supply to each item emitted by the currentObservablethat returns anObservableSource, and then emitting the items emitted by the most recently emitted of theseObservableSources.The resulting
Observablecompletes if both the currentObservableand the last innerObservableSource, if any, complete. If the currentObservablesignals anonError, the innerObservableSourceis disposed and the error delivered in-sequence.
- Scheduler:
switchMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the element type of the innerObservableSources and the output- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns anObservableSource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
switchMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> switchMap(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, int bufferSize) Returns a newObservableby applying a function that you supply to each item emitted by the currentObservablethat returns anObservableSource, and then emitting the items emitted by the most recently emitted of theseObservableSources.The resulting
Observablecompletes if both the currentObservableand the last innerObservableSource, if any, complete. If the currentObservablesignals anonError, the innerObservableSourceis disposed and the error delivered in-sequence.
- Scheduler:
switchMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the element type of the innerObservableSources and the output- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns anObservableSourcebufferSize- the number of elements expected from the current active innerObservableSourceto be buffered- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
switchMapCompletable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable switchMapCompletable(@NonNull @NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Maps the items of the currentObservableintoCompletableSources, subscribes to the newer one while disposing the subscription to the previousCompletableSource, thus keeping at most one activeCompletableSourcerunning.
Since a
CompletableSourcedoesn't produce any items, the resulting reactive type of this operator is aCompletablethat can only indicate successful completion or a failure in any of the innerCompletableSources or the failure of the currentObservable.- Scheduler:
switchMapCompletabledoes not operate by default on a particularScheduler.- Error handling:
- If either the current
Observableor the activeCompletableSourcesignals anonError, the resultingCompletableis terminated immediately with thatThrowable. Use theswitchMapCompletableDelayError(Function)to delay such inner failures until every innerCompletableSources and the mainObservableterminates in some fashion. If they fail concurrently, the operator may combine theThrowables into aCompositeExceptionand signal it to the downstream instead. If any inactivated (switched out)CompletableSourcesignals anonErrorlate, theThrowables will be signaled to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors.
History: 2.1.11 - experimental
- Parameters:
mapper- the function called with each upstream item and should return aCompletableSourceto be subscribed to and awaited for (non blockingly) for its terminal event- Returns:
- the new
Completableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
switchMapCompletableDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable switchMapCompletableDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends CompletableSource> mapper) Maps the upstream values intoCompletableSources, subscribes to the newer one while disposing the subscription to the previousCompletableSource, thus keeping at most one activeCompletableSourcerunning and delaying any main or inner errors until all of them terminate.
Since a
CompletableSourcedoesn't produce any items, the resulting reactive type of this operator is aCompletablethat can only indicate successful completion or a failure in any of the innerCompletableSources or the failure of the currentObservable.- Scheduler:
switchMapCompletableDelayErrordoes not operate by default on a particularScheduler.- Error handling:
- The errors of the current
Observableand all theCompletableSources, who had the chance to run to their completion, are delayed until all of them terminate in some fashion. At this point, if there was only one failure, the respectiveThrowableis emitted to the downstream. It there were more than one failures, the operator combines allThrowables into aCompositeExceptionand signals that to the downstream. If any inactivated (switched out)CompletableSourcesignals anonErrorlate, theThrowables will be signaled to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors.
History: 2.1.11 - experimental
- Parameters:
mapper- the function called with each upstream item and should return aCompletableSourceto be subscribed to and awaited for (non blockingly) for its terminal event- Returns:
- the new
Completableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
switchMapMaybe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> switchMapMaybe(@NonNull @NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper) Maps the items of the currentObservableintoMaybeSources and switches (subscribes) to the newer ones while disposing the older ones (and ignoring their signals) and emits the latest success value of the current one if available while failing immediately if the currentObservableor any of the active innerMaybeSources fail.
- Scheduler:
switchMapMaybedoes not operate by default on a particularScheduler.- Error handling:
- This operator terminates with an
onErrorif the currentObservableor any of the innerMaybeSources fail while they are active. When this happens concurrently, their individualThrowableerrors may get combined and emitted as a singleCompositeException. Otherwise, a late (i.e., inactive or switched out)onErrorfrom the currentObservableor from any of the innerMaybeSources will be forwarded to the global error handler viaRxJavaPlugins.onError(Throwable)asUndeliverableException
History: 2.1.11 - experimental
- Type Parameters:
R- the output value type- Parameters:
mapper- the function called with the current upstream event and should return aMaybeSourceto replace the current active inner source and get subscribed to.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
switchMapMaybeDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> switchMapMaybeDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends MaybeSource<? extends @NonNull R>> mapper) Maps the upstream items intoMaybeSources and switches (subscribes) to the newer ones while disposing the older ones (and ignoring their signals) and emits the latest success value of the current one if available, delaying errors from the currentObservableor the innerMaybeSources until all terminate.
- Scheduler:
switchMapMaybeDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.11 - experimental
- Type Parameters:
R- the output value type- Parameters:
mapper- the function called with the current upstream event and should return aMaybeSourceto replace the current active inner source and get subscribed to.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
switchMapSingle
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> switchMapSingle(@NonNull @NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Returns a newObservableby applying a function that you supply to each item emitted by the currentObservablethat returns aSingleSource, and then emitting the item emitted by the most recently emitted of theseSingleSources.The resulting
Observablecompletes if both the currentObservableand the last innerSingleSource, if any, complete. If the currentObservablesignals anonError, the innerSingleSourceis disposed and the error delivered in-sequence.
- Scheduler:
switchMapSingledoes not operate by default on a particularScheduler.
History: 2.0.8 - experimental
- Type Parameters:
R- the element type of the innerSingleSources and the output- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns aSingleSource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
switchMapSingleDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> switchMapSingleDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Returns a newObservableby applying a function that you supply to each item emitted by the currentObservablethat returns aSingleSource, and then emitting the item emitted by the most recently emitted of theseSingleSources and delays any error until allSingleSources terminate.The resulting
Observablecompletes if both the currentObservableand the last innerSingleSource, if any, complete. If the currentObservablesignals anonError, the termination of the last innerSingleSourcewill emit that error as is or wrapped into aCompositeExceptionalong with the other possible errors the former innerSingleSources signaled.
- Scheduler:
switchMapSingleDelayErrordoes not operate by default on a particularScheduler.
History: 2.0.8 - experimental
- Type Parameters:
R- the element type of the innerSingleSources and the output- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns aSingleSource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.2
- See Also:
-
switchMapDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> switchMapDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper) Returns a newObservableby applying a function that you supply to each item emitted by the currentObservablethat returns anObservableSource, and then emitting the items emitted by the most recently emitted of theseObservableSources and delays any error until allObservableSources terminate.The resulting
Observablecompletes if both the currentObservableand the last innerObservableSource, if any, complete. If the currentObservablesignals anonError, the termination of the last innerObservableSourcewill emit that error as is or wrapped into aCompositeExceptionalong with the other possible errors the former innerObservableSources signaled.
- Scheduler:
switchMapDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
R- the element type of the innerObservableSources and the output- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns anObservableSource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.0
- See Also:
-
switchMapDelayError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> switchMapDelayError(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<? extends @NonNull R>> mapper, int bufferSize) Returns a newObservableby applying a function that you supply to each item emitted by the currentObservablethat returns anObservableSource, and then emitting the items emitted by the most recently emitted of theseObservableSources and delays any error until allObservableSources terminate.The resulting
Observablecompletes if both the currentObservableand the last innerObservableSource, if any, complete. If the currentObservablesignals anonError, the termination of the last innerObservableSourcewill emit that error as is or wrapped into aCompositeExceptionalong with the other possible errors the former innerObservableSources signaled.
- Scheduler:
switchMapDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
R- the element type of the innerObservableSources and the output- Parameters:
mapper- a function that, when applied to an item emitted by the currentObservable, returns anObservableSourcebufferSize- the number of elements expected from the current active innerObservableSourceto be buffered- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnullIllegalArgumentException- ifbufferSizeis non-positive- Since:
- 2.0
- See Also:
-
take
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> take(long count) Returns anObservablethat emits only the firstcountitems emitted by the currentObservable. If the source emits fewer thancountitems then all of its items are emitted.
This method returns an
Observablethat will invoke a subscribingObserver'sonNextfunction a maximum ofcounttimes before invokingonComplete.Taking
0items from the currentObservablewill still subscribe to it, allowing the subscription-time side-effects to happen there, but will be immediately disposed and the downstream completed without any item emission.- Scheduler:
- This version of
takedoes not operate by default on a particularScheduler.
- Parameters:
count- the maximum number of items to emit- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- ifcountis negative- See Also:
-
take
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> take(long time, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits those items emitted by the currentObservablebefore a specified time runs out.If time runs out before the
Observablecompletes normally, theonCompleteevent will be signaled on the defaultcomputationScheduler.
- Scheduler:
- This version of
takeoperates by default on thecomputationScheduler.
- Parameters:
time- the length of the time windowunit- the time unit oftime- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
take
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> take(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits those items emitted by the currentObservablebefore a specified time (on a specifiedScheduler) runs out.If time runs out before the
Observablecompletes normally, theonCompleteevent will be signaled on the providedScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
time- the length of the time windowunit- the time unit oftimescheduler- theSchedulerused for time source- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
takeLast
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> takeLast(int count) Returns anObservablethat emits at most the lastcountitems emitted by the currentObservable. If the source emits fewer thancountitems then all of its items are emitted.
- Scheduler:
- This version of
takeLastdoes not operate by default on a particularScheduler.
- Parameters:
count- the maximum number of items to emit from the end of the sequence of items emitted by the currentObservable- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- ifcountis negative- See Also:
-
takeLast
@CheckReturnValue @SchedulerSupport("io.reactivex:trampoline") @NonNull public final @NonNull Observable<T> takeLast(long count, long time, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits at most a specified number of items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted.
- Scheduler:
takeLastdoes not operate on any particular scheduler but uses the current time from thetrampolineScheduler.
- Parameters:
count- the maximum number of items to emittime- the length of the time windowunit- the time unit oftime- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnullIllegalArgumentException- ifcountis negative- See Also:
-
takeLast
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> takeLast(long count, long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits at most a specified number of items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted, where the timing information is provided by a givenScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use for tracking the current time
- Parameters:
count- the maximum number of items to emittime- the length of the time windowunit- the time unit oftimescheduler- theSchedulerthat provides the timestamps for the observed items- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnullIllegalArgumentException- ifcountis negative- See Also:
-
takeLast
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> takeLast(long count, long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean delayError, int bufferSize) Returns anObservablethat emits at most a specified number of items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted, where the timing information is provided by a givenScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use for tracking the current time
- Parameters:
count- the maximum number of items to emittime- the length of the time windowunit- the time unit oftimescheduler- theSchedulerthat provides the timestamps for the observed itemsdelayError- iftrue, an exception signaled by the currentObservableis delayed until the regular elements are consumed by the downstream; iffalse, an exception is immediately signaled and all regular elements droppedbufferSize- the hint about how many elements to expect to be last- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnullIllegalArgumentException- ifcountis negative orbufferSizeis non-positive- See Also:
-
takeLast
@CheckReturnValue @SchedulerSupport("io.reactivex:trampoline") @NonNull public final @NonNull Observable<T> takeLast(long time, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits the items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted.
- Scheduler:
takeLastdoes not operate on any particular scheduler but uses the current time from thetrampolineScheduler.
- Parameters:
time- the length of the time windowunit- the time unit oftime- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
takeLast
@CheckReturnValue @SchedulerSupport("io.reactivex:trampoline") @NonNull public final @NonNull Observable<T> takeLast(long time, @NonNull @NonNull TimeUnit unit, boolean delayError) Returns anObservablethat emits the items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted.
- Scheduler:
takeLastdoes not operate on any particular scheduler but uses the current time from thetrampolineScheduler.
- Parameters:
time- the length of the time windowunit- the time unit oftimedelayError- iftrue, an exception signaled by the currentObservableis delayed until the regular elements are consumed by the downstream; iffalse, an exception is immediately signaled and all regular elements dropped- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnullIllegalArgumentException- ifcountis non-positive- See Also:
-
takeLast
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> takeLast(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits the items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted, where the timing information is provided by a specifiedScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
time- the length of the time windowunit- the time unit oftimescheduler- theSchedulerthat provides the timestamps for the observed items- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
takeLast
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> takeLast(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean delayError) Returns anObservablethat emits the items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted, where the timing information is provided by a specifiedScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
time- the length of the time windowunit- the time unit oftimescheduler- theSchedulerthat provides the timestamps for the observed itemsdelayError- iftrue, an exception signaled by the currentObservableis delayed until the regular elements are consumed by the downstream; iffalse, an exception is immediately signaled and all regular elements dropped- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
takeLast
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> takeLast(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean delayError, int bufferSize) Returns anObservablethat emits the items from the currentObservablethat were emitted in a specified window of time before the currentObservablecompleted, where the timing information is provided by a specifiedScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
time- the length of the time windowunit- the time unit oftimescheduler- theSchedulerthat provides the timestamps for the observed itemsdelayError- iftrue, an exception signaled by the currentObservableis delayed until the regular elements are consumed by the downstream; iffalse, an exception is immediately signaled and all regular elements droppedbufferSize- the hint about how many elements to expect to be last- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
takeUntil
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U> @NonNull Observable<T> takeUntil(@NonNull @NonNull ObservableSource<@NonNull U> other) Returns anObservablethat emits the items emitted by the currentObservableuntil a secondObservableSourceemits an item or completes.
- Scheduler:
takeUntildoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted byother- Parameters:
other- theObservableSourcewhose first emitted item or completion will causetakeUntilto stop emitting items from the currentObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- See Also:
-
takeUntil
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> takeUntil(@NonNull @NonNull Predicate<? super @NonNull T> stopPredicate) Returns anObservablethat emits items emitted by the currentObservable, checks the specified predicate for each item, and then completes when the condition is satisfied.
The difference between this operator and
takeWhile(Predicate)is that here, the condition is evaluated after the item is emitted.- Scheduler:
takeUntildoes not operate by default on a particularScheduler.
- Parameters:
stopPredicate- a function that evaluates an item emitted by the currentObservableand returns aBoolean- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifstopPredicateisnull- Since:
- 1.1.0
- See Also:
-
takeWhile
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> takeWhile(@NonNull @NonNull Predicate<? super @NonNull T> predicate) Returns anObservablethat emits items emitted by the currentObservableso long as each item satisfied a specified condition, and then completes as soon as this condition is not satisfied.
- Scheduler:
takeWhiledoes not operate by default on a particularScheduler.
- Parameters:
predicate- a function that evaluates an item emitted by the currentObservableand returns aBoolean- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifpredicateisnull- See Also:
-
throttleFirst
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> throttleFirst(long windowDuration, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits only the first item emitted by the currentObservableduring sequential time windows of a specified duration.This differs from
throttleLast(long, TimeUnit)in that this only tracks passage of time whereasthrottleLastticks at scheduled intervals.
- Scheduler:
throttleFirstoperates by default on thecomputationScheduler.
- Parameters:
windowDuration- time to wait before emitting another item after emitting the last itemunit- the unit of time ofwindowDuration- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
throttleFirst
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> throttleFirst(long skipDuration, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits only the first item emitted by the currentObservableduring sequential time windows of a specified duration, where the windows are managed by a specifiedScheduler.This differs from
throttleLast(long, TimeUnit)in that this only tracks passage of time whereasthrottleLastticks at scheduled intervals.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
skipDuration- time to wait before emitting another item after emitting the last itemunit- the unit of time ofskipDurationscheduler- theSchedulerto use internally to manage the timers that handle timeout for each event- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
throttleFirst
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> throttleFirst(long skipDuration, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, @NonNull @NonNull Consumer<? super @NonNull T> onDropped) Returns anObservablethat emits only the first item emitted by the currentObservableduring sequential time windows of a specified duration, where the windows are managed by a specifiedScheduler.This differs from
throttleLast(long, TimeUnit)in that this only tracks passage of time whereasthrottleLastticks at scheduled intervals.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
skipDuration- time to wait before emitting another item after emitting the last itemunit- the unit of time ofskipDurationscheduler- theSchedulerto use internally to manage the timers that handle timeout for each eventonDropped- called when an item doesn't get delivered to the downstream- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorscheduleroronDroppedisnull- Since:
- 3.1.6 - Experimental
- See Also:
-
throttleLast
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> throttleLast(long intervalDuration, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits only the last item emitted by the currentObservableduring sequential time windows of a specified duration.This differs from
throttleFirst(long, TimeUnit)in that this ticks along at a scheduled interval whereasthrottleFirstdoes not tick, it just tracks passage of time.
- Scheduler:
throttleLastoperates by default on thecomputationScheduler.
- Parameters:
intervalDuration- duration of windows within which the last item emitted by the currentObservablewill be emittedunit- the unit of time ofintervalDuration- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
throttleLast
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> throttleLast(long intervalDuration, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, @NonNull @NonNull Consumer<? super @NonNull T> onDropped) Returns anObservablethat emits only the last item emitted by the currentObservableduring sequential time windows of a specified duration, where the duration is governed by a specifiedScheduler.This differs from
throttleFirst(long, TimeUnit)in that this ticks along at a scheduled interval whereasthrottleFirstdoes not tick, it just tracks passage of time.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
intervalDuration- duration of windows within which the last item emitted by the currentObservablewill be emittedunit- the unit of time ofintervalDurationscheduler- theSchedulerto use internally to manage the timers that handle timeout for each eventonDropped- called with the current entry when it has been replaced by a new one- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnulloronDroppedisnull- Since:
- 3.1.6 - Experimental
- See Also:
-
throttleLast
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> throttleLast(long intervalDuration, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits only the last item emitted by the currentObservableduring sequential time windows of a specified duration, where the duration is governed by a specifiedScheduler.This differs from
throttleFirst(long, TimeUnit)in that this ticks along at a scheduled interval whereasthrottleFirstdoes not tick, it just tracks passage of time.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
intervalDuration- duration of windows within which the last item emitted by the currentObservablewill be emittedunit- the unit of time ofintervalDurationscheduler- theSchedulerto use internally to manage the timers that handle timeout for each event- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
throttleLatest
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> throttleLatest(long timeout, @NonNull @NonNull TimeUnit unit) Throttles items from the currentObservableby first emitting the next item from upstream, then periodically emitting the latest item (if any) when the specified timeout elapses between them.
Unlike the option with
throttleLatest(long, TimeUnit, boolean), the very last item being held back (if any) is not emitted when the upstream completes.If no items were emitted from the upstream during this timeout phase, the next upstream item is emitted immediately and the timeout window starts from then.
- Scheduler:
throttleLatestoperates by default on thecomputationScheduler.
History: 2.1.14 - experimental
- Parameters:
timeout- the time to wait after an item emission towards the downstream before trying to emit the latest item from upstream againunit- the time unit- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 2.2
- See Also:
-
throttleLatest
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> throttleLatest(long timeout, @NonNull @NonNull TimeUnit unit, boolean emitLast) Throttles items from the currentObservableby first emitting the next item from upstream, then periodically emitting the latest item (if any) when the specified timeout elapses between them.
If no items were emitted from the upstream during this timeout phase, the next upstream item is emitted immediately and the timeout window starts from then.
- Scheduler:
throttleLatestoperates by default on thecomputationScheduler.
History: 2.1.14 - experimental
- Parameters:
timeout- the time to wait after an item emission towards the downstream before trying to emit the latest item from upstream againunit- the time unitemitLast- Iftrue, the very last item from the upstream will be emitted immediately when the upstream completes, regardless if there is a timeout window active or not. Iffalse, the very last upstream item is ignored and the flow terminates.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 2.2
- See Also:
-
throttleLatest
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> throttleLatest(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Throttles items from the currentObservableby first emitting the next item from upstream, then periodically emitting the latest item (if any) when the specified timeout elapses between them.
Unlike the option with
throttleLatest(long, TimeUnit, Scheduler, boolean), the very last item being held back (if any) is not emitted when the upstream completes.If no items were emitted from the upstream during this timeout phase, the next upstream item is emitted immediately and the timeout window starts from then.
- Scheduler:
- You specify which
Schedulerthis operator will use.
History: 2.1.14 - experimental
- Parameters:
timeout- the time to wait after an item emission towards the downstream before trying to emit the latest item from upstream againunit- the time unitscheduler- theSchedulerwhere the timed wait and latest item emission will be performed- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- Since:
- 2.2
- See Also:
-
throttleLatest
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> throttleLatest(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean emitLast) Throttles items from the currentObservableby first emitting the next item from upstream, then periodically emitting the latest item (if any) when the specified timeout elapses between them.
If no items were emitted from the upstream during this timeout phase, the next upstream item is emitted immediately and the timeout window starts from then.
- Scheduler:
- You specify which
Schedulerthis operator will use.
History: 2.1.14 - experimental
- Parameters:
timeout- the time to wait after an item emission towards the downstream before trying to emit the latest item from upstream againunit- the time unitscheduler- theSchedulerwhere the timed wait and latest item emission will be performedemitLast- Iftrue, the very last item from the upstream will be emitted immediately when the upstream completes, regardless if there is a timeout window active or not. Iffalse, the very last upstream item is ignored and the flow terminates.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- Since:
- 2.2
-
throttleLatest
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> throttleLatest(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean emitLast, @NonNull @NonNull Consumer<? super @NonNull T> onDropped) Throttles items from the currentObservableby first emitting the next item from upstream, then periodically emitting the latest item (if any) when the specified timeout elapses between them, invoking the consumer for any dropped item.
If no items were emitted from the upstream during this timeout phase, the next upstream item is emitted immediately and the timeout window starts from then.
- Scheduler:
- You specify which
Schedulerthis operator will use. - Error handling:
-
If the upstream signals an
onErrororonDroppedcallback crashes, the error is delivered immediately to the downstream. If both happen, aCompositeExceptionis created, containing both the upstream and the callback error. If theonDroppedcallback crashes when the sequence gets disposed, the exception is forwarded to the global error handler viaRxJavaPlugins.onError(Throwable).
- Parameters:
timeout- the time to wait after an item emission towards the downstream before trying to emit the latest item from upstream againunit- the time unitscheduler- theSchedulerwhere the timed wait and latest item emission will be performedemitLast- Iftrue, the very last item from the upstream will be emitted immediately when the upstream completes, regardless if there is a timeout window active or not. Iffalse, the very last upstream item is ignored and the flow terminates.onDropped- called when an item is replaced by a newer item that doesn't get delivered to the downstream, including the very last item ifemitLastisfalseand the current undelivered item when the sequence gets disposed.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunit,scheduleroronDroppedisnull- Since:
- 3.1.6 - Experimental
-
throttleWithTimeout
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> throttleWithTimeout(long timeout, @NonNull @NonNull TimeUnit unit) Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by newer items before a timeout value expires. The timer resets on each emission (alias todebounce(long, TimeUnit, Scheduler)).Note: If items keep being emitted by the current
Observablefaster than the timeout then no items will be emitted by the resultingObservable.
- Scheduler:
throttleWithTimeoutoperates by default on thecomputationScheduler.
- Parameters:
timeout- the length of the window of time that must pass after the emission of an item from the currentObservable, in which the currentObservableemits no items, in order for the item to be emitted by the resultingObservableunit- the unit of time for the specifiedtimeout- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
throttleWithTimeout
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> throttleWithTimeout(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by newer items before a timeout value expires on a specifiedScheduler. The timer resets on each emission (Alias todebounce(long, TimeUnit, Scheduler)).Note: If items keep being emitted by the current
Observablefaster than the timeout then no items will be emitted by the resultingObservable.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timeout- the length of the window of time that must pass after the emission of an item from the currentObservable, in which the currentObservableemits no items, in order for the item to be emitted by the resultingObservableunit- the unit of time for the specifiedtimeoutscheduler- theSchedulerto use internally to manage the timers that handle the timeout for each item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
throttleWithTimeout
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> throttleWithTimeout(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, @NonNull @NonNull Consumer<? super @NonNull T> onDropped) Returns anObservablethat mirrors the currentObservable, except that it drops items emitted by the currentObservablethat are followed by newer items before a timeout value expires on a specifiedScheduler. The timer resets on each emission (Alias todebounce(long, TimeUnit, Scheduler)).Note: If items keep being emitted by the current
Observablefaster than the timeout then no items will be emitted by the resultingObservable.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timeout- the length of the window of time that must pass after the emission of an item from the currentObservable, in which the currentObservableemits no items, in order for the item to be emitted by the resultingObservableunit- the unit of time for the specifiedtimeoutscheduler- theSchedulerto use internally to manage the timers that handle the timeout for each itemonDropped- called with the current entry when it has been replaced by a new one- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnulloronDroppedisnull- Since:
- 3.1.6 - Experimental
- See Also:
-
timeInterval
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<Timed<T>> timeInterval()Returns anObservablethat emits records of the time interval between consecutive items emitted by the currentObservable.
- Scheduler:
timeIntervaldoes not operate on any particular scheduler but uses the current time from thecomputationScheduler.
- Returns:
- the new
Observableinstance - See Also:
-
timeInterval
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<Timed<T>> timeInterval(@NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits records of the time interval between consecutive items emitted by the currentObservable, where this interval is computed on a specifiedScheduler.
- Scheduler:
- The operator does not operate on any particular scheduler but uses the current time
from the specified
Scheduler.
- Parameters:
scheduler- theSchedulerused to compute time intervals- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifschedulerisnull- See Also:
-
timeInterval
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<Timed<T>> timeInterval(@NonNull @NonNull TimeUnit unit) Returns anObservablethat emits records of the time interval between consecutive items emitted by the currentObservable.
- Scheduler:
timeIntervaldoes not operate on any particular scheduler but uses the current time from thecomputationScheduler.
- Parameters:
unit- the time unit for the current time- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
timeInterval
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<Timed<T>> timeInterval(@NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits records of the time interval between consecutive items emitted by the currentObservable, where this interval is computed on a specifiedScheduler.
- Scheduler:
- The operator does not operate on any particular scheduler but uses the current time
from the specified
Scheduler.
- Parameters:
unit- the time unit for the current timescheduler- theSchedulerused to compute time intervals- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
timeout
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull V> @NonNull Observable<T> timeout(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull V>> itemTimeoutIndicator) Returns anObservablethat mirrors the currentObservable, but notifies observers of aTimeoutExceptionif an item emitted by the currentObservabledoesn't arrive within a window of time after the emission of the previous item, where that period of time is measured by anObservableSourcethat is a function of the previous item.
Note: The arrival of the first source item is never timed out.
- Scheduler:
- This version of
timeoutoperates by default on theimmediateScheduler.
- Type Parameters:
V- the timeout value type (ignored)- Parameters:
itemTimeoutIndicator- a function that returns anObservableSourcefor each item emitted by the currentObservableand that determines the timeout window for the subsequent item- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitemTimeoutIndicatorisnull- See Also:
-
timeout
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull V> @NonNull Observable<T> timeout(@NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull V>> itemTimeoutIndicator, @NonNull @NonNull ObservableSource<? extends @NonNull T> fallback) Returns anObservablethat mirrors the currentObservable, but that switches to a fallbackObservableSourceif an item emitted by the currentObservabledoesn't arrive within a window of time after the emission of the previous item, where that period of time is measured by anObservableSourcethat is a function of the previous item.
Note: The arrival of the first source item is never timed out.
- Scheduler:
- This version of
timeoutoperates by default on theimmediateScheduler.
- Type Parameters:
V- the timeout value type (ignored)- Parameters:
itemTimeoutIndicator- a function that returns anObservableSource, for each item emitted by the currentObservable, that determines the timeout window for the subsequent itemfallback- the fallbackObservableSourceto switch to if the currentObservabletimes out- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifitemTimeoutIndicatororfallbackisnull- See Also:
-
timeout
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> timeout(long timeout, @NonNull @NonNull TimeUnit unit) Returns anObservablethat mirrors the currentObservablebut applies a timeout policy for each emitted item. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the resultingObservableterminates and notifies observers of aTimeoutException.
- Scheduler:
- This version of
timeoutoperates by default on thecomputationScheduler.
- Parameters:
timeout- maximum duration between emitted items before a timeout occursunit- the unit of time that applies to thetimeoutargument.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
timeout
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<T> timeout(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull ObservableSource<? extends @NonNull T> fallback) Returns anObservablethat mirrors the currentObservablebut applies a timeout policy for each emitted item. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the currentObservableis disposed and the resultingObservablebegins instead to mirror a fallbackObservableSource.
- Scheduler:
- This version of
timeoutoperates by default on thecomputationScheduler.
- Parameters:
timeout- maximum duration between items before a timeout occursunit- the unit of time that applies to thetimeoutargumentfallback- the fallbackObservableSourceto use in case of a timeout- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorfallbackisnull- See Also:
-
timeout
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> timeout(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, @NonNull @NonNull ObservableSource<? extends @NonNull T> fallback) Returns anObservablethat mirrors the currentObservablebut applies a timeout policy for each emitted item using a specifiedScheduler. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the currentObservableis disposed and returnedObservablebegins instead to mirror a fallbackObservableSource.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timeout- maximum duration between items before a timeout occursunit- the unit of time that applies to thetimeoutargumentscheduler- theSchedulerto run the timeout timers onfallback- theObservableSourceto use as the fallback in case of a timeout- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunit,schedulerorfallbackisnull- See Also:
-
timeout
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> timeout(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat mirrors the currentObservablebut applies a timeout policy for each emitted item, where this policy is governed on a specifiedScheduler. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the resultingObservableterminates and notifies observers of aTimeoutException.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timeout- maximum duration between items before a timeout occursunit- the unit of time that applies to thetimeoutargumentscheduler- theSchedulerto run the timeout timers on- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
timeout
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull V> @NonNull Observable<T> timeout(@NonNull @NonNull ObservableSource<@NonNull U> firstTimeoutIndicator, @NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull V>> itemTimeoutIndicator) Returns anObservablethat mirrors the currentObservable, but notifies observers of aTimeoutExceptionif either the first item emitted by the currentObservableor any subsequent item doesn't arrive within time windows defined by indicatorObservableSources.
- Scheduler:
- This version of
timeoutoperates by default on theimmediateScheduler.
- Type Parameters:
U- the first timeout value type (ignored)V- the subsequent timeout value type (ignored)- Parameters:
firstTimeoutIndicator- a function that returns anObservableSourcethat determines the timeout window for the first source itemitemTimeoutIndicator- a function that returns anObservableSourcefor each item emitted by the currentObservableand that determines the timeout window in which the subsequent source item must arrive in order to continue the sequence- Returns:
- the new
Observableinstance - Throws:
NullPointerException- iffirstTimeoutIndicatororitemTimeoutIndicatorisnull- See Also:
-
timeout
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull V> @NonNull Observable<T> timeout(@NonNull @NonNull ObservableSource<@NonNull U> firstTimeoutIndicator, @NonNull @NonNull Function<? super @NonNull T, ? extends ObservableSource<@NonNull V>> itemTimeoutIndicator, @NonNull @NonNull ObservableSource<? extends @NonNull T> fallback) Returns anObservablethat mirrors the currentObservable, but switches to a fallbackObservableSourceif either the first item emitted by the currentObservableor any subsequent item doesn't arrive within time windows defined by indicatorObservableSources.
- Scheduler:
- This version of
timeoutoperates by default on theimmediateScheduler.
- Type Parameters:
U- the first timeout value type (ignored)V- the subsequent timeout value type (ignored)- Parameters:
firstTimeoutIndicator- a function that returns anObservableSourcewhich determines the timeout window for the first source itemitemTimeoutIndicator- a function that returns anObservableSourcefor each item emitted by the currentObservableand that determines the timeout window in which the subsequent source item must arrive in order to continue the sequencefallback- the fallbackObservableSourceto switch to if the currentObservabletimes out- Returns:
- the new
Observableinstance - Throws:
NullPointerException- iffirstTimeoutIndicator,itemTimeoutIndicatororfallbackisnull- See Also:
-
timestamp
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<Timed<T>> timestamp()Returns anObservablethat emits each item emitted by the currentObservable, wrapped in aTimedobject.
- Scheduler:
timestampdoes not operate on any particular scheduler but uses the current time from thecomputationScheduler.
- Returns:
- the new
Observableinstance - See Also:
-
timestamp
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<Timed<T>> timestamp(@NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits each item emitted by the currentObservable, wrapped in aTimedobject whose timestamps are provided by a specifiedScheduler.
- Scheduler:
- This operator does not operate on any particular scheduler but uses the current time
from the specified
Scheduler.
- Parameters:
scheduler- theSchedulerto use as a time source- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifschedulerisnull- See Also:
-
timestamp
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<Timed<T>> timestamp(@NonNull @NonNull TimeUnit unit) Returns anObservablethat emits each item emitted by the currentObservable, wrapped in aTimedobject.
- Scheduler:
timestampdoes not operate on any particular scheduler but uses the current time from thecomputationScheduler.
- Parameters:
unit- the time unit for the current time- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
timestamp
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<Timed<T>> timestamp(@NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits each item emitted by the currentObservable, wrapped in aTimedobject whose timestamps are provided by a specifiedScheduler.
- Scheduler:
- This operator does not operate on any particular scheduler but uses the current time
from the specified
Scheduler.
- Parameters:
unit- the time unit for the current timescheduler- theSchedulerto use as a time source- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
to
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> R to(@NonNull @NonNull ObservableConverter<@NonNull T, ? extends @NonNull R> converter) Calls the specified converter function during assembly time and returns its resulting value.This allows fluent conversion to any other type.
- Scheduler:
todoes not operate by default on a particularScheduler.
History: 2.1.7 - experimental
- Type Parameters:
R- the resulting object type- Parameters:
converter- the function that receives the currentObservableinstance and returns a value- Returns:
- the converted value
- Throws:
NullPointerException- ifconverterisnull- Since:
- 2.2
-
toList
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<@NonNull List<T>> toList()Returns aSinglethat emits a single item, aListcomposed of all the items emitted by the current and finiteObservable.
Normally, an
ObservableSourcethat returns multiple items will do so by invoking itsObserver'sonNextmethod for each such item. You can change this behavior by having the operator to compose a list of all of these items and then to invoke theSingleObserver'sonSuccessmethod once, passing it the entire list, by calling theObservable'stoListmethod prior to calling itssubscribe()method.Note that this operator requires the upstream to signal
onCompletefor the accumulated list to be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toListdoes not operate by default on a particularScheduler.
- Returns:
- the new
Singleinstance - See Also:
-
toList
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<@NonNull List<T>> toList(int capacityHint) Returns aSinglethat emits a single item, aListcomposed of all the items emitted by the current and finiteObservable.
Normally, an
ObservableSourcethat returns multiple items will do so by invoking itsObserver'sonNextmethod for each such item. You can change this behavior by having the operator to compose a list of all of these items and then to invoke theSingleObserver'sonSuccessmethod once, passing it the entire list, by calling theObservable'stoListmethod prior to calling itssubscribe()method.Note that this operator requires the upstream to signal
onCompletefor the accumulated list to be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toListdoes not operate by default on a particularScheduler.
- Parameters:
capacityHint- the number of elements expected from the currentObservable- Returns:
- the new
Singleinstance - Throws:
IllegalArgumentException- ifcapacityHintis non-positive- See Also:
-
toList
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U extends Collection<? super @NonNull T>> @NonNull Single<U> toList(@NonNull @NonNull Supplier<@NonNull U> collectionSupplier) Returns aSinglethat emits a single item, aCollection(subclass) composed of all the items emitted by the finite upstreamObservable.
Normally, an
ObservableSourcethat returns multiple items will do so by invoking itsObserver'sonNextmethod for each such item. You can change this behavior by having the operator to compose a collection of all of these items and then to invoke theSingleObserver'sonSuccessmethod once, passing it the entire collection, by calling theObservable'stoListmethod prior to calling itssubscribe()method.Note that this operator requires the upstream to signal
onCompletefor the accumulated collection to be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toListdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the subclass of a collection of Ts- Parameters:
collectionSupplier- theSupplierreturning the collection (for each individualObserver) to be filled in- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifcollectionSupplierisnull- See Also:
-
toMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K> @NonNull Single<@NonNull Map<K,T>> toMap(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector) Returns aSinglethat emits a singleHashMapcontaining all items emitted by the current and finiteObservable, mapped by the keys returned by a specifiedkeySelectorfunction.
If more than one source item maps to the same key, the
HashMapwill contain the latest of those items.Note that this operator requires the upstream to signal
onCompletefor the accumulatedHashMapto be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toMapdoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key type of the Map- Parameters:
keySelector- the function that extracts the key from a source item to be used in theHashMap- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifkeySelectorisnull- See Also:
-
toMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K, @NonNull V> @NonNull Single<Map<K,V>> toMap(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, @NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull V> valueSelector) Returns aSinglethat emits a singleHashMapcontaining values corresponding to items emitted by the current and finiteObservable, mapped by the keys and values returned by the given selector functions.
If more than one source item maps to the same key, the
HashMapwill contain a single entry that corresponds to the latest of those items.Note that this operator requires the upstream to signal
onCompletefor the accumulatedHashMapto be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toMapdoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key type of theHashMapV- the value type of theHashMap- Parameters:
keySelector- the function that extracts the key from a source item to be used in theHashMapvalueSelector- the function that extracts the value from a source item to be used in theHashMap- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifkeySelectororvalueSelectorisnull- See Also:
-
toMap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K, @NonNull V> @NonNull Single<Map<K,V>> toMap(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, @NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull V> valueSelector, @NonNull @NonNull Supplier<? extends Map<@NonNull K, @NonNull V>> mapSupplier) Returns aSinglethat emits a singleMap(subclass), returned by a specifiedmapFactoryfunction, that contains keys and values extracted from the items, via selector functions, emitted by the current and finiteObservable.
Note that this operator requires the upstream to signal
onCompletefor the accumulatedMapto be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toMapdoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key type of theMapV- the value type of theMap- Parameters:
keySelector- the function that extracts the key from a source item to be used in theMapvalueSelector- the function that extracts the value from the source items to be used as value in theMapmapSupplier- the function that returns aMapinstance to be used- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifkeySelector,valueSelectorormapSupplierisnull- See Also:
-
toMultimap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K> @NonNull Single<@NonNull Map<K, Collection<T>>> toMultimap(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector) Returns aSinglethat emits a singleHashMapthat contains anArrayListof items emitted by the current and finiteObservablekeyed by a specifiedkeySelectorfunction.
Note that this operator requires the upstream to signal
onCompletefor the accumulatedHashMapto be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toMultimapdoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key type of theHashMap- Parameters:
keySelector- the function that extracts the key from the source items to be used as key in theHashMap- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifkeySelectorisnull- See Also:
-
toMultimap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K, @NonNull V> @NonNull Single<@NonNull Map<K, Collection<V>>> toMultimap(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, Function<? super @NonNull T, ? extends @NonNull V> valueSelector) Returns aSinglethat emits a singleHashMapthat contains anArrayListof values extracted by a specifiedvalueSelectorfunction from items emitted by the current and finiteObservable, keyed by a specifiedkeySelectorfunction.
Note that this operator requires the upstream to signal
onCompletefor the accumulatedHashMapto be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toMultimapdoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key type of theHashMapV- the value type of theHashMap- Parameters:
keySelector- the function that extracts a key from the source items to be used as key in theHashMapvalueSelector- the function that extracts a value from the source items to be used as value in theHashMap- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifkeySelectororvalueSelectorisnull- See Also:
-
toMultimap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K, @NonNull V> @NonNull Single<@NonNull Map<K, Collection<V>>> toMultimap(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, @NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull V> valueSelector, @NonNull @NonNull Supplier<? extends Map<@NonNull K, Collection<@NonNull V>>> mapSupplier, @NonNull @NonNull Function<? super @NonNull K, ? extends Collection<? super @NonNull V>> collectionFactory) Returns aSinglethat emits a singleMap(subclass), returned by a specifiedmapFactoryfunction, that contains a customCollectionof values, extracted by a specifiedvalueSelectorfunction from items emitted by the current and finiteObservable, and keyed by thekeySelectorfunction.
Note that this operator requires the upstream to signal
onCompletefor the accumulatedMapto be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toMultimapdoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key type of theMapV- the value type of theMap- Parameters:
keySelector- the function that extracts a key from the source items to be used as the key in theMapvalueSelector- the function that extracts a value from the source items to be used as the value in theMapmapSupplier- the function that returns aMapinstance to be usedcollectionFactory- the function that returns aCollectioninstance for a particular key to be used in theMap- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifkeySelector,valueSelector,mapSupplierorcollectionFactoryisnull- See Also:
-
toMultimap
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull K, @NonNull V> @NonNull Single<@NonNull Map<K, Collection<V>>> toMultimap(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull K> keySelector, @NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull V> valueSelector, @NonNull @NonNull Supplier<Map<@NonNull K, Collection<@NonNull V>>> mapSupplier) Returns aSinglethat emits a singleMap(subclass), returned by a specifiedmapFactoryfunction, that contains anArrayListof values, extracted by a specifiedvalueSelectorfunction from items emitted by the current and finiteObservableand keyed by thekeySelectorfunction.
Note that this operator requires the upstream to signal
onCompletefor the accumulatedMapto be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toMultimapdoes not operate by default on a particularScheduler.
- Type Parameters:
K- the key type of theMapV- the value type of theMap- Parameters:
keySelector- the function that extracts a key from the source items to be used as the key in theMapvalueSelector- the function that extracts a value from the source items to be used as the value in theMapmapSupplier- the function that returns aMapinstance to be used- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifkeySelector,valueSelectorormapSupplierisnull- See Also:
-
toFlowable
@BackpressureSupport(SPECIAL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> toFlowable(@NonNull @NonNull BackpressureStrategy strategy) Converts the currentObservableinto aFlowableby applying the specified backpressure strategy.Marble diagrams for the various backpressure strategies are as follows:
BackpressureStrategy.BUFFER
BackpressureStrategy.DROP
BackpressureStrategy.LATEST
BackpressureStrategy.ERROR
BackpressureStrategy.MISSING
- Backpressure:
- The operator applies the chosen backpressure strategy of
BackpressureStrategyenum. - Scheduler:
toFlowabledoes not operate by default on a particularScheduler.
- Parameters:
strategy- the backpressure strategy to apply- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifstrategyisnull
-
toSortedList
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<@NonNull List<T>> toSortedList()Returns aSinglethat emits aListthat contains the items emitted by the current and finiteObservable, in a sorted order. Each item emitted by the currentObservablemust implementComparablewith respect to all other items in the sequence.If any item emitted by the current
Observabledoes not implementComparablewith respect to all other items emitted by the currentObservable, no items will be emitted and the sequence is terminated with aClassCastException.
Note that this operator requires the upstream to signal
onCompletefor the accumulatedListto be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toSortedListdoes not operate by default on a particularScheduler.
- Returns:
- the new
Singleinstance - See Also:
-
toSortedList
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<@NonNull List<T>> toSortedList(@NonNull @NonNull Comparator<? super @NonNull T> comparator) Returns aSinglethat emits aListthat contains the items emitted by the current and finiteObservable, in a sorted order based on a specified comparison function.
Note that this operator requires the upstream to signal
onCompletefor the accumulatedListto be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toSortedListdoes not operate by default on a particularScheduler.
- Parameters:
comparator- a function that compares two items emitted by the currentObservableand returns anintthat indicates their sort order- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifcomparatorisnull- See Also:
-
toSortedList
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<@NonNull List<T>> toSortedList(@NonNull @NonNull Comparator<? super @NonNull T> comparator, int capacityHint) Returns aSinglethat emits aListthat contains the items emitted by the current and finiteObservable, in a sorted order based on a specified comparison function.
Note that this operator requires the upstream to signal
onCompletefor the accumulatedListto be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toSortedListdoes not operate by default on a particularScheduler.
- Parameters:
comparator- a function that compares two items emitted by the currentObservableand returns anintthat indicates their sort ordercapacityHint- the initial capacity of theListused to accumulate items before sorting- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifcomparatorisnullIllegalArgumentException- ifcapacityHintis non-positive- Since:
- 2.0
- See Also:
-
toSortedList
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<@NonNull List<T>> toSortedList(int capacityHint) Returns aSinglethat emits aListthat contains the items emitted by the current and finiteObservable, in a sorted order. Each item emitted by the currentObservablemust implementComparablewith respect to all other items in the sequence.If any item emitted by the current
Observabledoes not implementComparablewith respect to all other items emitted by the currentObservable, no items will be emitted and the sequence is terminated with aClassCastException.
Note that this operator requires the upstream to signal
onCompletefor the accumulatedListto be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatalOutOfMemoryError.- Scheduler:
toSortedListdoes not operate by default on a particularScheduler.
- Parameters:
capacityHint- the initial capacity of theListused to accumulate items before sorting- Returns:
- the new
Singleinstance - Throws:
IllegalArgumentException- ifcapacityHintis non-positive- Since:
- 2.0
- See Also:
-
unsubscribeOn
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<T> unsubscribeOn(@NonNull @NonNull Scheduler scheduler) Return anObservablethat schedules the downstreamObservers'disposecalls aimed at the currentObservableon the givenScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
scheduler- theSchedulerto perform the call todispose()of the upstreamDisposable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifschedulerisnull- See Also:
-
window
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<Observable<T>> window(long count) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping windows, each containingcountitems. When the currentObservablecompletes or encounters an error, the resultingObservableemits the current window and propagates the notification from the currentObservable.
- Scheduler:
- This version of
windowdoes not operate by default on a particularScheduler.
- Parameters:
count- the maximum size of each window before it should be emitted- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- ifcountis non-positive- See Also:
-
window
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<Observable<T>> window(long count, long skip) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservableemits windows everyskipitems, each containing no more thancountitems. When the currentObservablecompletes or encounters an error, the resultingObservableemits the current window and propagates the notification from the currentObservable.
- Scheduler:
- This version of
windowdoes not operate by default on a particularScheduler.
- Parameters:
count- the maximum size of each window before it should be emittedskip- how many items need to be skipped before starting a new window. Note that ifskipandcountare equal this is the same operation aswindow(long).- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- ifcountorskipis non-positive- See Also:
-
window
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<Observable<T>> window(long count, long skip, int bufferSize) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservableemits windows everyskipitems, each containing no more thancountitems. When the currentObservablecompletes or encounters an error, the resultingObservableemits the current window and propagates the notification from the currentObservable.
- Scheduler:
- This version of
windowdoes not operate by default on a particularScheduler.
- Parameters:
count- the maximum size of each window before it should be emittedskip- how many items need to be skipped before starting a new window. Note that ifskipandcountare equal this is the same operation aswindow(long).bufferSize- the capacity hint for the buffer in the inner windows- Returns:
- the new
Observableinstance - Throws:
IllegalArgumentException- ifcount,skiporbufferSizeis non-positive- See Also:
-
window
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<Observable<T>> window(long timespan, long timeskip, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservablestarts a new window periodically, as determined by thetimeskipargument. It emits each window after a fixed timespan, specified by thetimespanargument. When the currentObservablecompletes or encounters an error, the resultingObservableemits the current window and propagates the notification from the currentObservable.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- This version of
windowoperates by default on thecomputationScheduler.
- Parameters:
timespan- the period of time each window collects items before it should be emittedtimeskip- the period of time after which a new window will be createdunit- the unit of time that applies to thetimespanandtimeskiparguments- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnullIllegalArgumentException- iftimespanortimeskipis non-positive- See Also:
-
window
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<Observable<T>> window(long timespan, long timeskip, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservablestarts a new window periodically, as determined by thetimeskipargument. It emits each window after a fixed timespan, specified by thetimespanargument. When the currentObservablecompletes or encounters an error, the resultingObservableemits the current window and propagates the notification from the currentObservable.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timespan- the period of time each window collects items before it should be emittedtimeskip- the period of time after which a new window will be createdunit- the unit of time that applies to thetimespanandtimeskipargumentsscheduler- theSchedulerto use when determining the end and start of a window- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnullIllegalArgumentException- iftimespanortimeskipis non-positive- See Also:
-
window
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<Observable<T>> window(long timespan, long timeskip, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, int bufferSize) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservablestarts a new window periodically, as determined by thetimeskipargument. It emits each window after a fixed timespan, specified by thetimespanargument. When the currentObservablecompletes or encounters an error, the resultingObservableemits the current window and propagates the notification from the currentObservable.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timespan- the period of time each window collects items before it should be emittedtimeskip- the period of time after which a new window will be createdunit- the unit of time that applies to thetimespanandtimeskipargumentsscheduler- theSchedulerto use when determining the end and start of a windowbufferSize- the capacity hint for the buffer in the inner windows- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnullIllegalArgumentException- iftimespan,timeskiporbufferSizeis non-positive- See Also:
-
window
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<Observable<T>> window(long timespan, @NonNull @NonNull TimeUnit unit) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping windows, each of a fixed duration specified by thetimespanargument. When the currentObservablecompletes or encounters an error, the resultingObservableemits the current window and propagates the notification from the currentObservable.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- This version of
windowoperates by default on thecomputationScheduler.
- Parameters:
timespan- the period of time each window collects items before it should be emitted and replaced with a new windowunit- the unit of time that applies to thetimespanargument- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnull- See Also:
-
window
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<Observable<T>> window(long timespan, @NonNull @NonNull TimeUnit unit, long count) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping windows, each of a fixed duration as specified by thetimespanargument or a maximum size as specified by thecountargument (whichever is reached first). When the currentObservablecompletes or encounters an error, the resultingObservableemits the current window and propagates the notification from the currentObservable.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- This version of
windowoperates by default on thecomputationScheduler.
- Parameters:
timespan- the period of time each window collects items before it should be emitted and replaced with a new windowunit- the unit of time that applies to thetimespanargumentcount- the maximum size of each window before it should be emitted- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnullIllegalArgumentException- ifcountis non-positive- See Also:
-
window
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Observable<Observable<T>> window(long timespan, @NonNull @NonNull TimeUnit unit, long count, boolean restart) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping windows, each of a fixed duration as specified by thetimespanargument or a maximum size as specified by thecountargument (whichever is reached first). When the currentObservablecompletes or encounters an error, the resultingObservableemits the current window and propagates the notification from the currentObservable.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- This version of
windowoperates by default on thecomputationScheduler.
- Parameters:
timespan- the period of time each window collects items before it should be emitted and replaced with a new windowunit- the unit of time that applies to thetimespanargumentcount- the maximum size of each window before it should be emittedrestart- iftrue, when a window reaches the capacity limit, the timer is restarted as well- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitisnullIllegalArgumentException- ifcountis non-positive- See Also:
-
window
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<Observable<T>> window(long timespan, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping windows, each of a fixed duration as specified by thetimespanargument. When the currentObservablecompletes or encounters an error, the resultingObservableemits the current window and propagates the notification from the currentObservable.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timespan- the period of time each window collects items before it should be emitted and replaced with a new windowunit- the unit of time which applies to thetimespanargumentscheduler- theSchedulerto use when determining the end and start of a window- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnull- See Also:
-
window
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<Observable<T>> window(long timespan, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, long count) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping windows, each of a fixed duration specified by thetimespanargument or a maximum size specified by thecountargument (whichever is reached first). When the currentObservablecompletes or encounters an error, the resultingObservableemits the current window and propagates the notification from the currentObservable.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timespan- the period of time each window collects items before it should be emitted and replaced with a new windowunit- the unit of time which applies to thetimespanargumentscheduler- theSchedulerto use when determining the end and start of a windowcount- the maximum size of each window before it should be emitted- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnullIllegalArgumentException- ifcountis non-positive- See Also:
-
window
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<Observable<T>> window(long timespan, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, long count, boolean restart) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping windows, each of a fixed duration specified by thetimespanargument or a maximum size specified by thecountargument (whichever is reached first). When the currentObservablecompletes or encounters an error, the resultingObservableemits the current window and propagates the notification from the currentObservable.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timespan- the period of time each window collects items before it should be emitted and replaced with a new windowunit- the unit of time which applies to thetimespanargumentscheduler- theSchedulerto use when determining the end and start of a windowcount- the maximum size of each window before it should be emittedrestart- iftrue, when a window reaches the capacity limit, the timer is restarted as well- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnullIllegalArgumentException- ifcountis non-positive- See Also:
-
window
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Observable<Observable<T>> window(long timespan, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, long count, boolean restart, int bufferSize) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservableemits connected, non-overlapping windows, each of a fixed duration specified by thetimespanargument or a maximum size specified by thecountargument (whichever is reached first). When the currentObservablecompletes or encounters an error, the resultingObservableemits the current window and propagates the notification from the currentObservable.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
timespan- the period of time each window collects items before it should be emitted and replaced with a new windowunit- the unit of time which applies to thetimespanargumentscheduler- theSchedulerto use when determining the end and start of a windowcount- the maximum size of each window before it should be emittedrestart- iftrue, when a window reaches the capacity limit, the timer is restarted as wellbufferSize- the capacity hint for the buffer in the inner windows- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifunitorschedulerisnullIllegalArgumentException- ifcountorbufferSizeis non-positive- See Also:
-
window
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull B> @NonNull Observable<Observable<T>> window(@NonNull @NonNull ObservableSource<@NonNull B> boundaryIndicator) Returns anObservablethat emits non-overlapping windows of items it collects from the currentObservablewhere the boundary of each window is determined by the items emitted from a specified boundary-governingObservableSource.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- This version of
windowdoes not operate by default on a particularScheduler.
- Type Parameters:
B- the window element type (ignored)- Parameters:
boundaryIndicator- anObservableSourcewhose emitted items close and open windows- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifboundaryIndicatorisnull- See Also:
-
window
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull B> @NonNull Observable<Observable<T>> window(@NonNull @NonNull ObservableSource<@NonNull B> boundaryIndicator, int bufferSize) Returns anObservablethat emits non-overlapping windows of items it collects from the currentObservablewhere the boundary of each window is determined by the items emitted from a specified boundary-governingObservableSource.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- This version of
windowdoes not operate by default on a particularScheduler.
- Type Parameters:
B- the window element type (ignored)- Parameters:
boundaryIndicator- anObservableSourcewhose emitted items close and open windowsbufferSize- the capacity hint for the buffer in the inner windows- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifboundaryIndicatorisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
window
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull V> @NonNull Observable<Observable<T>> window(@NonNull @NonNull ObservableSource<@NonNull U> openingIndicator, @NonNull @NonNull Function<? super @NonNull U, ? extends ObservableSource<@NonNull V>> closingIndicator) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservableemits windows that contain those items emitted by the currentObservablebetween the time when theopeningIndicatorObservableSourceemits an item and when theObservableSourcereturned byclosingIndicatoremits an item.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- This version of
windowdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the element type of the window-openingObservableSourceV- the element type of the window-closingObservableSources- Parameters:
openingIndicator- anObservableSourcethat, when it emits an item, causes another window to be createdclosingIndicator- aFunctionthat produces anObservableSourcefor every window created. When this indicatorObservableSourceemits an item, the associated window is completed- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifopeningIndicatororclosingIndicatorisnull- See Also:
-
window
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull V> @NonNull Observable<Observable<T>> window(@NonNull @NonNull ObservableSource<@NonNull U> openingIndicator, @NonNull @NonNull Function<? super @NonNull U, ? extends ObservableSource<@NonNull V>> closingIndicator, int bufferSize) Returns anObservablethat emits windows of items it collects from the currentObservable. The resultingObservableemits windows that contain those items emitted by the currentObservablebetween the time when theopeningIndicatorObservableSourceemits an item and when theObservableSourcereturned byclosingIndicatoremits an item.
Note that ignoring windows or subscribing later (i.e., on another thread) will result in so-called window abandonment where a window may not contain any elements. In this case, subsequent elements will be dropped until the condition for the next window boundary is satisfied. The behavior is a trade-off for ensuring upstream cancellation can happen under some race conditions.
- Scheduler:
- This version of
windowdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the element type of the window-openingObservableSourceV- the element type of the window-closingObservableSources- Parameters:
openingIndicator- anObservableSourcethat, when it emits an item, causes another window to be createdclosingIndicator- aFunctionthat produces anObservableSourcefor every window created. When this indicatorObservableSourceemits an item, the associated window is completedbufferSize- the capacity hint for the buffer in the inner windows- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifopeningIndicatororclosingIndicatorisnullIllegalArgumentException- ifbufferSizeis non-positive- See Also:
-
withLatestFrom
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull R> @NonNull Observable<R> withLatestFrom(@NonNull @NonNull ObservableSource<? extends @NonNull U> other, @NonNull @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> combiner) Merges the specifiedObservableSourceinto the currentObservablesequence by using theresultSelectorfunction only when the currentObservableemits an item.Note that this operator doesn't emit anything until the other source has produced at least one value. The resulting emission only happens when the current
Observableemits (and not when the other source emits, unlike combineLatest). If the other source doesn't produce any value and just completes, the sequence is completed immediately. If the upstream completes before the other source has produced at least one value, the sequence completes without emission.
- Scheduler:
- This operator, by default, doesn't run any particular
Scheduler.
- Type Parameters:
U- the element type of the otherObservableSourceR- the result type of the combination- Parameters:
other- the otherObservableSourcecombiner- the function to call when the currentObservableemits an item and the otherObservableSourcehas already emitted an item, to generate the item to be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherorcombinerisnull- Since:
- 2.0
- See Also:
-
withLatestFrom
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull T1, @NonNull T2, @NonNull R> @NonNull Observable<R> withLatestFrom(@NonNull @NonNull ObservableSource<@NonNull T1> source1, @NonNull @NonNull ObservableSource<@NonNull T2> source2, @NonNull @NonNull Function3<? super @NonNull T, ? super @NonNull T1, ? super @NonNull T2, @NonNull R> combiner) Combines the value emission from the currentObservablewith the latest emissions from the otherObservableSources via a function to produce the output item.Note that this operator doesn't emit anything until all other sources have produced at least one value. The resulting emission only happens when the current
Observableemits (and not when any of the other sources emit, unlikecombineLatest). If a source doesn't produce any value and just completes, the sequence is completed immediately. If the upstream completes before all other sources have produced at least one value, the sequence completes without emission.
- Scheduler:
- This operator does not operate by default on a particular
Scheduler.
- Type Parameters:
T1- the first other source's value typeT2- the second other source's value typeR- the result value type- Parameters:
source1- the first otherObservableSourcesource2- the second otherObservableSourcecombiner- the function called with an array of values from each participatingObservableSource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2orcombinerisnull- Since:
- 2.0
-
withLatestFrom
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull R> @NonNull Observable<R> withLatestFrom(@NonNull @NonNull ObservableSource<@NonNull T1> source1, @NonNull @NonNull ObservableSource<@NonNull T2> source2, @NonNull @NonNull ObservableSource<@NonNull T3> source3, @NonNull @NonNull Function4<? super @NonNull T, ? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, @NonNull R> combiner) Combines the value emission from the currentObservablewith the latest emissions from the otherObservableSources via a function to produce the output item.Note that this operator doesn't emit anything until all other sources have produced at least one value. The resulting emission only happens when the current
Observableemits (and not when any of the other sources emit, unlike combineLatest). If a source doesn't produce any value and just completes, the sequence is completed immediately. If the upstream completes before all other sources have produced at least one value, the sequence completes without emission.
- Scheduler:
- This operator does not operate by default on a particular
Scheduler.
- Type Parameters:
T1- the first other source's value typeT2- the second other source's value typeT3- the third other source's value typeR- the result value type- Parameters:
source1- the first otherObservableSourcesource2- the second otherObservableSourcesource3- the third otherObservableSourcecombiner- the function called with an array of values from each participatingObservableSource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3orcombinerisnull- Since:
- 2.0
-
withLatestFrom
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull R> @NonNull Observable<R> withLatestFrom(@NonNull @NonNull ObservableSource<@NonNull T1> source1, @NonNull @NonNull ObservableSource<@NonNull T2> source2, @NonNull @NonNull ObservableSource<@NonNull T3> source3, @NonNull @NonNull ObservableSource<@NonNull T4> source4, @NonNull @NonNull Function5<? super @NonNull T, ? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, @NonNull R> combiner) Combines the value emission from the currentObservablewith the latest emissions from the otherObservableSources via a function to produce the output item.Note that this operator doesn't emit anything until all other sources have produced at least one value. The resulting emission only happens when the current
Observableemits (and not when any of the other sources emit, unlike combineLatest). If a source doesn't produce any value and just completes, the sequence is completed immediately. If the upstream completes before all other sources have produced at least one value, the sequence completes without emission.
- Scheduler:
- This operator does not operate by default on a particular
Scheduler.
- Type Parameters:
T1- the first other source's value typeT2- the second other source's value typeT3- the third other source's value typeT4- the fourth other source's value typeR- the result value type- Parameters:
source1- the first otherObservableSourcesource2- the second otherObservableSourcesource3- the third otherObservableSourcesource4- the fourth otherObservableSourcecombiner- the function called with an array of values from each participatingObservableSource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsource1,source2,source3,source4orcombinerisnull- Since:
- 2.0
-
withLatestFrom
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> withLatestFrom(@NonNull @NonNull ObservableSource<?>[] others, @NonNull @NonNull Function<? super Object[], @NonNull R> combiner) Combines the value emission from the currentObservablewith the latest emissions from the otherObservableSources via a function to produce the output item.Note that this operator doesn't emit anything until all other sources have produced at least one value. The resulting emission only happens when the current
Observableemits (and not when any of the other sources emit, unlike combineLatest). If a source doesn't produce any value and just completes, the sequence is completed immediately. If the upstream completes before all other sources have produced at least one value, the sequence completes without emission.
- Scheduler:
- This operator does not operate by default on a particular
Scheduler.
- Type Parameters:
R- the result value type- Parameters:
others- the array of other sourcescombiner- the function called with an array of values from each participatingObservableSource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifothersorcombinerisnull- Since:
- 2.0
-
withLatestFrom
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> withLatestFrom(@NonNull @NonNull Iterable<@NonNull ? extends ObservableSource<?>> others, @NonNull @NonNull Function<? super Object[], @NonNull R> combiner) Combines the value emission from the currentObservablewith the latest emissions from the otherObservableSources via a function to produce the output item.Note that this operator doesn't emit anything until all other sources have produced at least one value. The resulting emission only happens when the current
Observableemits (and not when any of the other sources emit, unlikecombineLatest). If a source doesn't produce any value and just completes, the sequence is completed immediately. If the upstream completes before all other sources have produced at least one value, the sequence completes without emission.
- Scheduler:
- This operator does not operate by default on a particular
Scheduler.
- Type Parameters:
R- the result value type- Parameters:
others- the iterable of other sourcescombiner- the function called with an array of values from each participatingObservableSource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifothersorcombinerisnull- Since:
- 2.0
-
zipWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull R> @NonNull Observable<R> zipWith(@NonNull @NonNull Iterable<@NonNull U> other, @NonNull @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> zipper) Returns anObservablethat emits items that are the result of applying a specified function to pairs of values, one each from the currentObservableand a specifiedIterablesequence.
Note that the
otherIterableis evaluated as items are observed from the currentObservable; it is not pre-consumed. This allows you to zip infinite streams on either side.- Scheduler:
zipWithdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items in theotherIterableR- the type of items emitted by the resultingObservable- Parameters:
other- theIterablesequencezipper- a function that combines the pairs of items from the currentObservableand theIterableto generate the items to be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherorzipperisnull- See Also:
-
zipWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull R> @NonNull Observable<R> zipWith(@NonNull @NonNull ObservableSource<? extends @NonNull U> other, @NonNull @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> zipper) Returns anObservablethat emits items that are the result of applying a specified function to pairs of values, one each from the currentObservableand another specifiedObservableSource.
The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:range(1, 5).doOnComplete(action1).zipWith(range(6, 5).doOnComplete(action2), (a, b) -> a + b)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.- Scheduler:
zipWithdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted by theotherObservableSourceR- the type of items emitted by the resultingObservable- Parameters:
other- the otherObservableSourcezipper- a function that combines the pairs of items from the currentObservableand the otherObservableSourceto generate the items to be emitted by the resultingObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherorzipperisnull- See Also:
-
zipWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull R> @NonNull Observable<R> zipWith(@NonNull @NonNull ObservableSource<? extends @NonNull U> other, @NonNull @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> zipper, boolean delayError) Returns anObservablethat emits items that are the result of applying a specified function to pairs of values, one each from the currentObservableand another specifiedObservableSource.
The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:range(1, 5).doOnComplete(action1).zipWith(range(6, 5).doOnComplete(action2), (a, b) -> a + b)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.- Scheduler:
zipWithdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted by theotherObservableSourceR- the type of items emitted by the resultingObservable- Parameters:
other- the otherObservableSourcezipper- a function that combines the pairs of items from the currentObservableand the otherObservableSourceto generate the items to be emitted by the resultingObservabledelayError- iftrue, errors from the currentObservableor the otherObservableSourceis delayed until both terminate- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherorzipperisnull- Since:
- 2.0
- See Also:
-
zipWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull R> @NonNull Observable<R> zipWith(@NonNull @NonNull ObservableSource<? extends @NonNull U> other, @NonNull @NonNull BiFunction<? super @NonNull T, ? super @NonNull U, ? extends @NonNull R> zipper, boolean delayError, int bufferSize) Returns anObservablethat emits items that are the result of applying a specified function to pairs of values, one each from the currentObservableand another specifiedObservableSource.
The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling
doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:range(1, 5).doOnComplete(action1).zipWith(range(6, 5).doOnComplete(action2), (a, b) -> a + b)action1will be called butaction2won't.
To work around this termination property, usedoOnDispose(Action)as well or useusing()to do cleanup in case of completion or a dispose() call.- Scheduler:
zipWithdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted by theotherObservableSourceR- the type of items emitted by the resultingObservable- Parameters:
other- the otherObservableSourcezipper- a function that combines the pairs of items from the currentObservableand the otherObservableSourceto generate the items to be emitted by the resultingObservabledelayError- iftrue, errors from the currentObservableor the otherObservableSourceis delayed until both terminatebufferSize- the capacity hint for the buffer in the inner windows- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherorzipperisnullIllegalArgumentException- ifbufferSizeis non-positive- Since:
- 2.0
- See Also:
-
test
Creates aTestObserverand subscribes it to the currentObservable.- Scheduler:
testdoes not operate by default on a particularScheduler.
- Returns:
- the new
TestObserverinstance - Since:
- 2.0
-
test
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull TestObserver<T> test(boolean dispose) Creates aTestObserver, optionally disposes it and then subscribes it to the currentObservable.- Scheduler:
testdoes not operate by default on a particularScheduler.
- Parameters:
dispose- indicates if theTestObservershould be disposed before it is subscribed to the currentObservable- Returns:
- the new
TestObserverinstance - Since:
- 2.0
-
fromOptional
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<@NonNull T> fromOptional(@NonNull @NonNull Optional<@NonNull T> optional) Converts the existing value of the provided optional into ajust(Object)or an empty optional into anempty()Observableinstance.
Note that the operator takes an already instantiated optional reference and does not by any means create this original optional. If the optional is to be created per consumer upon subscription, use
defer(Supplier)aroundfromOptional:Observable.defer(() -> Observable.fromOptional(createOptional()));- Scheduler:
fromOptionaldoes not operate by default on a particularScheduler.
- Type Parameters:
T- the element type of the optional value- Parameters:
optional- the optional value to convert into anObservable- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifoptionalisnull- Since:
- 3.0.0
- See Also:
-
fromCompletionStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<@NonNull T> fromCompletionStage(@NonNull @NonNull CompletionStage<@NonNull T> stage) Signals the completion value or error of the given (hot)CompletionStage-based asynchronous calculation.
Note that the operator takes an already instantiated, running or terminated
CompletionStage. If theCompletionStageis to be created per consumer upon subscription, usedefer(Supplier)aroundfromCompletionStage:Observable.defer(() -> Observable.fromCompletionStage(createCompletionStage()));If the
CompletionStagecompletes withnull, aNullPointerExceptionis signaled.Canceling the flow can't cancel the execution of the
CompletionStagebecauseCompletionStageitself doesn't support cancellation. Instead, the operator detaches from theCompletionStage.- Scheduler:
fromCompletionStagedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the element type of theCompletionStage- Parameters:
stage- theCompletionStageto convert toObservableand signal its terminal value or error- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifstageisnull- Since:
- 3.0.0
-
fromStream
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Observable<@NonNull T> fromStream(@NonNull @NonNull Stream<@NonNull T> stream) Converts aStreaminto a finiteObservableand emits its items in the sequence.
The operator closes the
Streamupon cancellation and when it terminates. The exceptions raised when closing aStreamare routed to the global error handler (RxJavaPlugins.onError(Throwable). If aStreamshould not be closed, turn it into anIterableand usefromIterable(Iterable):Stream<T> stream = ... Observable.fromIterable(stream::iterator);Note that
Streams can be consumed only once; any subsequent attempt to consume aStreamwill result in anIllegalStateException.Primitive streams are not supported and items have to be boxed manually (e.g., via
IntStream.boxed()):IntStream intStream = IntStream.rangeClosed(1, 10); Observable.fromStream(intStream.boxed());Streamdoes not support concurrent usage so creating and/or consuming the same instance multiple times from multiple threads can lead to undefined behavior.- Scheduler:
fromStreamdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the element type of the sourceStream- Parameters:
stream- theStreamof values to emit- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifstreamisnull- Since:
- 3.0.0
- See Also:
-
mapOptional
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> mapOptional(@NonNull @NonNull Function<? super @NonNull T, @NonNull Optional<? extends @NonNull R>> mapper) Maps each upstream value into anOptionaland emits the contained item if not empty.
- Scheduler:
mapOptionaldoes not operate by default on a particularScheduler.
- Type Parameters:
R- the non-nulloutput type- Parameters:
mapper- the function that receives the upstream item and should return a non-emptyOptionalto emit as the output or an emptyOptionalto skip to the next upstream value- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-
collect
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R, @Nullable A> @NonNull Single<R> collect(@NonNull @NonNull Collector<? super @NonNull T, @Nullable A, @NonNull R> collector) Collects the finite upstream's values into a container via aStreamCollectorcallback set and emits it as the success result as aSingle.
- Scheduler:
collectdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the non-nullresult typeA- the intermediate container type used for the accumulation- Parameters:
collector- the interface defining the container supplier, accumulator and finisher functions; seeCollectorsfor some standard implementations- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifcollectorisnull- Since:
- 3.0.0
- See Also:
-
firstStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull CompletionStage<T> firstStage(@Nullable @NonNull T defaultItem) Signals the first upstream item (or the default item if the upstream is empty) via aCompletionStage.
The upstream can be canceled by converting the resulting
CompletionStageintoCompletableFutureviaCompletionStage.toCompletableFuture()and callingCompletableFuture.cancel(boolean)on it. The upstream will be also cancelled if the resultingCompletionStageis converted to and completed manually byCompletableFuture.complete(Object)orCompletableFuture.completeExceptionally(Throwable).CompletionStages don't have a notion of emptiness and allownulls, therefore, one can either use adefaultItemofnullor turn the flow into a sequence ofOptionals and default toOptional.empty():CompletionStage<Optional<T>> stage = source.map(Optional::of).firstStage(Optional.empty());- Scheduler:
firstStagedoes not operate by default on a particularScheduler.
- Parameters:
defaultItem- the item to signal if the upstream is empty- Returns:
- the new
CompletionStageinstance - Throws:
NullPointerException- ifdefaultItemisnull- Since:
- 3.0.0
- See Also:
-
singleStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull CompletionStage<T> singleStage(@Nullable @NonNull T defaultItem) Signals the only expected upstream item (or the default item if the upstream is empty) or signalsIllegalArgumentExceptionif the upstream has more than one item via aCompletionStage.
The upstream can be canceled by converting the resulting
CompletionStageintoCompletableFutureviaCompletionStage.toCompletableFuture()and callingCompletableFuture.cancel(boolean)on it. The upstream will be also cancelled if the resultingCompletionStageis converted to and completed manually byCompletableFuture.complete(Object)orCompletableFuture.completeExceptionally(Throwable).CompletionStages don't have a notion of emptiness and allownulls, therefore, one can either use adefaultItemofnullor turn the flow into a sequence ofOptionals and default toOptional.empty():CompletionStage<Optional<T>> stage = source.map(Optional::of).singleStage(Optional.empty());- Scheduler:
singleStagedoes not operate by default on a particularScheduler.
- Parameters:
defaultItem- the item to signal if the upstream is empty- Returns:
- the new
CompletionStageinstance - Throws:
NullPointerException- ifdefaultItemisnull- Since:
- 3.0.0
- See Also:
-
lastStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull CompletionStage<T> lastStage(@Nullable @NonNull T defaultItem) Signals the last upstream item (or the default item if the upstream is empty) via aCompletionStage.
The upstream can be canceled by converting the resulting
CompletionStageintoCompletableFutureviaCompletionStage.toCompletableFuture()and callingCompletableFuture.cancel(boolean)on it. The upstream will be also cancelled if the resultingCompletionStageis converted to and completed manually byCompletableFuture.complete(Object)orCompletableFuture.completeExceptionally(Throwable).CompletionStages don't have a notion of emptiness and allownulls, therefore, one can either use adefaultItemofnullor turn the flow into a sequence ofOptionals and default toOptional.empty():CompletionStage<Optional<T>> stage = source.map(Optional::of).lastStage(Optional.empty());- Scheduler:
lastStagedoes not operate by default on a particularScheduler.
- Parameters:
defaultItem- the item to signal if the upstream is empty- Returns:
- the new
CompletionStageinstance - Throws:
NullPointerException- ifdefaultItemisnull- Since:
- 3.0.0
- See Also:
-
firstOrErrorStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull CompletionStage<T> firstOrErrorStage()Signals the first upstream item or aNoSuchElementExceptionif the upstream is empty via aCompletionStage.
The upstream can be canceled by converting the resulting
CompletionStageintoCompletableFutureviaCompletionStage.toCompletableFuture()and callingCompletableFuture.cancel(boolean)on it. The upstream will be also cancelled if the resultingCompletionStageis converted to and completed manually byCompletableFuture.complete(Object)orCompletableFuture.completeExceptionally(Throwable).- Scheduler:
firstOrErrorStagedoes not operate by default on a particularScheduler.
- Returns:
- the new
CompletionStageinstance - Since:
- 3.0.0
- See Also:
-
singleOrErrorStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull CompletionStage<T> singleOrErrorStage()Signals the only expected upstream item, aNoSuchElementExceptionif the upstream is empty or signalsIllegalArgumentExceptionif the upstream has more than one item via aCompletionStage.
The upstream can be canceled by converting the resulting
CompletionStageintoCompletableFutureviaCompletionStage.toCompletableFuture()and callingCompletableFuture.cancel(boolean)on it. The upstream will be also cancelled if the resultingCompletionStageis converted to and completed manually byCompletableFuture.complete(Object)orCompletableFuture.completeExceptionally(Throwable).- Scheduler:
singleOrErrorStagedoes not operate by default on a particularScheduler.
- Returns:
- the new
CompletionStageinstance - Since:
- 3.0.0
- See Also:
-
lastOrErrorStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull CompletionStage<T> lastOrErrorStage()Signals the last upstream item or aNoSuchElementExceptionif the upstream is empty via aCompletionStage.
The upstream can be canceled by converting the resulting
CompletionStageintoCompletableFutureviaCompletionStage.toCompletableFuture()and callingCompletableFuture.cancel(boolean)on it. The upstream will be also cancelled if the resultingCompletionStageis converted to and completed manually byCompletableFuture.complete(Object)orCompletableFuture.completeExceptionally(Throwable).- Scheduler:
lastOrErrorStagedoes not operate by default on a particularScheduler.
- Returns:
- the new
CompletionStageinstance - Since:
- 3.0.0
- See Also:
-
blockingStream
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Stream<T> blockingStream()Creates a sequentialStreamto consume or process the currentObservablein a blocking manner via the JavaStreamAPI.
Cancellation of the upstream is done via
BaseStream.close(), therefore, it is strongly recommended the consumption is performed within a try-with-resources construct:Observable<Integer> source = Observable.range(1, 10) .subscribeOn(Schedulers.computation()); try (Stream<Integer> stream = source.blockingStream()) { stream.limit(3).forEach(System.out::println); }- Scheduler:
blockingStreamdoes not operate by default on a particularScheduler.
- Returns:
- the new
Streaminstance - Since:
- 3.0.0
- See Also:
-
blockingStream
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Stream<T> blockingStream(int capacityHint) Creates a sequentialStreamto consume or process the currentObservablein a blocking manner via the JavaStreamAPI.
Cancellation of the upstream is done via
BaseStream.close(), therefore, it is strongly recommended the consumption is performed within a try-with-resources construct:Observable<Integer> source = Observable.range(1, 10) .subscribeOn(Schedulers.computation()); try (Stream<Integer> stream = source.blockingStream(4)) { stream.limit(3).forEach(System.out::println); }- Scheduler:
blockingStreamdoes not operate by default on a particularScheduler.
- Parameters:
capacityHint- the expected number of items to be buffered- Returns:
- the new
Streaminstance - Throws:
IllegalArgumentException- ifcapacityHintis non-positive- Since:
- 3.0.0
-
concatMapStream
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> concatMapStream(@NonNull @NonNull Function<? super @NonNull T, @NonNull ? extends Stream<? extends @NonNull R>> mapper) Maps each upstream item into aStreamand emits theStream's items to the downstream in a sequential fashion.
Due to the blocking and sequential nature of Java
Streams, the streams are mapped and consumed in a sequential fashion without interleaving (unlike a more generalflatMap(Function)). Therefore,flatMapStreamandconcatMapStreamare identical operators and are provided as aliases.The operator closes the
Streamupon cancellation and when it terminates. The exceptions raised when closing aStreamare routed to the global error handler (RxJavaPlugins.onError(Throwable). If aStreamshould not be closed, turn it into anIterableand useconcatMapIterable(Function):source.concatMapIterable(v -> createStream(v)::iterator);Note that
Streams can be consumed only once; any subsequent attempt to consume aStreamwill result in anIllegalStateException.Primitive streams are not supported and items have to be boxed manually (e.g., via
IntStream.boxed()):source.concatMapStream(v -> IntStream.rangeClosed(v + 1, v + 10).boxed());Streamdoes not support concurrent usage so creating and/or consuming the same instance multiple times from multiple threads can lead to undefined behavior.- Scheduler:
concatMapStreamdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the element type of theStreams and the result- Parameters:
mapper- the function that receives an upstream item and should return aStreamwhose elements will be emitted to the downstream- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-
flatMapStream
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flatMapStream(@NonNull @NonNull Function<? super @NonNull T, @NonNull ? extends Stream<? extends @NonNull R>> mapper) Maps each upstream item into aStreamand emits theStream's items to the downstream in a sequential fashion.
Due to the blocking and sequential nature of Java
Streams, the streams are mapped and consumed in a sequential fashion without interleaving (unlike a more generalflatMap(Function)). Therefore,flatMapStreamandconcatMapStreamare identical operators and are provided as aliases.The operator closes the
Streamupon cancellation and when it terminates. The exceptions raised when closing aStreamare routed to the global error handler (RxJavaPlugins.onError(Throwable). If aStreamshould not be closed, turn it into anIterableand useflatMapIterable(Function):source.flatMapIterable(v -> createStream(v)::iterator);Note that
Streams can be consumed only once; any subsequent attempt to consume aStreamwill result in anIllegalStateException.Primitive streams are not supported and items have to be boxed manually (e.g., via
IntStream.boxed()):source.flatMapStream(v -> IntStream.rangeClosed(v + 1, v + 10).boxed());Streamdoes not support concurrent usage so creating and/or consuming the same instance multiple times from multiple threads can lead to undefined behavior.- Scheduler:
flatMapStreamdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the element type of theStreams and the result- Parameters:
mapper- the function that receives an upstream item and should return aStreamwhose elements will be emitted to the downstream- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-