All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.reactivex.Observable Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2016-present, RxJava Contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
 * the License for the specific language governing permissions and limitations under the License.
 */

package io.reactivex;

import java.util.*;
import java.util.concurrent.*;

import org.reactivestreams.Publisher;

import io.reactivex.annotations.*;
import io.reactivex.disposables.Disposable;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.functions.*;
import io.reactivex.internal.functions.*;
import io.reactivex.internal.fuseable.ScalarCallable;
import io.reactivex.internal.observers.*;
import io.reactivex.internal.operators.flowable.*;
import io.reactivex.internal.operators.mixed.*;
import io.reactivex.internal.operators.observable.*;
import io.reactivex.internal.util.*;
import io.reactivex.observables.*;
import io.reactivex.observers.*;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.*;

/**
 * The Observable class is the non-backpressured, optionally multi-valued base reactive class that
 * offers factory methods, intermediate operators and the ability to consume synchronous
 * and/or asynchronous reactive dataflows.
 * 

* Many operators in the class accept {@code ObservableSource}(s), the base reactive interface * for such non-backpressured flows, which {@code Observable} itself implements as well. *

* The Observable's operators, by default, run with a buffer size of 128 elements (see {@link Flowable#bufferSize()}), * that can be overridden globally via the system parameter {@code rx2.buffer-size}. Most operators, however, have * overloads that allow setting their internal buffer size explicitly. *

* The documentation for this class makes use of marble diagrams. The following legend explains these diagrams: *

* *

* The design of this class was derived from the * Reactive Streams design and specification * by removing any backpressure-related infrastructure and implementation detail, replacing the * {@code org.reactivestreams.Subscription} with {@link Disposable} as the primary means to dispose of * a flow. *

* The {@code Observable} follows the protocol *


 *      onSubscribe onNext* (onError | onComplete)?
 * 
* where * the stream can be disposed through the {@code Disposable} instance provided to consumers through * {@code Observer.onSubscribe}. *

* Unlike the {@code Observable} of version 1.x, {@link #subscribe(Observer)} does not allow external disposal * of a subscription and the {@code Observer} instance is expected to expose such capability. *

Example: *


 * Disposable d = Observable.just("Hello world!")
 *     .delay(1, TimeUnit.SECONDS)
 *     .subscribeWith(new DisposableObserver<String>() {
 *         @Override public void onStart() {
 *             System.out.println("Start!");
 *         }
 *         @Override public void onNext(String t) {
 *             System.out.println(t);
 *         }
 *         @Override public void onError(Throwable t) {
 *             t.printStackTrace();
 *         }
 *         @Override public void onComplete() {
 *             System.out.println("Done!");
 *         }
 *     });
 *
 * Thread.sleep(500);
 * // the sequence can now be disposed via dispose()
 * d.dispose();
 * 
* * @param * the type of the items emitted by the Observable * @see Flowable * @see io.reactivex.observers.DisposableObserver */ public abstract class Observable implements ObservableSource { /** * Mirrors the one ObservableSource in an Iterable of several ObservableSources that first either emits an item or sends * a termination notification. *

* *

*
Scheduler:
*
{@code amb} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element type * @param sources * an Iterable of ObservableSource sources competing to react first. A subscription to each source will * occur in the same order as in the Iterable. * @return an Observable that emits the same sequence as whichever of the source ObservableSources first * emitted an item or sent a termination notification * @see ReactiveX operators documentation: Amb */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable amb(Iterable> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); return RxJavaPlugins.onAssembly(new ObservableAmb(null, sources)); } /** * Mirrors the one ObservableSource in an array of several ObservableSources that first either emits an item or sends * a termination notification. *

* *

*
Scheduler:
*
{@code ambArray} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element type * @param sources * an array of ObservableSource sources competing to react first. A subscription to each source will * occur in the same order as in the array. * @return an Observable that emits the same sequence as whichever of the source ObservableSources first * emitted an item or sent a termination notification * @see ReactiveX operators documentation: Amb */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable ambArray(ObservableSource... sources) { ObjectHelper.requireNonNull(sources, "sources is null"); int len = sources.length; if (len == 0) { return empty(); } if (len == 1) { return (Observable)wrap(sources[0]); } return RxJavaPlugins.onAssembly(new ObservableAmb(sources, null)); } /** * Returns the default 'island' size or capacity-increment hint for unbounded buffers. *

Delegates to {@link Flowable#bufferSize} but is public for convenience. *

The value can be overridden via system parameter {@code rx2.buffer-size} * before the {@link Flowable} class is loaded. * @return the default 'island' size or capacity-increment hint */ public static int bufferSize() { return Flowable.bufferSize(); } /** * Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of * the source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function. *

* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* If there are no ObservableSources provided, the resulting sequence completes immediately without emitting * any items and without any calls to the combiner function. * *

* *

*
Scheduler:
*
{@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the common base type of source values * @param * the result type * @param sources * the collection of source ObservableSources * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @param bufferSize * the internal buffer size and prefetch amount applied to every source Observable * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest(Function combiner, int bufferSize, ObservableSource... sources) { return combineLatest(sources, combiner, bufferSize); } /** * Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of * the source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function. *

* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* If the provided iterable of ObservableSources is empty, the resulting sequence completes immediately without emitting * any items and without any calls to the combiner function. * *

* *

*
Scheduler:
*
{@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the common base type of source values * @param * the result type * @param sources * the collection of source ObservableSources * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest(Iterable> sources, Function combiner) { return combineLatest(sources, combiner, bufferSize()); } /** * Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of * the source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function. *

* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* If the provided iterable of ObservableSources is empty, the resulting sequence completes immediately without emitting * any items and without any calls to the combiner function. * *

* *

*
Scheduler:
*
{@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the common base type of source values * @param * the result type * @param sources * the collection of source ObservableSources * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @param bufferSize * the internal buffer size and prefetch amount applied to every source Observable * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest(Iterable> sources, Function combiner, int bufferSize) { ObjectHelper.requireNonNull(sources, "sources is null"); ObjectHelper.requireNonNull(combiner, "combiner is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); // the queue holds a pair of values so we need to double the capacity int s = bufferSize << 1; return RxJavaPlugins.onAssembly(new ObservableCombineLatest(null, sources, combiner, s, false)); } /** * Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of * the source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function. *

* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* If the provided array of ObservableSources is empty, the resulting sequence completes immediately without emitting * any items and without any calls to the combiner function. * *

* *

*
Scheduler:
*
{@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the common base type of source values * @param * the result type * @param sources * the collection of source ObservableSources * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest(ObservableSource[] sources, Function combiner) { return combineLatest(sources, combiner, bufferSize()); } /** * Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of * the source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function. *

* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* If the provided array of ObservableSources is empty, the resulting sequence completes immediately without emitting * any items and without any calls to the combiner function. * *

* *

*
Scheduler:
*
{@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the common base type of source values * @param * the result type * @param sources * the collection of source ObservableSources * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @param bufferSize * the internal buffer size and prefetch amount applied to every source Observable * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest(ObservableSource[] sources, Function combiner, int bufferSize) { ObjectHelper.requireNonNull(sources, "sources is null"); if (sources.length == 0) { return empty(); } ObjectHelper.requireNonNull(combiner, "combiner is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); // the queue holds a pair of values so we need to double the capacity int s = bufferSize << 1; return RxJavaPlugins.onAssembly(new ObservableCombineLatest(sources, null, combiner, s, false)); } /** * Combines two source ObservableSources by emitting an item that aggregates the latest values of each of the * source ObservableSources each time an item is received from either of the source ObservableSources, where this * aggregation is defined by a specified function. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* *

*
Scheduler:
*
{@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the first source * @param the element type of the second source * @param the combined output type * @param source1 * the first source ObservableSource * @param source2 * the second source ObservableSource * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, BiFunction combiner) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2); } /** * Combines three source ObservableSources by emitting an item that aggregates the latest values of each of the * source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* *

*
Scheduler:
*
{@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the first source * @param the element type of the second source * @param the element type of the third source * @param the combined output type * @param source1 * the first source ObservableSource * @param source2 * the second source ObservableSource * @param source3 * the third source ObservableSource * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, ObservableSource source3, Function3 combiner) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3); } /** * Combines four source ObservableSources by emitting an item that aggregates the latest values of each of the * source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* *

*
Scheduler:
*
{@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the first source * @param the element type of the second source * @param the element type of the third source * @param the element type of the fourth source * @param the combined output type * @param source1 * the first source ObservableSource * @param source2 * the second source ObservableSource * @param source3 * the third source ObservableSource * @param source4 * the fourth source ObservableSource * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4, Function4 combiner) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4); } /** * Combines five source ObservableSources by emitting an item that aggregates the latest values of each of the * source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* *

*
Scheduler:
*
{@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the first source * @param the element type of the second source * @param the element type of the third source * @param the element type of the fourth source * @param the element type of the fifth source * @param the combined output type * @param source1 * the first source ObservableSource * @param source2 * the second source ObservableSource * @param source3 * the third source ObservableSource * @param source4 * the fourth source ObservableSource * @param source5 * the fifth source ObservableSource * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4, ObservableSource source5, Function5 combiner) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5); } /** * Combines six source ObservableSources by emitting an item that aggregates the latest values of each of the * source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* *

*
Scheduler:
*
{@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the first source * @param the element type of the second source * @param the element type of the third source * @param the element type of the fourth source * @param the element type of the fifth source * @param the element type of the sixth source * @param the combined output type * @param source1 * the first source ObservableSource * @param source2 * the second source ObservableSource * @param source3 * the third source ObservableSource * @param source4 * the fourth source ObservableSource * @param source5 * the fifth source ObservableSource * @param source6 * the sixth source ObservableSource * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4, ObservableSource source5, ObservableSource source6, Function6 combiner) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); ObjectHelper.requireNonNull(source6, "source6 is null"); return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5, source6); } /** * Combines seven source ObservableSources by emitting an item that aggregates the latest values of each of the * source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* *

*
Scheduler:
*
{@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the first source * @param the element type of the second source * @param the element type of the third source * @param the element type of the fourth source * @param the element type of the fifth source * @param the element type of the sixth source * @param the element type of the seventh source * @param the combined output type * @param source1 * the first source ObservableSource * @param source2 * the second source ObservableSource * @param source3 * the third source ObservableSource * @param source4 * the fourth source ObservableSource * @param source5 * the fifth source ObservableSource * @param source6 * the sixth source ObservableSource * @param source7 * the seventh source ObservableSource * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4, ObservableSource source5, ObservableSource source6, ObservableSource source7, Function7 combiner) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); ObjectHelper.requireNonNull(source6, "source6 is null"); ObjectHelper.requireNonNull(source7, "source7 is null"); return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5, source6, source7); } /** * Combines eight source ObservableSources by emitting an item that aggregates the latest values of each of the * source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* *

*
Scheduler:
*
{@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the first source * @param the element type of the second source * @param the element type of the third source * @param the element type of the fourth source * @param the element type of the fifth source * @param the element type of the sixth source * @param the element type of the seventh source * @param the element type of the eighth source * @param the combined output type * @param source1 * the first source ObservableSource * @param source2 * the second source ObservableSource * @param source3 * the third source ObservableSource * @param source4 * the fourth source ObservableSource * @param source5 * the fifth source ObservableSource * @param source6 * the sixth source ObservableSource * @param source7 * the seventh source ObservableSource * @param source8 * the eighth source ObservableSource * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4, ObservableSource source5, ObservableSource source6, ObservableSource source7, ObservableSource source8, Function8 combiner) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); ObjectHelper.requireNonNull(source6, "source6 is null"); ObjectHelper.requireNonNull(source7, "source7 is null"); ObjectHelper.requireNonNull(source8, "source8 is null"); return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5, source6, source7, source8); } /** * Combines nine source ObservableSources by emitting an item that aggregates the latest values of each of the * source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* *

*
Scheduler:
*
{@code combineLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the first source * @param the element type of the second source * @param the element type of the third source * @param the element type of the fourth source * @param the element type of the fifth source * @param the element type of the sixth source * @param the element type of the seventh source * @param the element type of the eighth source * @param the element type of the ninth source * @param the combined output type * @param source1 * the first source ObservableSource * @param source2 * the second source ObservableSource * @param source3 * the third source ObservableSource * @param source4 * the fourth source ObservableSource * @param source5 * the fifth source ObservableSource * @param source6 * the sixth source ObservableSource * @param source7 * the seventh source ObservableSource * @param source8 * the eighth source ObservableSource * @param source9 * the ninth source ObservableSource * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatest( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4, ObservableSource source5, ObservableSource source6, ObservableSource source7, ObservableSource source8, ObservableSource source9, Function9 combiner) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); ObjectHelper.requireNonNull(source6, "source6 is null"); ObjectHelper.requireNonNull(source7, "source7 is null"); ObjectHelper.requireNonNull(source8, "source8 is null"); ObjectHelper.requireNonNull(source9, "source9 is null"); return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2, source3, source4, source5, source6, source7, source8, source9); } /** * Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of * the source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function. *

* *

* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* If the provided array of ObservableSources is empty, the resulting sequence completes immediately without emitting * any items and without any calls to the combiner function. * *

*
Scheduler:
*
{@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the common base type of source values * @param * the result type * @param sources * the collection of source ObservableSources * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatestDelayError(ObservableSource[] sources, Function combiner) { return combineLatestDelayError(sources, combiner, bufferSize()); } /** * Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of * the source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function and delays any error from the sources until * all source ObservableSources terminate. *

* *

* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* If there are no ObservableSources provided, the resulting sequence completes immediately without emitting * any items and without any calls to the combiner function. * *

*
Scheduler:
*
{@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the common base type of source values * @param * the result type * @param sources * the collection of source ObservableSources * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @param bufferSize * the internal buffer size and prefetch amount applied to every source Observable * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatestDelayError(Function combiner, int bufferSize, ObservableSource... sources) { return combineLatestDelayError(sources, combiner, bufferSize); } /** * Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of * the source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function and delays any error from the sources until * all source ObservableSources terminate. *

* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* If the provided array of ObservableSources is empty, the resulting sequence completes immediately without emitting * any items and without any calls to the combiner function. * *

* *

*
Scheduler:
*
{@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the common base type of source values * @param * the result type * @param sources * the collection of source ObservableSources * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @param bufferSize * the internal buffer size and prefetch amount applied to every source Observable * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatestDelayError(ObservableSource[] sources, Function combiner, int bufferSize) { ObjectHelper.verifyPositive(bufferSize, "bufferSize"); ObjectHelper.requireNonNull(combiner, "combiner is null"); if (sources.length == 0) { return empty(); } // the queue holds a pair of values so we need to double the capacity int s = bufferSize << 1; return RxJavaPlugins.onAssembly(new ObservableCombineLatest(sources, null, combiner, s, true)); } /** * Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of * the source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function and delays any error from the sources until * all source ObservableSources terminate. *

* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* If the provided iterable of ObservableSources is empty, the resulting sequence completes immediately without emitting * any items and without any calls to the combiner function. * *

* *

*
Scheduler:
*
{@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the common base type of source values * @param * the result type * @param sources * the collection of source ObservableSources * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatestDelayError(Iterable> sources, Function combiner) { return combineLatestDelayError(sources, combiner, bufferSize()); } /** * Combines a collection of source ObservableSources by emitting an item that aggregates the latest values of each of * the source ObservableSources each time an item is received from any of the source ObservableSources, where this * aggregation is defined by a specified function and delays any error from the sources until * all source ObservableSources terminate. *

* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. *

* If any of the sources never produces an item but only terminates (normally or with an error), the * resulting sequence terminates immediately (normally or with all the errors accumulated till that point). * If that input source is also synchronous, other sources after it will not be subscribed to. *

* If the provided iterable of ObservableSources is empty, the resulting sequence completes immediately without emitting * any items and without any calls to the combiner function. * *

* *

*
Scheduler:
*
{@code combineLatestDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the common base type of source values * @param * the result type * @param sources * the collection of source ObservableSources * @param combiner * the aggregation function used to combine the items emitted by the source ObservableSources * @param bufferSize * the internal buffer size and prefetch amount applied to every source Observable * @return an Observable that emits items that are the result of combining the items emitted by the source * ObservableSources by means of the given aggregation function * @see ReactiveX operators documentation: CombineLatest */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable combineLatestDelayError(Iterable> sources, Function combiner, int bufferSize) { ObjectHelper.requireNonNull(sources, "sources is null"); ObjectHelper.requireNonNull(combiner, "combiner is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); // the queue holds a pair of values so we need to double the capacity int s = bufferSize << 1; return RxJavaPlugins.onAssembly(new ObservableCombineLatest(null, sources, combiner, s, true)); } /** * Concatenates elements of each ObservableSource provided via an Iterable sequence into a single sequence * of elements without interleaving them. *

* *

*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
*
* @param the common value type of the sources * @param sources the Iterable sequence of ObservableSources * @return the new Observable instance */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable concat(Iterable> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); return fromIterable(sources).concatMapDelayError((Function)Functions.identity(), bufferSize(), false); } /** * Returns an Observable that emits the items emitted by each of the ObservableSources emitted by the source * ObservableSource, one after the other, without interleaving them. *

* *

*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources * an ObservableSource that emits ObservableSources * @return an Observable that emits items all of the items emitted by the ObservableSources emitted by * {@code ObservableSources}, one after the other, without interleaving them * @see ReactiveX operators documentation: Concat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concat(ObservableSource> sources) { return concat(sources, bufferSize()); } /** * Returns an Observable that emits the items emitted by each of the ObservableSources emitted by the source * ObservableSource, one after the other, without interleaving them. *

* *

*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources * an ObservableSource that emits ObservableSources * @param prefetch * the number of ObservableSources to prefetch from the sources sequence. * @return an Observable that emits items all of the items emitted by the ObservableSources emitted by * {@code ObservableSources}, one after the other, without interleaving them * @see ReactiveX operators documentation: Concat */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable concat(ObservableSource> sources, int prefetch) { ObjectHelper.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); return RxJavaPlugins.onAssembly(new ObservableConcatMap(sources, Functions.identity(), prefetch, ErrorMode.IMMEDIATE)); } /** * Returns an Observable that emits the items emitted by two ObservableSources, one after the other, without * interleaving them. *

* *

*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param source1 * an ObservableSource to be concatenated * @param source2 * an ObservableSource to be concatenated * @return an Observable that emits items emitted by the two source ObservableSources, one after the other, * without interleaving them * @see ReactiveX operators documentation: Concat */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable concat(ObservableSource source1, ObservableSource source2) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); return concatArray(source1, source2); } /** * Returns an Observable that emits the items emitted by three ObservableSources, one after the other, without * interleaving them. *

* *

*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param source1 * an ObservableSource to be concatenated * @param source2 * an ObservableSource to be concatenated * @param source3 * an ObservableSource to be concatenated * @return an Observable that emits items emitted by the three source ObservableSources, one after the other, * without interleaving them * @see ReactiveX operators documentation: Concat */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable concat( ObservableSource source1, ObservableSource source2, ObservableSource source3) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); return concatArray(source1, source2, source3); } /** * Returns an Observable that emits the items emitted by four ObservableSources, one after the other, without * interleaving them. *

* *

*
Scheduler:
*
{@code concat} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param source1 * an ObservableSource to be concatenated * @param source2 * an ObservableSource to be concatenated * @param source3 * an ObservableSource to be concatenated * @param source4 * an ObservableSource to be concatenated * @return an Observable that emits items emitted by the four source ObservableSources, one after the other, * without interleaving them * @see ReactiveX operators documentation: Concat */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable concat( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); return concatArray(source1, source2, source3, source4); } /** * Concatenates a variable number of ObservableSource sources. *

* Note: named this way because of overload conflict with concat(ObservableSource<ObservableSource>) *

* *

*
Scheduler:
*
{@code concatArray} does not operate by default on a particular {@link Scheduler}.
*
* @param sources the array of sources * @param the common base value type * @return the new Observable instance * @throws NullPointerException if sources is null */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatArray(ObservableSource... sources) { if (sources.length == 0) { return empty(); } if (sources.length == 1) { return wrap((ObservableSource)sources[0]); } return RxJavaPlugins.onAssembly(new ObservableConcatMap(fromArray(sources), Functions.identity(), bufferSize(), ErrorMode.BOUNDARY)); } /** * Concatenates a variable number of ObservableSource sources and delays errors from any of them * till all terminate. *

* *

*
Scheduler:
*
{@code concatArrayDelayError} does not operate by default on a particular {@link Scheduler}.
*
* @param sources the array of sources * @param the common base value type * @return the new Observable instance * @throws NullPointerException if sources is null */ @SuppressWarnings({ "unchecked" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatArrayDelayError(ObservableSource... sources) { if (sources.length == 0) { return empty(); } if (sources.length == 1) { return (Observable)wrap(sources[0]); } return concatDelayError(fromArray(sources)); } /** * Concatenates an array of ObservableSources eagerly into a single stream of values. *

* *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them * in order, each one after the previous one completes. *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources an array of ObservableSources that need to be eagerly concatenated * @return the new ObservableSource instance with the specified concatenation behavior * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatArrayEager(ObservableSource... sources) { return concatArrayEager(bufferSize(), bufferSize(), sources); } /** * Concatenates an array of ObservableSources eagerly into a single stream of values. *

* *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them * in order, each one after the previous one completes. *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources an array of ObservableSources that need to be eagerly concatenated * @param maxConcurrency the maximum number of concurrent subscriptions at a time, Integer.MAX_VALUE * is interpreted as indication to subscribe to all sources at once * @param prefetch the number of elements to prefetch from each ObservableSource source * @return the new ObservableSource instance with the specified concatenation behavior * @since 2.0 */ @SuppressWarnings({ "rawtypes", "unchecked" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatArrayEager(int maxConcurrency, int prefetch, ObservableSource... sources) { return fromArray(sources).concatMapEagerDelayError((Function)Functions.identity(), maxConcurrency, prefetch, false); } /** * Concatenates an array of {@link ObservableSource}s eagerly into a single stream of values * and delaying any errors until all sources terminate. *

* *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source {@code ObservableSource}s. The operator buffers the values emitted by these {@code ObservableSource}s * and then drains them in order, each one after the previous one completes. *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources an array of {@code ObservableSource}s that need to be eagerly concatenated * @return the new Observable instance with the specified concatenation behavior * @since 2.2.1 - experimental */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatArrayEagerDelayError(ObservableSource... sources) { return concatArrayEagerDelayError(bufferSize(), bufferSize(), sources); } /** * Concatenates an array of {@link ObservableSource}s eagerly into a single stream of values * and delaying any errors until all sources terminate. *

* *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source {@code ObservableSource}s. The operator buffers the values emitted by these {@code ObservableSource}s * and then drains them in order, each one after the previous one completes. *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources an array of {@code ObservableSource}s that need to be eagerly concatenated * @param maxConcurrency the maximum number of concurrent subscriptions at a time, Integer.MAX_VALUE * is interpreted as indication to subscribe to all sources at once * @param prefetch the number of elements to prefetch from each {@code ObservableSource} source * @return the new Observable instance with the specified concatenation behavior * @since 2.2.1 - experimental */ @SuppressWarnings({ "rawtypes", "unchecked" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatArrayEagerDelayError(int maxConcurrency, int prefetch, ObservableSource... sources) { return fromArray(sources).concatMapEagerDelayError((Function)Functions.identity(), maxConcurrency, prefetch, true); } /** * Concatenates the Iterable sequence of ObservableSources into a single sequence by subscribing to each ObservableSource, * one after the other, one at a time and delays any errors till the all inner ObservableSources terminate. *

* *

*
Scheduler:
*
{@code concatDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources the Iterable sequence of ObservableSources * @return the new ObservableSource with the concatenating behavior */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatDelayError(Iterable> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); return concatDelayError(fromIterable(sources)); } /** * Concatenates the ObservableSource sequence of ObservableSources into a single sequence by subscribing to each inner ObservableSource, * one after the other, one at a time and delays any errors till the all inner and the outer ObservableSources terminate. *

* *

*
Scheduler:
*
{@code concatDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources the ObservableSource sequence of ObservableSources * @return the new ObservableSource with the concatenating behavior */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatDelayError(ObservableSource> sources) { return concatDelayError(sources, bufferSize(), true); } /** * Concatenates the ObservableSource sequence of ObservableSources into a single sequence by subscribing to each inner ObservableSource, * one after the other, one at a time and delays any errors till the all inner and the outer ObservableSources terminate. *

* *

*
Scheduler:
*
{@code concatDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources the ObservableSource sequence of ObservableSources * @param prefetch the number of elements to prefetch from the outer ObservableSource * @param tillTheEnd if true exceptions from the outer and all inner ObservableSources are delayed to the end * if false, exception from the outer ObservableSource is delayed till the current ObservableSource terminates * @return the new ObservableSource with the concatenating behavior */ @SuppressWarnings({ "rawtypes", "unchecked" }) @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatDelayError(ObservableSource> sources, int prefetch, boolean tillTheEnd) { ObjectHelper.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(prefetch, "prefetch is null"); return RxJavaPlugins.onAssembly(new ObservableConcatMap(sources, Functions.identity(), prefetch, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY)); } /** * Concatenates an ObservableSource sequence of ObservableSources eagerly into a single stream of values. *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * emitted source ObservableSources as they are observed. The operator buffers the values emitted by these * ObservableSources and then drains them in order, each one after the previous one completes. *

* *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources a sequence of ObservableSources that need to be eagerly concatenated * @return the new ObservableSource instance with the specified concatenation behavior * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatEager(ObservableSource> sources) { return concatEager(sources, bufferSize(), bufferSize()); } /** * Concatenates an ObservableSource sequence of ObservableSources eagerly into a single stream of values. *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * emitted source ObservableSources as they are observed. The operator buffers the values emitted by these * ObservableSources and then drains them in order, each one after the previous one completes. *

* *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources a sequence of ObservableSources that need to be eagerly concatenated * @param maxConcurrency the maximum number of concurrently running inner ObservableSources; Integer.MAX_VALUE * is interpreted as all inner ObservableSources can be active at the same time * @param prefetch the number of elements to prefetch from each inner ObservableSource source * @return the new ObservableSource instance with the specified concatenation behavior * @since 2.0 */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatEager(ObservableSource> sources, int maxConcurrency, int prefetch) { return wrap(sources).concatMapEager((Function)Functions.identity(), maxConcurrency, prefetch); } /** * Concatenates a sequence of ObservableSources eagerly into a single stream of values. *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them * in order, each one after the previous one completes. *

* *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources a sequence of ObservableSources that need to be eagerly concatenated * @return the new ObservableSource instance with the specified concatenation behavior * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatEager(Iterable> sources) { return concatEager(sources, bufferSize(), bufferSize()); } /** * Concatenates a sequence of ObservableSources eagerly into a single stream of values. *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them * in order, each one after the previous one completes. *

* *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param sources a sequence of ObservableSources that need to be eagerly concatenated * @param maxConcurrency the maximum number of concurrently running inner ObservableSources; Integer.MAX_VALUE * is interpreted as all inner ObservableSources can be active at the same time * @param prefetch the number of elements to prefetch from each inner ObservableSource source * @return the new ObservableSource instance with the specified concatenation behavior * @since 2.0 */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable concatEager(Iterable> sources, int maxConcurrency, int prefetch) { return fromIterable(sources).concatMapEagerDelayError((Function)Functions.identity(), maxConcurrency, prefetch, false); } /** * Provides an API (via a cold Observable) that bridges the reactive world with the callback-style world. *

* Example: *


     * Observable.<Event>create(emitter -> {
     *     Callback listener = new Callback() {
     *         @Override
     *         public void onEvent(Event e) {
     *             emitter.onNext(e);
     *             if (e.isLast()) {
     *                 emitter.onComplete();
     *             }
     *         }
     *
     *         @Override
     *         public void onFailure(Exception e) {
     *             emitter.onError(e);
     *         }
     *     };
     *
     *     AutoCloseable c = api.someMethod(listener);
     *
     *     emitter.setCancellable(c::close);
     *
     * });
     * 
*

* *

* You should call the ObservableEmitter's onNext, onError and onComplete methods in a serialized fashion. The * rest of its methods are thread-safe. *

*
Scheduler:
*
{@code create} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type * @param source the emitter that is called when an Observer subscribes to the returned {@code Observable} * @return the new Observable instance * @see ObservableOnSubscribe * @see ObservableEmitter * @see Cancellable */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable create(ObservableOnSubscribe source) { ObjectHelper.requireNonNull(source, "source is null"); return RxJavaPlugins.onAssembly(new ObservableCreate(source)); } /** * Returns an Observable that calls an ObservableSource factory to create an ObservableSource for each new Observer * that subscribes. That is, for each subscriber, the actual ObservableSource that subscriber observes is * determined by the factory function. *

* *

* The defer Observer allows you to defer or delay emitting items from an ObservableSource until such time as an * Observer subscribes to the ObservableSource. This allows an {@link Observer} to easily obtain updates or a * refreshed version of the sequence. *

*
Scheduler:
*
{@code defer} does not operate by default on a particular {@link Scheduler}.
*
* * @param supplier * the ObservableSource factory function to invoke for each {@link Observer} that subscribes to the * resulting ObservableSource * @param * the type of the items emitted by the ObservableSource * @return an Observable whose {@link Observer}s' subscriptions trigger an invocation of the given * ObservableSource factory function * @see ReactiveX operators documentation: Defer */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable defer(Callable> supplier) { ObjectHelper.requireNonNull(supplier, "supplier is null"); return RxJavaPlugins.onAssembly(new ObservableDefer(supplier)); } /** * Returns an Observable that emits no items to the {@link Observer} and immediately invokes its * {@link Observer#onComplete onComplete} method. *

* *

*
Scheduler:
*
{@code empty} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of the items (ostensibly) emitted by the ObservableSource * @return an Observable that emits no items to the {@link Observer} but immediately invokes the * {@link Observer}'s {@link Observer#onComplete() onComplete} method * @see ReactiveX operators documentation: Empty */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Observable empty() { return RxJavaPlugins.onAssembly((Observable) ObservableEmpty.INSTANCE); } /** * Returns an Observable that invokes an {@link Observer}'s {@link Observer#onError onError} method when the * Observer subscribes to it. *

* *

*
Scheduler:
*
{@code error} does not operate by default on a particular {@link Scheduler}.
*
* * @param errorSupplier * a Callable factory to return a Throwable for each individual Observer * @param * the type of the items (ostensibly) emitted by the ObservableSource * @return an Observable that invokes the {@link Observer}'s {@link Observer#onError onError} method when * the Observer subscribes to it * @see ReactiveX operators documentation: Throw */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable error(Callable errorSupplier) { ObjectHelper.requireNonNull(errorSupplier, "errorSupplier is null"); return RxJavaPlugins.onAssembly(new ObservableError(errorSupplier)); } /** * Returns an Observable that invokes an {@link Observer}'s {@link Observer#onError onError} method when the * Observer subscribes to it. *

* *

*
Scheduler:
*
{@code error} does not operate by default on a particular {@link Scheduler}.
*
* * @param exception * the particular Throwable to pass to {@link Observer#onError onError} * @param * the type of the items (ostensibly) emitted by the ObservableSource * @return an Observable that invokes the {@link Observer}'s {@link Observer#onError onError} method when * the Observer subscribes to it * @see ReactiveX operators documentation: Throw */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable error(final Throwable exception) { ObjectHelper.requireNonNull(exception, "exception is null"); return error(Functions.justCallable(exception)); } /** * Converts an Array into an ObservableSource that emits the items in the Array. *

* *

*
Scheduler:
*
{@code fromArray} does not operate by default on a particular {@link Scheduler}.
*
* * @param items * the array of elements * @param * the type of items in the Array and the type of items to be emitted by the resulting ObservableSource * @return an Observable that emits each item in the source Array * @see ReactiveX operators documentation: From */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @NonNull public static Observable fromArray(T... items) { ObjectHelper.requireNonNull(items, "items is null"); if (items.length == 0) { return empty(); } if (items.length == 1) { return just(items[0]); } return RxJavaPlugins.onAssembly(new ObservableFromArray(items)); } /** * Returns an Observable that, when an observer subscribes to it, invokes a function you specify and then * emits the value returned from that function. *

* *

* This allows you to defer the execution of the function you specify until an observer subscribes to the * ObservableSource. That is to say, it makes the function "lazy." *

*
Scheduler:
*
{@code fromCallable} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If the {@link Callable} throws an exception, the respective {@link Throwable} is * delivered to the downstream via {@link Observer#onError(Throwable)}, * except when the downstream has disposed this {@code Observable} source. * In this latter case, the {@code Throwable} is delivered to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} as an {@link io.reactivex.exceptions.UndeliverableException UndeliverableException}. *
*
* @param supplier * a function, the execution of which should be deferred; {@code fromCallable} will invoke this * function only when an observer subscribes to the ObservableSource that {@code fromCallable} returns * @param * the type of the item emitted by the ObservableSource * @return an Observable whose {@link Observer}s' subscriptions trigger an invocation of the given function * @see #defer(Callable) * @since 2.0 */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable fromCallable(Callable supplier) { ObjectHelper.requireNonNull(supplier, "supplier is null"); return RxJavaPlugins.onAssembly(new ObservableFromCallable(supplier)); } /** * Converts a {@link Future} into an ObservableSource. *

* *

* You can convert any object that supports the {@link Future} interface into an ObservableSource that emits the * return value of the {@link Future#get} method of that object, by passing the object into the {@code from} * method. *

* Important note: This ObservableSource is blocking; you cannot dispose it. *

* Unlike 1.x, disposing the Observable won't cancel the future. If necessary, one can use composition to achieve the * cancellation effect: {@code futureObservableSource.doOnDispose(() -> future.cancel(true));}. *

*
Scheduler:
*
{@code fromFuture} does not operate by default on a particular {@link Scheduler}.
*
* * @param future * the source {@link Future} * @param * the type of object that the {@link Future} returns, and also the type of item to be emitted by * the resulting ObservableSource * @return an Observable that emits the item from the source {@link Future} * @see ReactiveX operators documentation: From */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable fromFuture(Future future) { ObjectHelper.requireNonNull(future, "future is null"); return RxJavaPlugins.onAssembly(new ObservableFromFuture(future, 0L, null)); } /** * Converts a {@link Future} into an ObservableSource, with a timeout on the Future. *

* *

* You can convert any object that supports the {@link Future} interface into an ObservableSource that emits the * return value of the {@link Future#get} method of that object, by passing the object into the {@code from} * method. *

* Unlike 1.x, disposing the Observable won't cancel the future. If necessary, one can use composition to achieve the * cancellation effect: {@code futureObservableSource.doOnDispose(() -> future.cancel(true));}. *

* Important note: This ObservableSource is blocking; you cannot dispose it. *

*
Scheduler:
*
{@code fromFuture} does not operate by default on a particular {@link Scheduler}.
*
* * @param future * the source {@link Future} * @param timeout * the maximum time to wait before calling {@code get} * @param unit * the {@link TimeUnit} of the {@code timeout} argument * @param * the type of object that the {@link Future} returns, and also the type of item to be emitted by * the resulting ObservableSource * @return an Observable that emits the item from the source {@link Future} * @see ReactiveX operators documentation: From */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable fromFuture(Future future, long timeout, TimeUnit unit) { ObjectHelper.requireNonNull(future, "future is null"); ObjectHelper.requireNonNull(unit, "unit is null"); return RxJavaPlugins.onAssembly(new ObservableFromFuture(future, timeout, unit)); } /** * Converts a {@link Future} into an ObservableSource, with a timeout on the Future. *

* *

* You can convert any object that supports the {@link Future} interface into an ObservableSource that emits the * return value of the {@link Future#get} method of that object, by passing the object into the {@code from} * method. *

* Unlike 1.x, disposing the Observable won't cancel the future. If necessary, one can use composition to achieve the * cancellation effect: {@code futureObservableSource.doOnDispose(() -> future.cancel(true));}. *

* Important note: This ObservableSource is blocking; you cannot dispose it. *

*
Scheduler:
*
{@code fromFuture} does not operate by default on a particular {@link Scheduler}.
*
* * @param future * the source {@link Future} * @param timeout * the maximum time to wait before calling {@code get} * @param unit * the {@link TimeUnit} of the {@code timeout} argument * @param scheduler * the {@link Scheduler} to wait for the Future on. Use a Scheduler such as * {@link Schedulers#io()} that can block and wait on the Future * @param * the type of object that the {@link Future} returns, and also the type of item to be emitted by * the resulting ObservableSource * @return an Observable that emits the item from the source {@link Future} * @see ReactiveX operators documentation: From */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public static Observable fromFuture(Future future, long timeout, TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); Observable o = fromFuture(future, timeout, unit); return o.subscribeOn(scheduler); } /** * Converts a {@link Future}, operating on a specified {@link Scheduler}, into an ObservableSource. *

* *

* You can convert any object that supports the {@link Future} interface into an ObservableSource that emits the * return value of the {@link Future#get} method of that object, by passing the object into the {@code from} * method. *

* Unlike 1.x, disposing the Observable won't cancel the future. If necessary, one can use composition to achieve the * cancellation effect: {@code futureObservableSource.doOnDispose(() -> future.cancel(true));}. *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param future * the source {@link Future} * @param scheduler * the {@link Scheduler} to wait for the Future on. Use a Scheduler such as * {@link Schedulers#io()} that can block and wait on the Future * @param * the type of object that the {@link Future} returns, and also the type of item to be emitted by * the resulting ObservableSource * @return an Observable that emits the item from the source {@link Future} * @see ReactiveX operators documentation: From */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public static Observable fromFuture(Future future, Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); Observable o = fromFuture(future); return o.subscribeOn(scheduler); } /** * Converts an {@link Iterable} sequence into an ObservableSource that emits the items in the sequence. *

* *

*
Scheduler:
*
{@code fromIterable} does not operate by default on a particular {@link Scheduler}.
*
* * @param source * the source {@link Iterable} sequence * @param * the type of items in the {@link Iterable} sequence and the type of items to be emitted by the * resulting ObservableSource * @return an Observable that emits each item in the source {@link Iterable} sequence * @see ReactiveX operators documentation: From */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable fromIterable(Iterable source) { ObjectHelper.requireNonNull(source, "source is null"); return RxJavaPlugins.onAssembly(new ObservableFromIterable(source)); } /** * Converts an arbitrary Reactive Streams Publisher into an Observable. *

* *

* The {@link Publisher} must follow the * Reactive Streams specification. * Violating the specification may result in undefined behavior. *

* If possible, use {@link #create(ObservableOnSubscribe)} to create a * source-like {@code Observable} instead. *

* Note that even though {@link Publisher} appears to be a functional interface, it * is not recommended to implement it through a lambda as the specification requires * state management that is not achievable with a stateless lambda. *

*
Backpressure:
*
The source {@code publisher} is consumed in an unbounded fashion without applying any * backpressure to it.
*
Scheduler:
*
{@code fromPublisher} does not operate by default on a particular {@link Scheduler}.
*
* @param the value type of the flow * @param publisher the Publisher to convert * @return the new Observable instance * @throws NullPointerException if publisher is null * @see #create(ObservableOnSubscribe) */ @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable fromPublisher(Publisher publisher) { ObjectHelper.requireNonNull(publisher, "publisher is null"); return RxJavaPlugins.onAssembly(new ObservableFromPublisher(publisher)); } /** * Returns a cold, synchronous and stateless generator of values. *

* *

* Note that the {@link Emitter#onNext}, {@link Emitter#onError} and * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance 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:
*
{@code generate} does not operate by default on a particular {@link Scheduler}.
*
* * @param the generated value type * @param generator the Consumer called whenever a particular downstream Observer has * requested a value. The callback then should call {@code onNext}, {@code onError} or * {@code onComplete} to signal a value or a terminal event. Signalling multiple {@code onNext} * in a call will make the operator signal {@code IllegalStateException}. * @return the new Observable instance */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable generate(final Consumer> generator) { ObjectHelper.requireNonNull(generator, "generator is null"); return generate(Functions.nullSupplier(), ObservableInternalHelper.simpleGenerator(generator), Functions.emptyConsumer()); } /** * Returns a cold, synchronous and stateful generator of values. *

* *

* Note that the {@link Emitter#onNext}, {@link Emitter#onError} and * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance 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:
*
{@code generate} does not operate by default on a particular {@link Scheduler}.
*
* * @param the type of the per-Observer state * @param the generated value type * @param initialState the Callable to generate the initial state for each Observer * @param generator the Consumer called with the current state whenever a particular downstream Observer has * requested a value. The callback then should call {@code onNext}, {@code onError} or * {@code onComplete} to signal a value or a terminal event. Signalling multiple {@code onNext} * in a call will make the operator signal {@code IllegalStateException}. * @return the new Observable instance */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable generate(Callable initialState, final BiConsumer> generator) { ObjectHelper.requireNonNull(generator, "generator is null"); return generate(initialState, ObservableInternalHelper.simpleBiGenerator(generator), Functions.emptyConsumer()); } /** * Returns a cold, synchronous and stateful generator of values. *

* *

* Note that the {@link Emitter#onNext}, {@link Emitter#onError} and * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance 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:
*
{@code generate} does not operate by default on a particular {@link Scheduler}.
*
* * @param the type of the per-Observer state * @param the generated value type * @param initialState the Callable to generate the initial state for each Observer * @param generator the Consumer called with the current state whenever a particular downstream Observer has * requested a value. The callback then should call {@code onNext}, {@code onError} or * {@code onComplete} to signal a value or a terminal event. Signalling multiple {@code onNext} * in a call will make the operator signal {@code IllegalStateException}. * @param disposeState the Consumer that is called with the current state when the generator * terminates the sequence or it gets disposed * @return the new Observable instance */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable generate( final Callable initialState, final BiConsumer> generator, Consumer disposeState) { ObjectHelper.requireNonNull(generator, "generator is null"); return generate(initialState, ObservableInternalHelper.simpleBiGenerator(generator), disposeState); } /** * Returns a cold, synchronous and stateful generator of values. *

* *

* Note that the {@link Emitter#onNext}, {@link Emitter#onError} and * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance 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:
*
{@code generate} does not operate by default on a particular {@link Scheduler}.
*
* * @param the type of the per-Observer state * @param the generated value type * @param initialState the Callable to generate the initial state for each Observer * @param generator the Function called with the current state whenever a particular downstream Observer has * requested a value. The callback then should call {@code onNext}, {@code onError} or * {@code onComplete} to signal a value or a terminal event and should return a (new) state for * the next invocation. Signalling multiple {@code onNext} * in a call will make the operator signal {@code IllegalStateException}. * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable generate(Callable initialState, BiFunction, S> generator) { return generate(initialState, generator, Functions.emptyConsumer()); } /** * Returns a cold, synchronous and stateful generator of values. *

* *

* Note that the {@link Emitter#onNext}, {@link Emitter#onError} and * {@link Emitter#onComplete} methods provided to the function via the {@link Emitter} instance 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:
*
{@code generate} does not operate by default on a particular {@link Scheduler}.
*
* * @param the type of the per-Observer state * @param the generated value type * @param initialState the Callable to generate the initial state for each Observer * @param generator the Function called with the current state whenever a particular downstream Observer has * requested a value. The callback then should call {@code onNext}, {@code onError} or * {@code onComplete} to signal a value or a terminal event and should return a (new) state for * the next invocation. Signalling multiple {@code onNext} * in a call will make the operator signal {@code IllegalStateException}. * @param disposeState the Consumer that is called with the current state when the generator * terminates the sequence or it gets disposed * @return the new Observable instance */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable generate(Callable initialState, BiFunction, S> generator, Consumer disposeState) { ObjectHelper.requireNonNull(initialState, "initialState is null"); ObjectHelper.requireNonNull(generator, "generator is null"); ObjectHelper.requireNonNull(disposeState, "disposeState is null"); return RxJavaPlugins.onAssembly(new ObservableGenerate(initialState, generator, disposeState)); } /** * Returns an Observable that emits a {@code 0L} after the {@code initialDelay} and ever increasing numbers * after each {@code period} of time thereafter. *

* *

*
Scheduler:
*
{@code interval} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param initialDelay * the initial delay time to wait before emitting the first value of 0L * @param period * the period of time between emissions of the subsequent numbers * @param unit * the time unit for both {@code initialDelay} and {@code period} * @return an Observable that emits a 0L after the {@code initialDelay} and ever increasing numbers after * each {@code period} of time thereafter * @see ReactiveX operators documentation: Interval * @since 1.0.12 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public static Observable interval(long initialDelay, long period, TimeUnit unit) { return interval(initialDelay, period, unit, Schedulers.computation()); } /** * Returns an Observable that emits a {@code 0L} after the {@code initialDelay} and ever increasing numbers * after each {@code period} of time thereafter, on a specified {@link Scheduler}. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param initialDelay * the initial delay time to wait before emitting the first value of 0L * @param period * the period of time between emissions of the subsequent numbers * @param unit * the time unit for both {@code initialDelay} and {@code period} * @param scheduler * the Scheduler on which the waiting happens and items are emitted * @return an Observable that emits a 0L after the {@code initialDelay} and ever increasing numbers after * each {@code period} of time thereafter, while running on the given Scheduler * @see ReactiveX operators documentation: Interval * @since 1.0.12 */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public static Observable interval(long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new ObservableInterval(Math.max(0L, initialDelay), Math.max(0L, period), unit, scheduler)); } /** * Returns an Observable that emits a sequential number every specified interval of time. *

* *

*
Scheduler:
*
{@code interval} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param period * the period size in time units (see below) * @param unit * time units to use for the interval size * @return an Observable that emits a sequential number each time interval * @see ReactiveX operators documentation: Interval */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public static Observable interval(long period, TimeUnit unit) { return interval(period, period, unit, Schedulers.computation()); } /** * Returns an Observable that emits a sequential number every specified interval of time, on a * specified Scheduler. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param period * the period size in time units (see below) * @param unit * time units to use for the interval size * @param scheduler * the Scheduler to use for scheduling the items * @return an Observable that emits a sequential number each time interval * @see ReactiveX operators documentation: Interval */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public static Observable interval(long period, TimeUnit unit, Scheduler scheduler) { return interval(period, period, unit, 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:
*
{@code intervalRange} by default operates on the {@link Schedulers#computation() computation} {@link Scheduler}.
*
* @param start that start value of the range * @param count the number of values to emit in total, if zero, the operator emits an onComplete after the initial delay. * @param initialDelay the initial delay before signalling the first value (the start) * @param period the period between subsequent values * @param unit the unit of measure of the initialDelay and period amounts * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public static Observable intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit) { return intervalRange(start, count, initialDelay, period, unit, Schedulers.computation()); } /** * 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 {@link Scheduler}.
*
* @param start that start value of the range * @param count the number of values to emit in total, if zero, the operator emits an onComplete after the initial delay. * @param initialDelay the initial delay before signalling the first value (the start) * @param period the period between subsequent values * @param unit the unit of measure of the initialDelay and period amounts * @param scheduler the target scheduler where the values and terminal signals will be emitted * @return the new Observable instance */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.CUSTOM) public static Observable intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { if (count < 0) { throw new IllegalArgumentException("count >= 0 required but it was " + count); } if (count == 0L) { return Observable.empty().delay(initialDelay, unit, scheduler); } long end = start + (count - 1); if (start > 0 && end < 0) { throw new IllegalArgumentException("Overflow! start + count is bigger than Long.MAX_VALUE"); } ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new ObservableIntervalRange(start, end, Math.max(0L, initialDelay), Math.max(0L, period), unit, scheduler)); } /** * Returns an Observable that 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 {@code just}. Use {@link #fromCallable(Callable)} * to generate a single item on demand (when {@code Observer}s subscribe to it). *

* See the multi-parameter overloads of {@code just} to emit more than one (constant reference) items one after the other. * Use {@link #fromArray(Object...)} to emit an arbitrary number of items that are known upfront. *

* To emit the items of an {@link Iterable} sequence (such as a {@link java.util.List}), use {@link #fromIterable(Iterable)}. *

*
Scheduler:
*
{@code just} does not operate by default on a particular {@link Scheduler}.
*
* * @param item * the item to emit * @param * the type of that item * @return an Observable that emits {@code value} as a single item and then completes * @see ReactiveX operators documentation: Just * @see #just(Object, Object) * @see #fromCallable(Callable) * @see #fromArray(Object...) * @see #fromIterable(Iterable) */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item) { ObjectHelper.requireNonNull(item, "item is null"); return RxJavaPlugins.onAssembly(new ObservableJust(item)); } /** * Converts two items into an ObservableSource that emits those items. *

* *

*
Scheduler:
*
{@code just} does not operate by default on a particular {@link Scheduler}.
*
* * @param item1 * first item * @param item2 * second item * @param * the type of these items * @return an Observable that emits each item * @see ReactiveX operators documentation: Just */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2) { ObjectHelper.requireNonNull(item1, "item1 is null"); ObjectHelper.requireNonNull(item2, "item2 is null"); return fromArray(item1, item2); } /** * Converts three items into an ObservableSource that emits those items. *

* *

*
Scheduler:
*
{@code just} does not operate by default on a particular {@link Scheduler}.
*
* * @param item1 * first item * @param item2 * second item * @param item3 * third item * @param * the type of these items * @return an Observable that emits each item * @see ReactiveX operators documentation: Just */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3) { ObjectHelper.requireNonNull(item1, "item1 is null"); ObjectHelper.requireNonNull(item2, "item2 is null"); ObjectHelper.requireNonNull(item3, "item3 is null"); return fromArray(item1, item2, item3); } /** * Converts four items into an ObservableSource that emits those items. *

* *

*
Scheduler:
*
{@code just} does not operate by default on a particular {@link Scheduler}.
*
* * @param item1 * first item * @param item2 * second item * @param item3 * third item * @param item4 * fourth item * @param * the type of these items * @return an Observable that emits each item * @see ReactiveX operators documentation: Just */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4) { ObjectHelper.requireNonNull(item1, "item1 is null"); ObjectHelper.requireNonNull(item2, "item2 is null"); ObjectHelper.requireNonNull(item3, "item3 is null"); ObjectHelper.requireNonNull(item4, "item4 is null"); return fromArray(item1, item2, item3, item4); } /** * Converts five items into an ObservableSource that emits those items. *

* *

*
Scheduler:
*
{@code just} does not operate by default on a particular {@link Scheduler}.
*
* * @param item1 * first item * @param item2 * second item * @param item3 * third item * @param item4 * fourth item * @param item5 * fifth item * @param * the type of these items * @return an Observable that emits each item * @see ReactiveX operators documentation: Just */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5) { ObjectHelper.requireNonNull(item1, "item1 is null"); ObjectHelper.requireNonNull(item2, "item2 is null"); ObjectHelper.requireNonNull(item3, "item3 is null"); ObjectHelper.requireNonNull(item4, "item4 is null"); ObjectHelper.requireNonNull(item5, "item5 is null"); return fromArray(item1, item2, item3, item4, item5); } /** * Converts six items into an ObservableSource that emits those items. *

* *

*
Scheduler:
*
{@code just} does not operate by default on a particular {@link Scheduler}.
*
* * @param item1 * first item * @param item2 * second item * @param item3 * third item * @param item4 * fourth item * @param item5 * fifth item * @param item6 * sixth item * @param * the type of these items * @return an Observable that emits each item * @see ReactiveX operators documentation: Just */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6) { ObjectHelper.requireNonNull(item1, "item1 is null"); ObjectHelper.requireNonNull(item2, "item2 is null"); ObjectHelper.requireNonNull(item3, "item3 is null"); ObjectHelper.requireNonNull(item4, "item4 is null"); ObjectHelper.requireNonNull(item5, "item5 is null"); ObjectHelper.requireNonNull(item6, "item6 is null"); return fromArray(item1, item2, item3, item4, item5, item6); } /** * Converts seven items into an ObservableSource that emits those items. *

* *

*
Scheduler:
*
{@code just} does not operate by default on a particular {@link Scheduler}.
*
* * @param item1 * first item * @param item2 * second item * @param item3 * third item * @param item4 * fourth item * @param item5 * fifth item * @param item6 * sixth item * @param item7 * seventh item * @param * the type of these items * @return an Observable that emits each item * @see ReactiveX operators documentation: Just */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7) { ObjectHelper.requireNonNull(item1, "item1 is null"); ObjectHelper.requireNonNull(item2, "item2 is null"); ObjectHelper.requireNonNull(item3, "item3 is null"); ObjectHelper.requireNonNull(item4, "item4 is null"); ObjectHelper.requireNonNull(item5, "item5 is null"); ObjectHelper.requireNonNull(item6, "item6 is null"); ObjectHelper.requireNonNull(item7, "item7 is null"); return fromArray(item1, item2, item3, item4, item5, item6, item7); } /** * Converts eight items into an ObservableSource that emits those items. *

* *

*
Scheduler:
*
{@code just} does not operate by default on a particular {@link Scheduler}.
*
* * @param item1 * first item * @param item2 * second item * @param item3 * third item * @param item4 * fourth item * @param item5 * fifth item * @param item6 * sixth item * @param item7 * seventh item * @param item8 * eighth item * @param * the type of these items * @return an Observable that emits each item * @see ReactiveX operators documentation: Just */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8) { ObjectHelper.requireNonNull(item1, "item1 is null"); ObjectHelper.requireNonNull(item2, "item2 is null"); ObjectHelper.requireNonNull(item3, "item3 is null"); ObjectHelper.requireNonNull(item4, "item4 is null"); ObjectHelper.requireNonNull(item5, "item5 is null"); ObjectHelper.requireNonNull(item6, "item6 is null"); ObjectHelper.requireNonNull(item7, "item7 is null"); ObjectHelper.requireNonNull(item8, "item8 is null"); return fromArray(item1, item2, item3, item4, item5, item6, item7, item8); } /** * Converts nine items into an ObservableSource that emits those items. *

* *

*
Scheduler:
*
{@code just} does not operate by default on a particular {@link Scheduler}.
*
* * @param item1 * first item * @param item2 * second item * @param item3 * third item * @param item4 * fourth item * @param item5 * fifth item * @param item6 * sixth item * @param item7 * seventh item * @param item8 * eighth item * @param item9 * ninth item * @param * the type of these items * @return an Observable that emits each item * @see ReactiveX operators documentation: Just */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8, T item9) { ObjectHelper.requireNonNull(item1, "item1 is null"); ObjectHelper.requireNonNull(item2, "item2 is null"); ObjectHelper.requireNonNull(item3, "item3 is null"); ObjectHelper.requireNonNull(item4, "item4 is null"); ObjectHelper.requireNonNull(item5, "item5 is null"); ObjectHelper.requireNonNull(item6, "item6 is null"); ObjectHelper.requireNonNull(item7, "item7 is null"); ObjectHelper.requireNonNull(item8, "item8 is null"); ObjectHelper.requireNonNull(item9, "item9 is null"); return fromArray(item1, item2, item3, item4, item5, item6, item7, item8, item9); } /** * Converts ten items into an ObservableSource that emits those items. *

* *

*
Scheduler:
*
{@code just} does not operate by default on a particular {@link Scheduler}.
*
* * @param item1 * first item * @param item2 * second item * @param item3 * third item * @param item4 * fourth item * @param item5 * fifth item * @param item6 * sixth item * @param item7 * seventh item * @param item8 * eighth item * @param item9 * ninth item * @param item10 * tenth item * @param * the type of these items * @return an Observable that emits each item * @see ReactiveX operators documentation: Just */ @SuppressWarnings("unchecked") @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Observable just(T item1, T item2, T item3, T item4, T item5, T item6, T item7, T item8, T item9, T item10) { ObjectHelper.requireNonNull(item1, "item1 is null"); ObjectHelper.requireNonNull(item2, "item2 is null"); ObjectHelper.requireNonNull(item3, "item3 is null"); ObjectHelper.requireNonNull(item4, "item4 is null"); ObjectHelper.requireNonNull(item5, "item5 is null"); ObjectHelper.requireNonNull(item6, "item6 is null"); ObjectHelper.requireNonNull(item7, "item7 is null"); ObjectHelper.requireNonNull(item8, "item8 is null"); ObjectHelper.requireNonNull(item9, "item9 is null"); ObjectHelper.requireNonNull(item10, "item10 is null"); return fromArray(item1, item2, item3, item4, item5, item6, item7, item8, item9, item10); } /** * Flattens an Iterable of ObservableSources into one ObservableSource, without any transformation, while limiting the * number of concurrent subscriptions to these ObservableSources. *

* *

* You can combine the items emitted by multiple ObservableSources so that they appear as a single ObservableSource, by * using the {@code merge} method. *

*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(Iterable, int, int)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. *
*
* * @param the common element base type * @param sources * the Iterable of ObservableSources * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @param bufferSize * the number of items to prefetch from each inner ObservableSource * @return an Observable that emits items that are the result of flattening the items emitted by the * ObservableSources in the Iterable * @throws IllegalArgumentException * if {@code maxConcurrent} is less than or equal to 0 * @see ReactiveX operators documentation: Merge * @see #mergeDelayError(Iterable, int, int) */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable merge(Iterable> sources, int maxConcurrency, int bufferSize) { return fromIterable(sources).flatMap((Function)Functions.identity(), false, maxConcurrency, bufferSize); } /** * Flattens an Iterable of ObservableSources into one ObservableSource, without any transformation, while limiting the * number of concurrent subscriptions to these ObservableSources. *

* *

* You can combine the items emitted by multiple ObservableSources so that they appear as a single ObservableSource, by * using the {@code merge} method. *

*
Scheduler:
*
{@code mergeArray} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeArrayDelayError(int, int, ObservableSource...)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. *
*
* * @param the common element base type * @param sources * the array of ObservableSources * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @param bufferSize * the number of items to prefetch from each inner ObservableSource * @return an Observable that emits items that are the result of flattening the items emitted by the * ObservableSources in the Iterable * @throws IllegalArgumentException * if {@code maxConcurrent} is less than or equal to 0 * @see ReactiveX operators documentation: Merge * @see #mergeArrayDelayError(int, int, ObservableSource...) */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeArray(int maxConcurrency, int bufferSize, ObservableSource... sources) { return fromArray(sources).flatMap((Function)Functions.identity(), false, maxConcurrency, bufferSize); } /** * Flattens an Iterable of ObservableSources into one ObservableSource, without any transformation. *

* *

* You can combine the items emitted by multiple ObservableSources so that they appear as a single ObservableSource, by * using the {@code merge} method. *

*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(Iterable)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. *
*
* * @param the common element base type * @param sources * the Iterable of ObservableSources * @return an Observable that emits items that are the result of flattening the items emitted by the * ObservableSources in the Iterable * @see ReactiveX operators documentation: Merge * @see #mergeDelayError(Iterable) */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable merge(Iterable> sources) { return fromIterable(sources).flatMap((Function)Functions.identity()); } /** * Flattens an Iterable of ObservableSources into one ObservableSource, without any transformation, while limiting the * number of concurrent subscriptions to these ObservableSources. *

* *

* You can combine the items emitted by multiple ObservableSources so that they appear as a single ObservableSource, by * using the {@code merge} method. *

*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(Iterable, int)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. *
*
* * @param the common element base type * @param sources * the Iterable of ObservableSources * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @return an Observable that emits items that are the result of flattening the items emitted by the * ObservableSources in the Iterable * @throws IllegalArgumentException * if {@code maxConcurrent} is less than or equal to 0 * @see ReactiveX operators documentation: Merge * @see #mergeDelayError(Iterable, int) */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable merge(Iterable> sources, int maxConcurrency) { return fromIterable(sources).flatMap((Function)Functions.identity(), maxConcurrency); } /** * Flattens an ObservableSource that emits ObservableSources into a single ObservableSource that emits the items emitted by * those ObservableSources, without any transformation. *

* *

* You can combine the items emitted by multiple ObservableSources so that they appear as a single ObservableSource, by * using the {@code merge} method. *

*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(ObservableSource)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. *
*
* * @param the common element base type * @param sources * an ObservableSource that emits ObservableSources * @return an Observable that emits items that are the result of flattening the ObservableSources emitted by the * {@code source} ObservableSource * @see ReactiveX operators documentation: Merge * @see #mergeDelayError(ObservableSource) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings({ "unchecked", "rawtypes" }) public static Observable merge(ObservableSource> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); return RxJavaPlugins.onAssembly(new ObservableFlatMap(sources, Functions.identity(), false, Integer.MAX_VALUE, bufferSize())); } /** * Flattens an ObservableSource that emits ObservableSources into a single ObservableSource that emits the items emitted by * those ObservableSources, without any transformation, while limiting the maximum number of concurrent * subscriptions to these ObservableSources. *

* *

* You can combine the items emitted by multiple ObservableSources so that they appear as a single ObservableSource, by * using the {@code merge} method. *

*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(ObservableSource, int)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. *
*
* * @param the common element base type * @param sources * an ObservableSource that emits ObservableSources * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @return an Observable that emits items that are the result of flattening the ObservableSources emitted by the * {@code source} ObservableSource * @throws IllegalArgumentException * if {@code maxConcurrent} is less than or equal to 0 * @see ReactiveX operators documentation: Merge * @since 1.1.0 * @see #mergeDelayError(ObservableSource, int) */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable merge(ObservableSource> sources, int maxConcurrency) { ObjectHelper.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency"); return RxJavaPlugins.onAssembly(new ObservableFlatMap(sources, Functions.identity(), false, maxConcurrency, bufferSize())); } /** * Flattens two ObservableSources into a single ObservableSource, without any transformation. *

* *

* You can combine items emitted by multiple ObservableSources so that they appear as a single ObservableSource, by * using the {@code merge} method. *

*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(ObservableSource, ObservableSource)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. *
*
* * @param the common element base type * @param source1 * an ObservableSource to be merged * @param source2 * an ObservableSource to be merged * @return an Observable that emits all of the items emitted by the source ObservableSources * @see ReactiveX operators documentation: Merge * @see #mergeDelayError(ObservableSource, ObservableSource) */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable merge(ObservableSource source1, ObservableSource source2) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); return fromArray(source1, source2).flatMap((Function)Functions.identity(), false, 2); } /** * Flattens three ObservableSources into a single ObservableSource, without any transformation. *

* *

* You can combine items emitted by multiple ObservableSources so that they appear as a single ObservableSource, by * using the {@code merge} method. *

*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(ObservableSource, ObservableSource, ObservableSource)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. *
*
* * @param the common element base type * @param source1 * an ObservableSource to be merged * @param source2 * an ObservableSource to be merged * @param source3 * an ObservableSource to be merged * @return an Observable that emits all of the items emitted by the source ObservableSources * @see ReactiveX operators documentation: Merge * @see #mergeDelayError(ObservableSource, ObservableSource, ObservableSource) */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable merge(ObservableSource source1, ObservableSource source2, ObservableSource source3) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); return fromArray(source1, source2, source3).flatMap((Function)Functions.identity(), false, 3); } /** * Flattens four ObservableSources into a single ObservableSource, without any transformation. *

* *

* You can combine items emitted by multiple ObservableSources so that they appear as a single ObservableSource, by * using the {@code merge} method. *

*
Scheduler:
*
{@code merge} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeDelayError(ObservableSource, ObservableSource, ObservableSource, ObservableSource)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. *
*
* * @param the common element base type * @param source1 * an ObservableSource to be merged * @param source2 * an ObservableSource to be merged * @param source3 * an ObservableSource to be merged * @param source4 * an ObservableSource to be merged * @return an Observable that emits all of the items emitted by the source ObservableSources * @see ReactiveX operators documentation: Merge * @see #mergeDelayError(ObservableSource, ObservableSource, ObservableSource, ObservableSource) */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable merge( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); return fromArray(source1, source2, source3, source4).flatMap((Function)Functions.identity(), false, 4); } /** * Flattens an Array of ObservableSources into one ObservableSource, without any transformation. *

* *

* You can combine items emitted by multiple ObservableSources so that they appear as a single ObservableSource, by * using the {@code merge} method. *

*
Scheduler:
*
{@code mergeArray} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If any of the source {@code ObservableSource}s signal a {@code Throwable} via {@code onError}, the resulting * {@code Observable} terminates with that {@code Throwable} and all other source {@code ObservableSource}s are disposed. * If more than one {@code ObservableSource} signals an error, the resulting {@code Observable} may terminate with the * first one's error or, depending on the concurrency of the sources, may terminate with a * {@code CompositeException} containing two or more of the various error signals. * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. Similarly, {@code Throwable}s * signaled by source(s) after the returned {@code Observable} has been disposed or terminated with a * (composite) error will be sent to the same global error handler. * Use {@link #mergeArrayDelayError(ObservableSource...)} to merge sources and terminate only when all source {@code ObservableSource}s * have completed or failed with an error. *
*
* * @param the common element base type * @param sources * the array of ObservableSources * @return an Observable that emits all of the items emitted by the ObservableSources in the Array * @see ReactiveX operators documentation: Merge * @see #mergeArrayDelayError(ObservableSource...) */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeArray(ObservableSource... sources) { return fromArray(sources).flatMap((Function)Functions.identity(), sources.length); } /** * Flattens an Iterable of ObservableSources into one ObservableSource, in a way that allows an Observer to receive all * successfully emitted items from each of the source ObservableSources without being interrupted by an error * notification from one of them. *

* This behaves like {@link #merge(ObservableSource)} except that if any of the merged ObservableSources notify of an * error via {@link Observer#onError onError}, {@code mergeDelayError} will refrain from propagating that * error notification until all of the merged ObservableSources have finished emitting items. *

* *

* Even if multiple merged ObservableSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources * the Iterable of ObservableSources * @return an Observable that emits items that are the result of flattening the items emitted by the * ObservableSources in the Iterable * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeDelayError(Iterable> sources) { return fromIterable(sources).flatMap((Function)Functions.identity(), true); } /** * Flattens an Iterable of ObservableSources into one ObservableSource, in a way that allows an Observer to receive all * successfully emitted items from each of the source ObservableSources without being interrupted by an error * notification from one of them, while limiting the number of concurrent subscriptions to these ObservableSources. *

* This behaves like {@link #merge(ObservableSource)} except that if any of the merged ObservableSources notify of an * error via {@link Observer#onError onError}, {@code mergeDelayError} will refrain from propagating that * error notification until all of the merged ObservableSources have finished emitting items. *

* *

* Even if multiple merged ObservableSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources * the Iterable of ObservableSources * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @param bufferSize * the number of items to prefetch from each inner ObservableSource * @return an Observable that emits items that are the result of flattening the items emitted by the * ObservableSources in the Iterable * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeDelayError(Iterable> sources, int maxConcurrency, int bufferSize) { return fromIterable(sources).flatMap((Function)Functions.identity(), true, maxConcurrency, bufferSize); } /** * Flattens an array of ObservableSources into one ObservableSource, in a way that allows an Observer to receive all * successfully emitted items from each of the source ObservableSources without being interrupted by an error * notification from one of them, while limiting the number of concurrent subscriptions to these ObservableSources. *

* This behaves like {@link #merge(ObservableSource)} except that if any of the merged ObservableSources notify of an * error via {@link Observer#onError onError}, {@code mergeDelayError} will refrain from propagating that * error notification until all of the merged ObservableSources have finished emitting items. *

* *

* Even if multiple merged ObservableSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeArrayDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources * the array of ObservableSources * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @param bufferSize * the number of items to prefetch from each inner ObservableSource * @return an Observable that emits items that are the result of flattening the items emitted by the * ObservableSources in the Iterable * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeArrayDelayError(int maxConcurrency, int bufferSize, ObservableSource... sources) { return fromArray(sources).flatMap((Function)Functions.identity(), true, maxConcurrency, bufferSize); } /** * Flattens an Iterable of ObservableSources into one ObservableSource, in a way that allows an Observer to receive all * successfully emitted items from each of the source ObservableSources without being interrupted by an error * notification from one of them, while limiting the number of concurrent subscriptions to these ObservableSources. *

* This behaves like {@link #merge(ObservableSource)} except that if any of the merged ObservableSources notify of an * error via {@link Observer#onError onError}, {@code mergeDelayError} will refrain from propagating that * error notification until all of the merged ObservableSources have finished emitting items. *

* *

* Even if multiple merged ObservableSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources * the Iterable of ObservableSources * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @return an Observable that emits items that are the result of flattening the items emitted by the * ObservableSources in the Iterable * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeDelayError(Iterable> sources, int maxConcurrency) { return fromIterable(sources).flatMap((Function)Functions.identity(), true, maxConcurrency); } /** * Flattens an ObservableSource that emits ObservableSources into one ObservableSource, in a way that allows an Observer to * receive all successfully emitted items from all of the source ObservableSources without being interrupted by * an error notification from one of them. *

* This behaves like {@link #merge(ObservableSource)} except that if any of the merged ObservableSources notify of an * error via {@link Observer#onError onError}, {@code mergeDelayError} will refrain from propagating that * error notification until all of the merged ObservableSources have finished emitting items. *

* *

* Even if multiple merged ObservableSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources * an ObservableSource that emits ObservableSources * @return an Observable that emits all of the items emitted by the ObservableSources emitted by the * {@code source} ObservableSource * @see ReactiveX operators documentation: Merge */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings({ "unchecked", "rawtypes" }) public static Observable mergeDelayError(ObservableSource> sources) { ObjectHelper.requireNonNull(sources, "sources is null"); return RxJavaPlugins.onAssembly(new ObservableFlatMap(sources, Functions.identity(), true, Integer.MAX_VALUE, bufferSize())); } /** * Flattens an ObservableSource that emits ObservableSources into one ObservableSource, in a way that allows an Observer to * receive all successfully emitted items from all of the source ObservableSources without being interrupted by * an error notification from one of them, while limiting the * number of concurrent subscriptions to these ObservableSources. *

* This behaves like {@link #merge(ObservableSource)} except that if any of the merged ObservableSources notify of an * error via {@link Observer#onError onError}, {@code mergeDelayError} will refrain from propagating that * error notification until all of the merged ObservableSources have finished emitting items. *

* *

* Even if multiple merged ObservableSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources * an ObservableSource that emits ObservableSources * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @return an Observable that emits all of the items emitted by the ObservableSources emitted by the * {@code source} ObservableSource * @see ReactiveX operators documentation: Merge * @since 2.0 */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeDelayError(ObservableSource> sources, int maxConcurrency) { ObjectHelper.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency"); return RxJavaPlugins.onAssembly(new ObservableFlatMap(sources, Functions.identity(), true, maxConcurrency, bufferSize())); } /** * Flattens two ObservableSources into one ObservableSource, in a way that allows an Observer to receive all * successfully emitted items from each of the source ObservableSources without being interrupted by an error * notification from one of them. *

* This behaves like {@link #merge(ObservableSource, ObservableSource)} except that if any of the merged ObservableSources * notify of an error via {@link Observer#onError onError}, {@code mergeDelayError} will refrain from * propagating that error notification until all of the merged ObservableSources have finished emitting items. *

* *

* Even if both merged ObservableSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param source1 * an ObservableSource to be merged * @param source2 * an ObservableSource to be merged * @return an Observable that emits all of the items that are emitted by the two source ObservableSources * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeDelayError(ObservableSource source1, ObservableSource source2) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); return fromArray(source1, source2).flatMap((Function)Functions.identity(), true, 2); } /** * Flattens three ObservableSources into one ObservableSource, in a way that allows an Observer to receive all * successfully emitted items from all of the source ObservableSources without being interrupted by an error * notification from one of them. *

* This behaves like {@link #merge(ObservableSource, ObservableSource, ObservableSource)} except that if any of the merged * ObservableSources notify of an error via {@link Observer#onError onError}, {@code mergeDelayError} will refrain * from propagating that error notification until all of the merged ObservableSources have finished emitting * items. *

* *

* Even if multiple merged ObservableSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param source1 * an ObservableSource to be merged * @param source2 * an ObservableSource to be merged * @param source3 * an ObservableSource to be merged * @return an Observable that emits all of the items that are emitted by the source ObservableSources * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeDelayError(ObservableSource source1, ObservableSource source2, ObservableSource source3) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); return fromArray(source1, source2, source3).flatMap((Function)Functions.identity(), true, 3); } /** * Flattens four ObservableSources into one ObservableSource, in a way that allows an Observer to receive all * successfully emitted items from all of the source ObservableSources without being interrupted by an error * notification from one of them. *

* This behaves like {@link #merge(ObservableSource, ObservableSource, ObservableSource, ObservableSource)} except that if any of * the merged ObservableSources notify of an error via {@link Observer#onError onError}, {@code mergeDelayError} * will refrain from propagating that error notification until all of the merged ObservableSources have finished * emitting items. *

* *

* Even if multiple merged ObservableSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param source1 * an ObservableSource to be merged * @param source2 * an ObservableSource to be merged * @param source3 * an ObservableSource to be merged * @param source4 * an ObservableSource to be merged * @return an Observable that emits all of the items that are emitted by the source ObservableSources * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeDelayError( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); return fromArray(source1, source2, source3, source4).flatMap((Function)Functions.identity(), true, 4); } /** * Flattens an Iterable of ObservableSources into one ObservableSource, in a way that allows an Observer to receive all * successfully emitted items from each of the source ObservableSources without being interrupted by an error * notification from one of them. *

* This behaves like {@link #merge(ObservableSource)} except that if any of the merged ObservableSources notify of an * error via {@link Observer#onError onError}, {@code mergeDelayError} will refrain from propagating that * error notification until all of the merged ObservableSources have finished emitting items. *

* *

* Even if multiple merged ObservableSources send {@code onError} notifications, {@code mergeDelayError} will only * invoke the {@code onError} method of its Observers once. *

*
Scheduler:
*
{@code mergeArrayDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element base type * @param sources * the Iterable of ObservableSources * @return an Observable that emits items that are the result of flattening the items emitted by the * ObservableSources in the Iterable * @see ReactiveX operators documentation: Merge */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable mergeArrayDelayError(ObservableSource... sources) { return fromArray(sources).flatMap((Function)Functions.identity(), true, sources.length); } /** * Returns an Observable that never sends any items or notifications to an {@link Observer}. *

* *

* This ObservableSource is useful primarily for testing purposes. *

*
Scheduler:
*
{@code never} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items (not) emitted by the ObservableSource * @return an Observable that never emits any items or sends any notifications to an {@link Observer} * @see ReactiveX operators documentation: Never */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static Observable never() { return RxJavaPlugins.onAssembly((Observable) ObservableNever.INSTANCE); } /** * Returns an Observable that emits a sequence of Integers within a specified range. *

* *

*
Scheduler:
*
{@code range} does not operate by default on a particular {@link Scheduler}.
*
* * @param start * the value of the first Integer in the sequence * @param count * the number of sequential Integers to generate * @return an Observable that emits a range of sequential Integers * @throws IllegalArgumentException * if {@code count} is less than zero, or if {@code start} + {@code count} − 1 exceeds * {@code Integer.MAX_VALUE} * @see ReactiveX operators documentation: Range */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable range(final int start, final int count) { if (count < 0) { throw new IllegalArgumentException("count >= 0 required but it was " + count); } if (count == 0) { return empty(); } if (count == 1) { return just(start); } if ((long)start + (count - 1) > Integer.MAX_VALUE) { throw new IllegalArgumentException("Integer overflow"); } return RxJavaPlugins.onAssembly(new ObservableRange(start, count)); } /** * Returns an Observable that emits a sequence of Longs within a specified range. *

* *

*
Scheduler:
*
{@code rangeLong} does not operate by default on a particular {@link Scheduler}.
*
* * @param start * the value of the first Long in the sequence * @param count * the number of sequential Longs to generate * @return an Observable that emits a range of sequential Longs * @throws IllegalArgumentException * if {@code count} is less than zero, or if {@code start} + {@code count} − 1 exceeds * {@code Long.MAX_VALUE} * @see ReactiveX operators documentation: Range */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable rangeLong(long start, long count) { if (count < 0) { throw new IllegalArgumentException("count >= 0 required but it was " + count); } if (count == 0) { return empty(); } if (count == 1) { return just(start); } long end = start + (count - 1); if (start > 0 && end < 0) { throw new IllegalArgumentException("Overflow! start + count is bigger than Long.MAX_VALUE"); } return RxJavaPlugins.onAssembly(new ObservableRangeLong(start, count)); } /** * Returns a Single that emits a Boolean value that indicates whether two ObservableSource sequences are the * same by comparing the items emitted by each ObservableSource pairwise. *

* *

*
Scheduler:
*
{@code sequenceEqual} does not operate by default on a particular {@link Scheduler}.
*
* * @param source1 * the first ObservableSource to compare * @param source2 * the second ObservableSource to compare * @param * the type of items emitted by each ObservableSource * @return a Single that emits a Boolean value that indicates whether the two sequences are the same * @see ReactiveX operators documentation: SequenceEqual */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Single sequenceEqual(ObservableSource source1, ObservableSource source2) { return sequenceEqual(source1, source2, ObjectHelper.equalsPredicate(), bufferSize()); } /** * Returns a Single that emits a Boolean value that indicates whether two ObservableSource sequences are the * same by comparing the items emitted by each ObservableSource pairwise based on the results of a specified * equality function. *

* *

*
Scheduler:
*
{@code sequenceEqual} does not operate by default on a particular {@link Scheduler}.
*
* * @param source1 * the first ObservableSource to compare * @param source2 * the second ObservableSource to compare * @param isEqual * a function used to compare items emitted by each ObservableSource * @param * the type of items emitted by each ObservableSource * @return a Single that emits a Boolean value that indicates whether the two ObservableSource two sequences * are the same according to the specified function * @see ReactiveX operators documentation: SequenceEqual */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Single sequenceEqual(ObservableSource source1, ObservableSource source2, BiPredicate isEqual) { return sequenceEqual(source1, source2, isEqual, bufferSize()); } /** * Returns a Single that emits a Boolean value that indicates whether two ObservableSource sequences are the * same by comparing the items emitted by each ObservableSource pairwise based on the results of a specified * equality function. *

* *

*
Scheduler:
*
{@code sequenceEqual} does not operate by default on a particular {@link Scheduler}.
*
* * @param source1 * the first ObservableSource to compare * @param source2 * the second ObservableSource to compare * @param isEqual * a function used to compare items emitted by each ObservableSource * @param bufferSize * the number of items to prefetch from the first and second source ObservableSource * @param * the type of items emitted by each ObservableSource * @return an Observable that emits a Boolean value that indicates whether the two ObservableSource two sequences * are the same according to the specified function * @see ReactiveX operators documentation: SequenceEqual */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Single sequenceEqual(ObservableSource source1, ObservableSource source2, BiPredicate isEqual, int bufferSize) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(isEqual, "isEqual is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return RxJavaPlugins.onAssembly(new ObservableSequenceEqualSingle(source1, source2, isEqual, bufferSize)); } /** * Returns a Single that emits a Boolean value that indicates whether two ObservableSource sequences are the * same by comparing the items emitted by each ObservableSource pairwise. *

* *

*
Scheduler:
*
{@code sequenceEqual} does not operate by default on a particular {@link Scheduler}.
*
* * @param source1 * the first ObservableSource to compare * @param source2 * the second ObservableSource to compare * @param bufferSize * the number of items to prefetch from the first and second source ObservableSource * @param * the type of items emitted by each ObservableSource * @return a Single that emits a Boolean value that indicates whether the two sequences are the same * @see ReactiveX operators documentation: SequenceEqual */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Single sequenceEqual(ObservableSource source1, ObservableSource source2, int bufferSize) { return sequenceEqual(source1, source2, ObjectHelper.equalsPredicate(), bufferSize); } /** * Converts an ObservableSource that emits ObservableSources into an ObservableSource that emits the items emitted by the * most recently emitted of those ObservableSources. *

* *

* {@code switchOnNext} subscribes to an ObservableSource that emits ObservableSources. Each time it observes one of * these emitted ObservableSources, the ObservableSource returned by {@code switchOnNext} begins emitting the items * emitted by that ObservableSource. When a new ObservableSource is emitted, {@code switchOnNext} stops emitting items * from the earlier-emitted ObservableSource and begins emitting items from the new one. *

* The resulting ObservableSource completes if both the outer ObservableSource and the last inner ObservableSource, if any, complete. * If the outer ObservableSource signals an onError, the inner ObservableSource is disposed and the error delivered in-sequence. *

*
Scheduler:
*
{@code switchOnNext} does not operate by default on a particular {@link Scheduler}.
*
* * @param the item type * @param sources * the source ObservableSource that emits ObservableSources * @param bufferSize * the number of items to prefetch from the inner ObservableSources * @return an Observable that emits the items emitted by the ObservableSource most recently emitted by the source * ObservableSource * @see ReactiveX operators documentation: Switch */ @SuppressWarnings({ "rawtypes", "unchecked" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable switchOnNext(ObservableSource> sources, int bufferSize) { ObjectHelper.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return RxJavaPlugins.onAssembly(new ObservableSwitchMap(sources, Functions.identity(), bufferSize, false)); } /** * Converts an ObservableSource that emits ObservableSources into an ObservableSource that emits the items emitted by the * most recently emitted of those ObservableSources. *

* *

* {@code switchOnNext} subscribes to an ObservableSource that emits ObservableSources. Each time it observes one of * these emitted ObservableSources, the ObservableSource returned by {@code switchOnNext} begins emitting the items * emitted by that ObservableSource. When a new ObservableSource is emitted, {@code switchOnNext} stops emitting items * from the earlier-emitted ObservableSource and begins emitting items from the new one. *

* The resulting ObservableSource completes if both the outer ObservableSource and the last inner ObservableSource, if any, complete. * If the outer ObservableSource signals an onError, the inner ObservableSource is disposed and the error delivered in-sequence. *

*
Scheduler:
*
{@code switchOnNext} does not operate by default on a particular {@link Scheduler}.
*
* * @param the item type * @param sources * the source ObservableSource that emits ObservableSources * @return an Observable that emits the items emitted by the ObservableSource most recently emitted by the source * ObservableSource * @see ReactiveX operators documentation: Switch */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable switchOnNext(ObservableSource> sources) { return switchOnNext(sources, bufferSize()); } /** * Converts an ObservableSource that emits ObservableSources into an ObservableSource that emits the items emitted by the * most recently emitted of those ObservableSources and delays any exception until all ObservableSources terminate. *

* *

* {@code switchOnNext} subscribes to an ObservableSource that emits ObservableSources. Each time it observes one of * these emitted ObservableSources, the ObservableSource returned by {@code switchOnNext} begins emitting the items * emitted by that ObservableSource. When a new ObservableSource is emitted, {@code switchOnNext} stops emitting items * from the earlier-emitted ObservableSource and begins emitting items from the new one. *

* The resulting ObservableSource completes if both the main ObservableSource and the last inner ObservableSource, if any, complete. * If the main ObservableSource signals an onError, the termination of the last inner ObservableSource will emit that error as is * or wrapped into a CompositeException along with the other possible errors the former inner ObservableSources signalled. *

*
Scheduler:
*
{@code switchOnNextDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the item type * @param sources * the source ObservableSource that emits ObservableSources * @return an Observable that emits the items emitted by the ObservableSource most recently emitted by the source * ObservableSource * @see ReactiveX operators documentation: Switch * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable switchOnNextDelayError(ObservableSource> sources) { return switchOnNextDelayError(sources, bufferSize()); } /** * Converts an ObservableSource that emits ObservableSources into an ObservableSource that emits the items emitted by the * most recently emitted of those ObservableSources and delays any exception until all ObservableSources terminate. *

* *

* {@code switchOnNext} subscribes to an ObservableSource that emits ObservableSources. Each time it observes one of * these emitted ObservableSources, the ObservableSource returned by {@code switchOnNext} begins emitting the items * emitted by that ObservableSource. When a new ObservableSource is emitted, {@code switchOnNext} stops emitting items * from the earlier-emitted ObservableSource and begins emitting items from the new one. *

* The resulting ObservableSource completes if both the main ObservableSource and the last inner ObservableSource, if any, complete. * If the main ObservableSource signals an onError, the termination of the last inner ObservableSource will emit that error as is * or wrapped into a CompositeException along with the other possible errors the former inner ObservableSources signalled. *

*
Scheduler:
*
{@code switchOnNextDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the item type * @param sources * the source ObservableSource that emits ObservableSources * @param prefetch * the number of items to prefetch from the inner ObservableSources * @return an Observable that emits the items emitted by the ObservableSource most recently emitted by the source * ObservableSource * @see ReactiveX operators documentation: Switch * @since 2.0 */ @SuppressWarnings({ "rawtypes", "unchecked" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable switchOnNextDelayError(ObservableSource> sources, int prefetch) { ObjectHelper.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); return RxJavaPlugins.onAssembly(new ObservableSwitchMap(sources, Functions.identity(), prefetch, true)); } /** * Returns an Observable that emits {@code 0L} after a specified delay, and then completes. *

* *

*
Scheduler:
*
{@code timer} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param delay * the initial delay before emitting a single {@code 0L} * @param unit * time units to use for {@code delay} * @return an Observable that {@code 0L} after a specified delay, and then completes * @see ReactiveX operators documentation: Timer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public static Observable timer(long delay, TimeUnit unit) { return timer(delay, unit, Schedulers.computation()); } /** * Returns an Observable that emits {@code 0L} after a specified delay, on a specified Scheduler, and then * completes. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param delay * the initial delay before emitting a single 0L * @param unit * time units to use for {@code delay} * @param scheduler * the {@link Scheduler} to use for scheduling the item * @throws NullPointerException * if {@code unit} is null, or * if {@code scheduler} is null * @return an Observable that emits {@code 0L} after a specified delay, on a specified Scheduler, and then * completes * @see ReactiveX operators documentation: Timer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public static Observable timer(long delay, TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new ObservableTimer(Math.max(delay, 0L), unit, scheduler)); } /** * Create an Observable by wrapping an ObservableSource which has to be implemented according * to the Reactive Streams based Observable specification by handling * disposal correctly; no safeguards are provided by the Observable itself. *
*
Scheduler:
*
{@code unsafeCreate} by default doesn't operate on any particular {@link Scheduler}.
*
* @param the value type emitted * @param onSubscribe the ObservableSource instance to wrap * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable unsafeCreate(ObservableSource onSubscribe) { ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null"); if (onSubscribe instanceof Observable) { throw new IllegalArgumentException("unsafeCreate(Observable) should be upgraded"); } return RxJavaPlugins.onAssembly(new ObservableFromUnsafeSource(onSubscribe)); } /** * Constructs an ObservableSource that creates a dependent resource object which is disposed of when the downstream * calls dispose(). *

* *

*
Scheduler:
*
{@code using} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the generated ObservableSource * @param the type of the resource associated with the output sequence * @param resourceSupplier * the factory function to create a resource object that depends on the ObservableSource * @param sourceSupplier * the factory function to create an ObservableSource * @param disposer * the function that will dispose of the resource * @return the ObservableSource whose lifetime controls the lifetime of the dependent resource object * @see ReactiveX operators documentation: Using */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable using(Callable resourceSupplier, Function> sourceSupplier, Consumer disposer) { return using(resourceSupplier, sourceSupplier, disposer, true); } /** * Constructs an ObservableSource that creates a dependent resource object which is disposed of just before * termination if you have set {@code disposeEagerly} to {@code true} and a dispose() call does not occur * before termination. Otherwise resource disposal will occur on a dispose() call. Eager disposal is * particularly appropriate for a synchronous ObservableSource that reuses resources. {@code disposeAction} will * only be called once per subscription. *

* *

*
Scheduler:
*
{@code using} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the generated ObservableSource * @param the type of the resource associated with the output sequence * @param resourceSupplier * the factory function to create a resource object that depends on the ObservableSource * @param sourceSupplier * the factory function to create an ObservableSource * @param disposer * the function that will dispose of the resource * @param eager * if {@code true} then disposal will happen either on a dispose() call or just before emission of * a terminal event ({@code onComplete} or {@code onError}). * @return the ObservableSource whose lifetime controls the lifetime of the dependent resource object * @see ReactiveX operators documentation: Using * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable using(Callable resourceSupplier, Function> sourceSupplier, Consumer disposer, boolean eager) { ObjectHelper.requireNonNull(resourceSupplier, "resourceSupplier is null"); ObjectHelper.requireNonNull(sourceSupplier, "sourceSupplier is null"); ObjectHelper.requireNonNull(disposer, "disposer is null"); return RxJavaPlugins.onAssembly(new ObservableUsing(resourceSupplier, sourceSupplier, disposer, eager)); } /** * Wraps an ObservableSource into an Observable if not already an Observable. * *
*
Scheduler:
*
{@code wrap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type * @param source the source ObservableSource instance * @return the new Observable instance or the same as the source * @throws NullPointerException if source is null */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable wrap(ObservableSource source) { ObjectHelper.requireNonNull(source, "source is null"); if (source instanceof Observable) { return RxJavaPlugins.onAssembly((Observable)source); } return RxJavaPlugins.onAssembly(new ObservableFromUnsafeSource(source)); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * items emitted, in sequence, by an Iterable of other ObservableSources. *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by each of the source ObservableSources; * the second item emitted by the new ObservableSource will be the result of the function applied to the second * item emitted by each of those ObservableSources; and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@code onNext} as many times as * the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} 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 {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. * *

* *

*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common value type * @param the zipped result type * @param sources * an Iterable of source ObservableSources * @param zipper * a function that, when applied to an item emitted by each of the source ObservableSources, results in * an item that will be emitted by the resulting ObservableSource * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zip(Iterable> sources, Function zipper) { ObjectHelper.requireNonNull(zipper, "zipper is null"); ObjectHelper.requireNonNull(sources, "sources is null"); return RxJavaPlugins.onAssembly(new ObservableZip(null, sources, zipper, bufferSize(), false)); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * n items emitted, in sequence, by the n ObservableSources emitted by a specified ObservableSource. *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by each of the ObservableSources emitted * by the source ObservableSource; the second item emitted by the new ObservableSource will be the result of the * function applied to the second item emitted by each of those ObservableSources; and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@code onNext} as many times as * the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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(just(range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2)), (a) -> a)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} 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 {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. * *

* *

*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the inner ObservableSources * @param the zipped result type * @param sources * an ObservableSource of source ObservableSources * @param zipper * a function that, when applied to an item emitted by each of the ObservableSources emitted by * {@code ws}, results in an item that will be emitted by the resulting ObservableSource * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings({ "rawtypes", "unchecked" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zip(ObservableSource> sources, final Function zipper) { ObjectHelper.requireNonNull(zipper, "zipper is null"); ObjectHelper.requireNonNull(sources, "sources is null"); return RxJavaPlugins.onAssembly(new ObservableToList(sources, 16) .flatMap(ObservableInternalHelper.zipIterable(zipper))); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * two items emitted, in sequence, by two other ObservableSources. *

* *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by {@code o1} and the first item * emitted by {@code o2}; the second item emitted by the new ObservableSource will be the result of the function * applied to the second item emitted by {@code o1} and the second item emitted by {@code o2}; and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@link Observer#onNext onNext} * as many times as the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} to do cleanup in case of completion * or a dispose() call. *
*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the zipped result type * @param source1 * the first source ObservableSource * @param source2 * a second source ObservableSource * @param zipper * a function that, when applied to an item emitted by each of the source ObservableSources, results * in an item that will be emitted by the resulting ObservableSource * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zip( ObservableSource source1, ObservableSource source2, BiFunction zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * two items emitted, in sequence, by two other ObservableSources. *

* *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by {@code o1} and the first item * emitted by {@code o2}; the second item emitted by the new ObservableSource will be the result of the function * applied to the second item emitted by {@code o1} and the second item emitted by {@code o2}; and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@link Observer#onNext onNext} * as many times as the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} to do cleanup in case of completion * or a dispose() call. *
*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the zipped result type * @param source1 * the first source ObservableSource * @param source2 * a second source ObservableSource * @param zipper * a function that, when applied to an item emitted by each of the source ObservableSources, results * in an item that will be emitted by the resulting ObservableSource * @param delayError delay errors from any of the source ObservableSources till the other terminates * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zip( ObservableSource source1, ObservableSource source2, BiFunction zipper, boolean delayError) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); return zipArray(Functions.toFunction(zipper), delayError, bufferSize(), source1, source2); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * two items emitted, in sequence, by two other ObservableSources. *

* *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by {@code o1} and the first item * emitted by {@code o2}; the second item emitted by the new ObservableSource will be the result of the function * applied to the second item emitted by {@code o1} and the second item emitted by {@code o2}; and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@link Observer#onNext onNext} * as many times as the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} to do cleanup in case of completion * or a dispose() call. *
*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the zipped result type * @param source1 * the first source ObservableSource * @param source2 * a second source ObservableSource * @param zipper * a function that, when applied to an item emitted by each of the source ObservableSources, results * in an item that will be emitted by the resulting ObservableSource * @param delayError delay errors from any of the source ObservableSources till the other terminates * @param bufferSize the number of elements to prefetch from each source ObservableSource * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zip( ObservableSource source1, ObservableSource source2, BiFunction zipper, boolean delayError, int bufferSize) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); return zipArray(Functions.toFunction(zipper), delayError, bufferSize, source1, source2); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * three items emitted, in sequence, by three other ObservableSources. *

* *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by {@code o1}, the first item * emitted by {@code o2}, and the first item emitted by {@code o3}; the second item emitted by the new * ObservableSource will be the result of the function applied to the second item emitted by {@code o1}, the * second item emitted by {@code o2}, and the second item emitted by {@code o3}; and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@link Observer#onNext onNext} * as many times as the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} to do cleanup in case of completion * or a dispose() call. *
*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the zipped result type * @param source1 * the first source ObservableSource * @param source2 * a second source ObservableSource * @param source3 * a third source ObservableSource * @param zipper * a function that, when applied to an item emitted by each of the source ObservableSources, results in * an item that will be emitted by the resulting ObservableSource * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zip( ObservableSource source1, ObservableSource source2, ObservableSource source3, Function3 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * four items emitted, in sequence, by four other ObservableSources. *

* *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by {@code o1}, the first item * emitted by {@code o2}, the first item emitted by {@code o3}, and the first item emitted by {@code 04}; * the second item emitted by the new ObservableSource will be the result of the function applied to the second * item emitted by each of those ObservableSources; and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@link Observer#onNext onNext} * as many times as the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} to do cleanup in case of completion * or a dispose() call. *
*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the value type of the fourth source * @param the zipped result type * @param source1 * the first source ObservableSource * @param source2 * a second source ObservableSource * @param source3 * a third source ObservableSource * @param source4 * a fourth source ObservableSource * @param zipper * a function that, when applied to an item emitted by each of the source ObservableSources, results in * an item that will be emitted by the resulting ObservableSource * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zip( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4, Function4 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * five items emitted, in sequence, by five other ObservableSources. *

* *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by {@code o1}, the first item * emitted by {@code o2}, the first item emitted by {@code o3}, the first item emitted by {@code o4}, and * the first item emitted by {@code o5}; the second item emitted by the new ObservableSource will be the result of * the function applied to the second item emitted by each of those ObservableSources; and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@link Observer#onNext onNext} * as many times as the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} to do cleanup in case of completion * or a dispose() call. *
*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the value type of the fourth source * @param the value type of the fifth source * @param the zipped result type * @param source1 * the first source ObservableSource * @param source2 * a second source ObservableSource * @param source3 * a third source ObservableSource * @param source4 * a fourth source ObservableSource * @param source5 * a fifth source ObservableSource * @param zipper * a function that, when applied to an item emitted by each of the source ObservableSources, results in * an item that will be emitted by the resulting ObservableSource * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zip( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4, ObservableSource source5, Function5 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * six items emitted, in sequence, by six other ObservableSources. *

* *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by each source ObservableSource, the * second item emitted by the new ObservableSource will be the result of the function applied to the second item * emitted by each of those ObservableSources, and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@link Observer#onNext onNext} * as many times as the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} to do cleanup in case of completion * or a dispose() call. *
*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the value type of the fourth source * @param the value type of the fifth source * @param the value type of the sixth source * @param the zipped result type * @param source1 * the first source ObservableSource * @param source2 * a second source ObservableSource * @param source3 * a third source ObservableSource * @param source4 * a fourth source ObservableSource * @param source5 * a fifth source ObservableSource * @param source6 * a sixth source ObservableSource * @param zipper * a function that, when applied to an item emitted by each of the source ObservableSources, results in * an item that will be emitted by the resulting ObservableSource * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zip( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4, ObservableSource source5, ObservableSource source6, Function6 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); ObjectHelper.requireNonNull(source6, "source6 is null"); return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5, source6); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * seven items emitted, in sequence, by seven other ObservableSources. *

* *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by each source ObservableSource, the * second item emitted by the new ObservableSource will be the result of the function applied to the second item * emitted by each of those ObservableSources, and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@link Observer#onNext onNext} * as many times as the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} to do cleanup in case of completion * or a dispose() call. *
*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the value type of the fourth source * @param the value type of the fifth source * @param the value type of the sixth source * @param the value type of the seventh source * @param the zipped result type * @param source1 * the first source ObservableSource * @param source2 * a second source ObservableSource * @param source3 * a third source ObservableSource * @param source4 * a fourth source ObservableSource * @param source5 * a fifth source ObservableSource * @param source6 * a sixth source ObservableSource * @param source7 * a seventh source ObservableSource * @param zipper * a function that, when applied to an item emitted by each of the source ObservableSources, results in * an item that will be emitted by the resulting ObservableSource * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zip( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4, ObservableSource source5, ObservableSource source6, ObservableSource source7, Function7 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); ObjectHelper.requireNonNull(source6, "source6 is null"); ObjectHelper.requireNonNull(source7, "source7 is null"); return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5, source6, source7); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * eight items emitted, in sequence, by eight other ObservableSources. *

* *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by each source ObservableSource, the * second item emitted by the new ObservableSource will be the result of the function applied to the second item * emitted by each of those ObservableSources, and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@link Observer#onNext onNext} * as many times as the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} to do cleanup in case of completion * or a dispose() call. *
*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the value type of the fourth source * @param the value type of the fifth source * @param the value type of the sixth source * @param the value type of the seventh source * @param the value type of the eighth source * @param the zipped result type * @param source1 * the first source ObservableSource * @param source2 * a second source ObservableSource * @param source3 * a third source ObservableSource * @param source4 * a fourth source ObservableSource * @param source5 * a fifth source ObservableSource * @param source6 * a sixth source ObservableSource * @param source7 * a seventh source ObservableSource * @param source8 * an eighth source ObservableSource * @param zipper * a function that, when applied to an item emitted by each of the source ObservableSources, results in * an item that will be emitted by the resulting ObservableSource * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zip( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4, ObservableSource source5, ObservableSource source6, ObservableSource source7, ObservableSource source8, Function8 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); ObjectHelper.requireNonNull(source6, "source6 is null"); ObjectHelper.requireNonNull(source7, "source7 is null"); ObjectHelper.requireNonNull(source8, "source8 is null"); return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5, source6, source7, source8); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * nine items emitted, in sequence, by nine other ObservableSources. *

* *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by each source ObservableSource, the * second item emitted by the new ObservableSource will be the result of the function applied to the second item * emitted by each of those ObservableSources, and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@link Observer#onNext onNext} * as many times as the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} to do cleanup in case of completion * or a dispose() call. *
*
Scheduler:
*
{@code zip} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the first source * @param the value type of the second source * @param the value type of the third source * @param the value type of the fourth source * @param the value type of the fifth source * @param the value type of the sixth source * @param the value type of the seventh source * @param the value type of the eighth source * @param the value type of the ninth source * @param the zipped result type * @param source1 * the first source ObservableSource * @param source2 * a second source ObservableSource * @param source3 * a third source ObservableSource * @param source4 * a fourth source ObservableSource * @param source5 * a fifth source ObservableSource * @param source6 * a sixth source ObservableSource * @param source7 * a seventh source ObservableSource * @param source8 * an eighth source ObservableSource * @param source9 * a ninth source ObservableSource * @param zipper * a function that, when applied to an item emitted by each of the source ObservableSources, results in * an item that will be emitted by the resulting ObservableSource * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zip( ObservableSource source1, ObservableSource source2, ObservableSource source3, ObservableSource source4, ObservableSource source5, ObservableSource source6, ObservableSource source7, ObservableSource source8, ObservableSource source9, Function9 zipper) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); ObjectHelper.requireNonNull(source5, "source5 is null"); ObjectHelper.requireNonNull(source6, "source6 is null"); ObjectHelper.requireNonNull(source7, "source7 is null"); ObjectHelper.requireNonNull(source8, "source8 is null"); ObjectHelper.requireNonNull(source9, "source9 is null"); return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5, source6, source7, source8, source9); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * items emitted, in sequence, by an array of other ObservableSources. *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by each of the source ObservableSources; * the second item emitted by the new ObservableSource will be the result of the function applied to the second * item emitted by each of those ObservableSources; and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@code onNext} as many times as * the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} 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 {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. * *

* *

*
Scheduler:
*
{@code zipArray} does not operate by default on a particular {@link Scheduler}.
*
* * @param the common element type * @param the result type * @param sources * an array of source ObservableSources * @param zipper * a function that, when applied to an item emitted by each of the source ObservableSources, results in * an item that will be emitted by the resulting ObservableSource * @param delayError * delay errors signalled by any of the source ObservableSource until all ObservableSources terminate * @param bufferSize * the number of elements to prefetch from each source ObservableSource * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zipArray(Function zipper, boolean delayError, int bufferSize, ObservableSource... sources) { if (sources.length == 0) { return empty(); } ObjectHelper.requireNonNull(zipper, "zipper is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return RxJavaPlugins.onAssembly(new ObservableZip(sources, null, zipper, bufferSize, delayError)); } /** * Returns an Observable that emits the results of a specified combiner function applied to combinations of * items emitted, in sequence, by an Iterable of other ObservableSources. *

* {@code zip} applies this function in strict sequence, so the first item emitted by the new ObservableSource * will be the result of the function applied to the first item emitted by each of the source ObservableSources; * the second item emitted by the new ObservableSource will be the result of the function applied to the second * item emitted by each of those ObservableSources; and so forth. *

* The resulting {@code ObservableSource} returned from {@code zip} will invoke {@code onNext} as many times as * the number of {@code onNext} invocations of the source ObservableSource that 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} 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 {@code new T[]}, the * implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a * {@code Function} passed to the method would trigger a {@code ClassCastException}. * *

* *

*
Scheduler:
*
{@code zipIterable} does not operate by default on a particular {@link Scheduler}.
*
* * * @param sources * an Iterable of source ObservableSources * @param zipper * a function that, when applied to an item emitted by each of the source ObservableSources, results in * an item that will be emitted by the resulting ObservableSource * @param delayError * delay errors signalled by any of the source ObservableSource until all ObservableSources terminate * @param bufferSize * the number of elements to prefetch from each source ObservableSource * @param the common source value type * @param the zipped result type * @return an Observable that emits the zipped results * @see ReactiveX operators documentation: Zip */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Observable zipIterable(Iterable> sources, Function zipper, boolean delayError, int bufferSize) { ObjectHelper.requireNonNull(zipper, "zipper is null"); ObjectHelper.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return RxJavaPlugins.onAssembly(new ObservableZip(null, sources, zipper, bufferSize, delayError)); } // *************************************************************************************************** // Instance operators // *************************************************************************************************** /** * Returns a Single that emits a Boolean that indicates whether all of the items emitted by the source * ObservableSource satisfy a condition. *

* *

*
Scheduler:
*
{@code all} does not operate by default on a particular {@link Scheduler}.
*
* * @param predicate * a function that evaluates an item and returns a Boolean * @return a Single that emits {@code true} if all items emitted by the source ObservableSource satisfy the * predicate; otherwise, {@code false} * @see ReactiveX operators documentation: All */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single all(Predicate predicate) { ObjectHelper.requireNonNull(predicate, "predicate is null"); return RxJavaPlugins.onAssembly(new ObservableAllSingle(this, predicate)); } /** * Mirrors the ObservableSource (current or provided) that first either emits an item or sends a termination * notification. *

* *

*
Scheduler:
*
{@code ambWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param other * an ObservableSource competing to react first. A subscription to this provided source will occur after * subscribing to the current source. * @return an Observable that emits the same sequence as whichever of the source ObservableSources first * emitted an item or sent a termination notification * @see ReactiveX operators documentation: Amb */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable ambWith(ObservableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return ambArray(this, other); } /** * Returns a Single that emits {@code true} if any item emitted by the source ObservableSource satisfies a * specified condition, otherwise {@code false}. Note: this always emits {@code false} if the * source ObservableSource is empty. *

* *

* In Rx.Net this is the {@code any} Observer but we renamed it in RxJava to better match Java naming * idioms. *

*
Scheduler:
*
{@code any} does not operate by default on a particular {@link Scheduler}.
*
* * @param predicate * the condition to test items emitted by the source ObservableSource * @return a Single that emits a Boolean that indicates whether any item emitted by the source * ObservableSource satisfies the {@code predicate} * @see ReactiveX operators documentation: Contains */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single any(Predicate predicate) { ObjectHelper.requireNonNull(predicate, "predicate is null"); return RxJavaPlugins.onAssembly(new ObservableAnySingle(this, predicate)); } /** * Calls the specified converter function during assembly time and returns its resulting value. *

* This allows fluent conversion to any other type. *

*
Scheduler:
*
{@code as} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.7 - experimental * @param the resulting object type * @param converter the function that receives the current Observable instance and returns a value * @return the converted value * @throws NullPointerException if converter is null * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final R as(@NonNull ObservableConverter converter) { return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); } /** * Returns the first item emitted by this {@code Observable}, or throws * {@code NoSuchElementException} if it emits no items. *

* *

*
Scheduler:
*
{@code blockingFirst} does not operate by default on a particular {@link Scheduler}.
*
* * @return the first item emitted by this {@code Observable} * @throws NoSuchElementException * if this {@code Observable} emits no items * @see ReactiveX documentation: First */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final T blockingFirst() { BlockingFirstObserver observer = new BlockingFirstObserver(); subscribe(observer); T v = observer.blockingGet(); if (v != null) { return v; } throw new NoSuchElementException(); } /** * Returns the first item emitted by this {@code Observable}, or a default value if it emits no * items. *

* *

*
Scheduler:
*
{@code blockingFirst} does not operate by default on a particular {@link Scheduler}.
*
* * @param defaultItem * a default value to return if this {@code Observable} emits no items * @return the first item emitted by this {@code Observable}, or the default value if it emits no * items * @see ReactiveX documentation: First */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final T blockingFirst(T defaultItem) { BlockingFirstObserver observer = new BlockingFirstObserver(); subscribe(observer); T v = observer.blockingGet(); return v != null ? v : defaultItem; } /** * Consumes the upstream {@code Observable} in a blocking fashion and invokes the given * {@code Consumer} with 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 {@code Consumer} on the current thread while * {@link #subscribe(Consumer)} executes the consumer on the original caller thread of the * sequence. *

*
Scheduler:
*
{@code blockingForEach} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If the source signals an error, the operator wraps a checked {@link Exception} * into {@link RuntimeException} and throws that. Otherwise, {@code RuntimeException}s and * {@link Error}s are rethrown as they are.
*
* * @param onNext * the {@link Consumer} to invoke for each item emitted by the {@code Observable} * @throws RuntimeException * if an error occurs * @see ReactiveX documentation: Subscribe * @see #subscribe(Consumer) */ @SchedulerSupport(SchedulerSupport.NONE) public final void blockingForEach(Consumer onNext) { Iterator it = blockingIterable().iterator(); while (it.hasNext()) { try { onNext.accept(it.next()); } catch (Throwable e) { Exceptions.throwIfFatal(e); ((Disposable)it).dispose(); throw ExceptionHelper.wrapOrThrow(e); } } } /** * Converts this {@code Observable} into an {@link Iterable}. *

* *

*
Scheduler:
*
{@code blockingIterable} does not operate by default on a particular {@link Scheduler}.
*
* * @return an {@link Iterable} version of this {@code Observable} * @see ReactiveX documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Iterable blockingIterable() { return blockingIterable(bufferSize()); } /** * Converts this {@code Observable} into an {@link Iterable}. *

* *

*
Scheduler:
*
{@code blockingIterable} does not operate by default on a particular {@link Scheduler}.
*
* * @param bufferSize the number of items to prefetch from the current Observable * @return an {@link Iterable} version of this {@code Observable} * @see ReactiveX documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Iterable blockingIterable(int bufferSize) { ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return new BlockingObservableIterable(this, bufferSize); } /** * Returns the last item emitted by this {@code Observable}, or throws * {@code NoSuchElementException} if this {@code Observable} emits no items. *

* *

*
Scheduler:
*
{@code blockingLast} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If the source signals an error, the operator wraps a checked {@link Exception} * into {@link RuntimeException} and throws that. Otherwise, {@code RuntimeException}s and * {@link Error}s are rethrown as they are.
*
* * @return the last item emitted by this {@code Observable} * @throws NoSuchElementException * if this {@code Observable} emits no items * @see ReactiveX documentation: Last */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final T blockingLast() { BlockingLastObserver observer = new BlockingLastObserver(); subscribe(observer); T v = observer.blockingGet(); if (v != null) { return v; } throw new NoSuchElementException(); } /** * Returns the last item emitted by this {@code Observable}, or a default value if it emits no * items. *

* *

*
Scheduler:
*
{@code blockingLast} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If the source signals an error, the operator wraps a checked {@link Exception} * into {@link RuntimeException} and throws that. Otherwise, {@code RuntimeException}s and * {@link Error}s are rethrown as they are.
*
* * @param defaultItem * a default value to return if this {@code Observable} emits no items * @return the last item emitted by the {@code Observable}, or the default value if it emits no * items * @see ReactiveX documentation: Last */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final T blockingLast(T defaultItem) { BlockingLastObserver observer = new BlockingLastObserver(); subscribe(observer); T v = observer.blockingGet(); return v != null ? v : defaultItem; } /** * Returns an {@link Iterable} that returns the latest item emitted by this {@code Observable}, * waiting if necessary for one to become available. *

* *

* If this {@code Observable} produces items faster than {@code Iterator.next} takes them, * {@code onNext} events might be skipped, but {@code onError} or {@code onComplete} events are not. *

* Note also that an {@code onNext} directly followed by {@code onComplete} might hide the {@code onNext} * event. *

*
Scheduler:
*
{@code blockingLatest} does not operate by default on a particular {@link Scheduler}.
*
* * @return an Iterable that always returns the latest item emitted by this {@code Observable} * @see ReactiveX documentation: First */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Iterable blockingLatest() { return new BlockingObservableLatest(this); } /** * Returns an {@link Iterable} that always returns the item most recently emitted by this * {@code Observable}. *

* *

*
Scheduler:
*
{@code blockingMostRecent} does not operate by default on a particular {@link Scheduler}.
*
* * @param initialValue * the initial value that the {@link Iterable} sequence will yield if this * {@code Observable} has not yet emitted an item * @return an {@link Iterable} that on each iteration returns the item that this {@code Observable} * has most recently emitted * @see ReactiveX documentation: First */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Iterable blockingMostRecent(T initialValue) { return new BlockingObservableMostRecent(this, initialValue); } /** * Returns an {@link Iterable} that blocks until this {@code Observable} emits another item, then * returns that item. *

* *

*
Scheduler:
*
{@code blockingNext} does not operate by default on a particular {@link Scheduler}.
*
* * @return an {@link Iterable} that blocks upon each iteration until this {@code Observable} emits * a new item, whereupon the Iterable returns that item * @see ReactiveX documentation: TakeLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Iterable blockingNext() { return new BlockingObservableNext(this); } /** * If this {@code Observable} completes after emitting a single item, return that item, otherwise * throw a {@code NoSuchElementException}. *

* *

*
Scheduler:
*
{@code blockingSingle} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If the source signals an error, the operator wraps a checked {@link Exception} * into {@link RuntimeException} and throws that. Otherwise, {@code RuntimeException}s and * {@link Error}s are rethrown as they are.
*
* * @return the single item emitted by this {@code Observable} * @see ReactiveX documentation: First */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final T blockingSingle() { T v = singleElement().blockingGet(); if (v == null) { throw new NoSuchElementException(); } return v; } /** * If this {@code Observable} completes after emitting a single item, return that item; if it emits * more than one item, throw an {@code IllegalArgumentException}; if it emits no items, return a default * value. *

* *

*
Scheduler:
*
{@code blockingSingle} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If the source signals an error, the operator wraps a checked {@link Exception} * into {@link RuntimeException} and throws that. Otherwise, {@code RuntimeException}s and * {@link Error}s are rethrown as they are.
*
* * @param defaultItem * a default value to return if this {@code Observable} emits no items * @return the single item emitted by this {@code Observable}, or the default value if it emits no * items * @see ReactiveX documentation: First */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final T blockingSingle(T defaultItem) { return single(defaultItem).blockingGet(); } /** * Returns a {@link Future} representing the only value emitted by this {@code Observable}. *

* *

* If the {@link Observable} emits more than one item, {@link java.util.concurrent.Future} will receive an * {@link java.lang.IndexOutOfBoundsException}. If the {@link Observable} is empty, {@link java.util.concurrent.Future} * will receive an {@link java.util.NoSuchElementException}. The {@code Observable} source has to terminate in order * for the returned {@code Future} to terminate as well. *

* If the {@code Observable} may emit more than one item, use {@code Observable.toList().toFuture()}. *

*
Scheduler:
*
{@code toFuture} does not operate by default on a particular {@link Scheduler}.
*
* * @return a {@link Future} that expects a single item to be emitted by this {@code Observable} * @see ReactiveX documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Future toFuture() { return subscribeWith(new FutureObserver()); } /** * Runs the source observable to 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:
*
{@code blockingSubscribe} does not operate by default on a particular {@link Scheduler}.
*
* @since 2.0 * @see #blockingSubscribe(Consumer) * @see #blockingSubscribe(Consumer, Consumer) * @see #blockingSubscribe(Consumer, Consumer, Action) */ @SchedulerSupport(SchedulerSupport.NONE) public final void blockingSubscribe() { ObservableBlockingSubscribe.subscribe(this); } /** * Subscribes to the source and calls the given callbacks on the current thread. *

* *

* If the {@code Observable} emits an error, it is wrapped into an * {@link io.reactivex.exceptions.OnErrorNotImplementedException OnErrorNotImplementedException} * and routed to the RxJavaPlugins.onError handler. * Using the overloads {@link #blockingSubscribe(Consumer, Consumer)} * or {@link #blockingSubscribe(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:
*
{@code blockingSubscribe} does not operate by default on a particular {@link Scheduler}.
*
* @param onNext the callback action for each source value * @since 2.0 * @see #blockingSubscribe(Consumer, Consumer) * @see #blockingSubscribe(Consumer, Consumer, Action) */ @SchedulerSupport(SchedulerSupport.NONE) public final void blockingSubscribe(Consumer onNext) { ObservableBlockingSubscribe.subscribe(this, onNext, Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION); } /** * 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:
*
{@code blockingSubscribe} does not operate by default on a particular {@link Scheduler}.
*
* @param onNext the callback action for each source value * @param onError the callback action for an error event * @since 2.0 * @see #blockingSubscribe(Consumer, Consumer, Action) */ @SchedulerSupport(SchedulerSupport.NONE) public final void blockingSubscribe(Consumer onNext, Consumer onError) { ObservableBlockingSubscribe.subscribe(this, onNext, onError, Functions.EMPTY_ACTION); } /** * 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:
*
{@code blockingSubscribe} does not operate by default on a particular {@link Scheduler}.
*
* @param onNext the callback action for each source value * @param onError the callback action for an error event * @param onComplete the callback action for the completion event. * @since 2.0 */ @SchedulerSupport(SchedulerSupport.NONE) public final void blockingSubscribe(Consumer onNext, Consumer onError, Action onComplete) { ObservableBlockingSubscribe.subscribe(this, onNext, onError, onComplete); } /** * Subscribes to the source and calls the {@link Observer} methods on the current thread. *

* Note that calling this method will block the caller thread until the upstream terminates * normally, with an error or the {@code Observer} disposes the {@link Disposable} it receives via * {@link Observer#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:
*
{@code blockingSubscribe} does not operate by default on a particular {@link Scheduler}.
*
* The a dispose() call is composed through. * @param observer the {@code Observer} instance to forward events and calls to in the current thread * @since 2.0 */ @SchedulerSupport(SchedulerSupport.NONE) public final void blockingSubscribe(Observer observer) { ObservableBlockingSubscribe.subscribe(this, observer); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping buffers, each containing {@code count} items. When the source * ObservableSource completes, the resulting ObservableSource emits the current buffer and propagates the notification * from the source ObservableSource. Note that if the source ObservableSource issues an onError notification * the event is passed on immediately without first emitting the buffer it is in the process of assembling. *

* *

*
Scheduler:
*
This version of {@code buffer} does not operate by default on a particular {@link Scheduler}.
*
* * @param count * the maximum number of items in each buffer before it should be emitted * @return an Observable that emits connected, non-overlapping buffers, each containing at most * {@code count} items from the source ObservableSource * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> buffer(int count) { return buffer(count, count); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource emits buffers every {@code skip} items, each containing {@code count} items. When the source * ObservableSource completes, the resulting ObservableSource emits the current buffer and propagates the notification * from the source ObservableSource. Note that if the source ObservableSource issues an onError notification * the event is passed on immediately without first emitting the buffer it is in the process of assembling. *

* *

*
Scheduler:
*
This version of {@code buffer} does not operate by default on a particular {@link Scheduler}.
*
* * @param count * the maximum size of each buffer before it should be emitted * @param skip * how many items emitted by the source ObservableSource should be skipped before starting a new * buffer. Note that when {@code skip} and {@code count} are equal, this is the same operation as * {@link #buffer(int)}. * @return an Observable that emits buffers for every {@code skip} item from the source ObservableSource and * containing at most {@code count} items * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> buffer(int count, int skip) { return buffer(count, skip, ArrayListSupplier.asCallable()); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource emits buffers every {@code skip} items, each containing {@code count} items. When the source * ObservableSource completes, the resulting ObservableSource emits the current buffer and propagates the notification * from the source ObservableSource. Note that if the source ObservableSource issues an onError notification * the event is passed on immediately without first emitting the buffer it is in the process of assembling. *

* *

*
Scheduler:
*
This version of {@code buffer} does not operate by default on a particular {@link Scheduler}.
*
* * @param the collection subclass type to buffer into * @param count * the maximum size of each buffer before it should be emitted * @param skip * how many items emitted by the source ObservableSource should be skipped before starting a new * buffer. Note that when {@code skip} and {@code count} are equal, this is the same operation as * {@link #buffer(int)}. * @param bufferSupplier * a factory function that returns an instance of the collection subclass to be used and returned * as the buffer * @return an Observable that emits buffers for every {@code skip} item from the source ObservableSource and * containing at most {@code count} items * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final > Observable buffer(int count, int skip, Callable bufferSupplier) { ObjectHelper.verifyPositive(count, "count"); ObjectHelper.verifyPositive(skip, "skip"); ObjectHelper.requireNonNull(bufferSupplier, "bufferSupplier is null"); return RxJavaPlugins.onAssembly(new ObservableBuffer(this, count, skip, bufferSupplier)); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping buffers, each containing {@code count} items. When the source * ObservableSource completes, the resulting ObservableSource emits the current buffer and propagates the notification * from the source ObservableSource. Note that if the source ObservableSource issues an onError notification * the event is passed on immediately without first emitting the buffer it is in the process of assembling. *

* *

*
Scheduler:
*
This version of {@code buffer} does not operate by default on a particular {@link Scheduler}.
*
* * @param the collection subclass type to buffer into * @param count * the maximum number of items in each buffer before it should be emitted * @param bufferSupplier * a factory function that returns an instance of the collection subclass to be used and returned * as the buffer * @return an Observable that emits connected, non-overlapping buffers, each containing at most * {@code count} items from the source ObservableSource * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final > Observable buffer(int count, Callable bufferSupplier) { return buffer(count, count, bufferSupplier); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource starts a new buffer periodically, as determined by the {@code timeskip} argument. It emits * each buffer after a fixed timespan, specified by the {@code timespan} argument. When the source * ObservableSource completes, the resulting ObservableSource emits the current buffer and propagates the notification * from the source ObservableSource. Note that if the source ObservableSource issues an onError notification * the event is passed on immediately without first emitting the buffer it is in the process of assembling. *

* *

*
Scheduler:
*
This version of {@code buffer} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param timespan * the period of time each buffer collects items before it is emitted * @param timeskip * the period of time after which a new buffer will be created * @param unit * the unit of time that applies to the {@code timespan} and {@code timeskip} arguments * @return an Observable that emits new buffers of items emitted by the source ObservableSource periodically after * a fixed timespan has elapsed * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable> buffer(long timespan, long timeskip, TimeUnit unit) { return buffer(timespan, timeskip, unit, Schedulers.computation(), ArrayListSupplier.asCallable()); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource starts a new buffer periodically, as determined by the {@code timeskip} argument, and on the * specified {@code scheduler}. It emits each buffer after a fixed timespan, specified by the * {@code timespan} argument. When the source ObservableSource completes, the resulting ObservableSource emits the * current buffer and propagates the notification from the source ObservableSource. Note that if the source * ObservableSource issues an onError notification the event is passed on immediately without first emitting the * buffer it is in the process of assembling. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param timespan * the period of time each buffer collects items before it is emitted * @param timeskip * the period of time after which a new buffer will be created * @param unit * the unit of time that applies to the {@code timespan} and {@code timeskip} arguments * @param scheduler * the {@link Scheduler} to use when determining the end and start of a buffer * @return an Observable that emits new buffers of items emitted by the source ObservableSource periodically after * a fixed timespan has elapsed * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable> buffer(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler) { return buffer(timespan, timeskip, unit, scheduler, ArrayListSupplier.asCallable()); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource starts a new buffer periodically, as determined by the {@code timeskip} argument, and on the * specified {@code scheduler}. It emits each buffer after a fixed timespan, specified by the * {@code timespan} argument. When the source ObservableSource completes, the resulting ObservableSource emits the * current buffer and propagates the notification from the source ObservableSource. Note that if the source * ObservableSource issues an onError notification the event is passed on immediately without first emitting the * buffer it is in the process of assembling. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param the collection subclass type to buffer into * @param timespan * the period of time each buffer collects items before it is emitted * @param timeskip * the period of time after which a new buffer will be created * @param unit * the unit of time that applies to the {@code timespan} and {@code timeskip} arguments * @param scheduler * the {@link Scheduler} to use when determining the end and start of a buffer * @param bufferSupplier * a factory function that returns an instance of the collection subclass to be used and returned * as the buffer * @return an Observable that emits new buffers of items emitted by the source ObservableSource periodically after * a fixed timespan has elapsed * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final > Observable buffer(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler, Callable bufferSupplier) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); ObjectHelper.requireNonNull(bufferSupplier, "bufferSupplier is null"); return RxJavaPlugins.onAssembly(new ObservableBufferTimed(this, timespan, timeskip, unit, scheduler, bufferSupplier, Integer.MAX_VALUE, false)); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping buffers, each of a fixed duration specified by the * {@code timespan} argument. When the source ObservableSource completes, the resulting ObservableSource emits the * current buffer and propagates the notification from the source ObservableSource. Note that if the source * ObservableSource issues an onError notification the event is passed on immediately without first emitting the * buffer it is in the process of assembling. *

* *

*
Scheduler:
*
This version of {@code buffer} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param timespan * the period of time each buffer collects items before it is emitted and replaced with a new * buffer * @param unit * the unit of time that applies to the {@code timespan} argument * @return an Observable that emits connected, non-overlapping buffers of items emitted by the source * ObservableSource within a fixed duration * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable> buffer(long timespan, TimeUnit unit) { return buffer(timespan, unit, Schedulers.computation(), Integer.MAX_VALUE); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping buffers, each of a fixed duration specified by the * {@code timespan} argument or a maximum size specified by the {@code count} argument (whichever is reached * first). When the source ObservableSource completes, the resulting ObservableSource emits the current buffer and * propagates the notification from the source ObservableSource. Note that if the source ObservableSource issues an * onError notification the event is passed on immediately without first emitting the buffer it is in the process of * assembling. *

* *

*
Scheduler:
*
This version of {@code buffer} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param timespan * the period of time each buffer collects items before it is emitted and replaced with a new * buffer * @param unit * the unit of time which applies to the {@code timespan} argument * @param count * the maximum size of each buffer before it is emitted * @return an Observable that emits connected, non-overlapping buffers of items emitted by the source * ObservableSource, after a fixed duration or when the buffer reaches maximum capacity (whichever occurs * first) * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable> buffer(long timespan, TimeUnit unit, int count) { return buffer(timespan, unit, Schedulers.computation(), count); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping buffers, each of a fixed duration specified by the * {@code timespan} argument as measured on the specified {@code scheduler}, or a maximum size specified by * the {@code count} argument (whichever is reached first). When the source ObservableSource completes, the resulting * ObservableSource emits the current buffer and propagates the notification from the source ObservableSource. Note * that if the source ObservableSource issues an onError notification the event is passed on immediately without * first emitting the buffer it is in the process of assembling. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param timespan * the period of time each buffer collects items before it is emitted and replaced with a new * buffer * @param unit * the unit of time which applies to the {@code timespan} argument * @param scheduler * the {@link Scheduler} to use when determining the end and start of a buffer * @param count * the maximum size of each buffer before it is emitted * @return an Observable that emits connected, non-overlapping buffers of items emitted by the source * ObservableSource after a fixed duration or when the buffer reaches maximum capacity (whichever occurs * first) * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable> buffer(long timespan, TimeUnit unit, Scheduler scheduler, int count) { return buffer(timespan, unit, scheduler, count, ArrayListSupplier.asCallable(), false); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping buffers, each of a fixed duration specified by the * {@code timespan} argument as measured on the specified {@code scheduler}, or a maximum size specified by * the {@code count} argument (whichever is reached first). When the source ObservableSource completes, the resulting * ObservableSource emits the current buffer and propagates the notification from the source ObservableSource. Note * that if the source ObservableSource issues an onError notification the event is passed on immediately without * first emitting the buffer it is in the process of assembling. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param the collection subclass type to buffer into * @param timespan * the period of time each buffer collects items before it is emitted and replaced with a new * buffer * @param unit * the unit of time which applies to the {@code timespan} argument * @param scheduler * the {@link Scheduler} to use when determining the end and start of a buffer * @param count * the maximum size of each buffer before it is emitted * @param bufferSupplier * a factory function that returns an instance of the collection subclass to be used and returned * as the buffer * @param restartTimerOnMaxSize if true the time window is restarted when the max capacity of the current buffer * is reached * @return an Observable that emits connected, non-overlapping buffers of items emitted by the source * ObservableSource after a fixed duration or when the buffer reaches maximum capacity (whichever occurs * first) * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final > Observable buffer( long timespan, TimeUnit unit, Scheduler scheduler, int count, Callable bufferSupplier, boolean restartTimerOnMaxSize) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); ObjectHelper.requireNonNull(bufferSupplier, "bufferSupplier is null"); ObjectHelper.verifyPositive(count, "count"); return RxJavaPlugins.onAssembly(new ObservableBufferTimed(this, timespan, timespan, unit, scheduler, bufferSupplier, count, restartTimerOnMaxSize)); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping buffers, each of a fixed duration specified by the * {@code timespan} argument and on the specified {@code scheduler}. When the source ObservableSource completes, * the resulting ObservableSource emits the current buffer and propagates the notification from the source * ObservableSource. Note that if the source ObservableSource issues an onError notification the event is passed on * immediately without first emitting the buffer it is in the process of assembling. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param timespan * the period of time each buffer collects items before it is emitted and replaced with a new * buffer * @param unit * the unit of time which applies to the {@code timespan} argument * @param scheduler * the {@link Scheduler} to use when determining the end and start of a buffer * @return an Observable that emits connected, non-overlapping buffers of items emitted by the source * ObservableSource within a fixed duration * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable> buffer(long timespan, TimeUnit unit, Scheduler scheduler) { return buffer(timespan, unit, scheduler, Integer.MAX_VALUE, ArrayListSupplier.asCallable(), false); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource emits buffers that it creates when the specified {@code openingIndicator} ObservableSource emits an * item, and closes when the ObservableSource returned from {@code closingIndicator} emits an item. If any of the * source ObservableSource, {@code openingIndicator} or {@code closingIndicator} issues an onError notification the * event is passed on immediately without first emitting the buffer it is in the process of assembling. *

* *

*
Scheduler:
*
This version of {@code buffer} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the buffer-opening ObservableSource * @param the element type of the individual buffer-closing ObservableSources * @param openingIndicator * the ObservableSource that, when it emits an item, causes a new buffer to be created * @param closingIndicator * the {@link Function} that is used to produce an ObservableSource for every buffer created. When this * ObservableSource emits an item, the associated buffer is emitted. * @return an Observable that emits buffers, containing items from the source ObservableSource, that are created * and closed when the specified ObservableSources emit items * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> buffer( ObservableSource openingIndicator, Function> closingIndicator) { return buffer(openingIndicator, closingIndicator, ArrayListSupplier.asCallable()); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource emits buffers that it creates when the specified {@code openingIndicator} ObservableSource emits an * item, and closes when the ObservableSource returned from {@code closingIndicator} emits an item. If any of the * source ObservableSource, {@code openingIndicator} or {@code closingIndicator} issues an onError notification the * event is passed on immediately without first emitting the buffer it is in the process of assembling. *

* *

*
Scheduler:
*
This version of {@code buffer} does not operate by default on a particular {@link Scheduler}.
*
* * @param the collection subclass type to buffer into * @param the element type of the buffer-opening ObservableSource * @param the element type of the individual buffer-closing ObservableSources * @param openingIndicator * the ObservableSource that, when it emits an item, causes a new buffer to be created * @param closingIndicator * the {@link Function} that is used to produce an ObservableSource for every buffer created. When this * ObservableSource emits an item, the associated buffer is emitted. * @param bufferSupplier * a factory function that returns an instance of the collection subclass to be used and returned * as the buffer * @return an Observable that emits buffers, containing items from the source ObservableSource, that are created * and closed when the specified ObservableSources emit items * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final > Observable buffer( ObservableSource openingIndicator, Function> closingIndicator, Callable bufferSupplier) { ObjectHelper.requireNonNull(openingIndicator, "openingIndicator is null"); ObjectHelper.requireNonNull(closingIndicator, "closingIndicator is null"); ObjectHelper.requireNonNull(bufferSupplier, "bufferSupplier is null"); return RxJavaPlugins.onAssembly(new ObservableBufferBoundary(this, openingIndicator, closingIndicator, bufferSupplier)); } /** * Returns an Observable that emits non-overlapping buffered items from the source ObservableSource each time the * specified boundary ObservableSource emits an item. *

* *

* Completion of either the source or the boundary ObservableSource causes the returned ObservableSource to emit the * latest buffer and complete. If either the source ObservableSource or the boundary ObservableSource issues an * onError notification the event is passed on immediately without first emitting the buffer it is in the process of * assembling. *

*
Scheduler:
*
This version of {@code buffer} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the boundary value type (ignored) * @param boundary * the boundary ObservableSource * @return an Observable that emits buffered items from the source ObservableSource when the boundary ObservableSource * emits an item * @see #buffer(ObservableSource, int) * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> buffer(ObservableSource boundary) { return buffer(boundary, ArrayListSupplier.asCallable()); } /** * Returns an Observable that emits non-overlapping buffered items from the source ObservableSource each time the * specified boundary ObservableSource emits an item. *

* *

* Completion of either the source or the boundary ObservableSource causes the returned ObservableSource to emit the * latest buffer and complete. If either the source ObservableSource or the boundary ObservableSource issues an * onError notification the event is passed on immediately without first emitting the buffer it is in the process of * assembling. *

*
Scheduler:
*
This version of {@code buffer} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the boundary value type (ignored) * @param boundary * the boundary ObservableSource * @param initialCapacity * the initial capacity of each buffer chunk * @return an Observable that emits buffered items from the source ObservableSource when the boundary ObservableSource * emits an item * @see ReactiveX operators documentation: Buffer * @see #buffer(ObservableSource) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> buffer(ObservableSource boundary, final int initialCapacity) { ObjectHelper.verifyPositive(initialCapacity, "initialCapacity"); return buffer(boundary, Functions.createArrayList(initialCapacity)); } /** * Returns an Observable that emits non-overlapping buffered items from the source ObservableSource each time the * specified boundary ObservableSource emits an item. *

* *

* Completion of either the source or the boundary ObservableSource causes the returned ObservableSource to emit the * latest buffer and complete. If either the source ObservableSource or the boundary ObservableSource issues an * onError notification the event is passed on immediately without first emitting the buffer it is in the process of * assembling. *

*
Scheduler:
*
This version of {@code buffer} does not operate by default on a particular {@link Scheduler}.
*
* * @param the collection subclass type to buffer into * @param * the boundary value type (ignored) * @param boundary * the boundary ObservableSource * @param bufferSupplier * a factory function that returns an instance of the collection subclass to be used and returned * as the buffer * @return an Observable that emits buffered items from the source ObservableSource when the boundary ObservableSource * emits an item * @see #buffer(ObservableSource, int) * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final > Observable buffer(ObservableSource boundary, Callable bufferSupplier) { ObjectHelper.requireNonNull(boundary, "boundary is null"); ObjectHelper.requireNonNull(bufferSupplier, "bufferSupplier is null"); return RxJavaPlugins.onAssembly(new ObservableBufferExactBoundary(this, boundary, bufferSupplier)); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping buffers. It emits the current buffer and replaces it with a * new buffer whenever the ObservableSource produced by the specified {@code boundarySupplier} emits an item. *

* *

* If either the source {@code ObservableSource} or the boundary {@code ObservableSource} issues an {@code onError} notification the event * is passed on immediately without first emitting the buffer it is in the process of assembling. *

*
Scheduler:
*
This version of {@code buffer} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the boundary-providing ObservableSource * @param boundarySupplier * a {@link Callable} that produces an ObservableSource that governs the boundary between buffers. * Whenever the supplied {@code ObservableSource} emits an item, {@code buffer} emits the current buffer and * begins to fill a new one * @return an Observable that emits a connected, non-overlapping buffer of items from the source ObservableSource * each time the ObservableSource created with the {@code closingIndicator} argument emits an item * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> buffer(Callable> boundarySupplier) { return buffer(boundarySupplier, ArrayListSupplier.asCallable()); } /** * Returns an Observable that emits buffers of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping buffers. It emits the current buffer and replaces it with a * new buffer whenever the ObservableSource produced by the specified {@code boundarySupplier} emits an item. *

* *

* If either the source {@code ObservableSource} or the boundary {@code ObservableSource} issues an {@code onError} notification the event * is passed on immediately without first emitting the buffer it is in the process of assembling. *

*
Scheduler:
*
This version of {@code buffer} does not operate by default on a particular {@link Scheduler}.
*
* * @param the collection subclass type to buffer into * @param the value type of the boundary-providing ObservableSource * @param boundarySupplier * a {@link Callable} that produces an ObservableSource that governs the boundary between buffers. * Whenever the supplied {@code ObservableSource} emits an item, {@code buffer} emits the current buffer and * begins to fill a new one * @param bufferSupplier * a factory function that returns an instance of the collection subclass to be used and returned * as the buffer * @return an Observable that emits a connected, non-overlapping buffer of items from the source ObservableSource * each time the ObservableSource created with the {@code closingIndicator} argument emits an item * @see ReactiveX operators documentation: Buffer */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final > Observable buffer(Callable> boundarySupplier, Callable bufferSupplier) { ObjectHelper.requireNonNull(boundarySupplier, "boundarySupplier is null"); ObjectHelper.requireNonNull(bufferSupplier, "bufferSupplier is null"); return RxJavaPlugins.onAssembly(new ObservableBufferBoundarySupplier(this, boundarySupplier, bufferSupplier)); } /** * Returns an Observable that subscribes to this ObservableSource lazily, caches all of its events * and replays them, in the same order as received, to all the downstream subscribers. *

* *

* This is useful when you want an ObservableSource to cache responses and you can't control the * subscribe/dispose behavior of all the {@link Observer}s. *

* The operator subscribes only when the first downstream subscriber subscribes and maintains * a single subscription towards this ObservableSource. In contrast, the operator family of {@link #replay()} * that return a {@link ConnectableObservable} require an explicit call to {@link ConnectableObservable#connect()}. *

* Note: You sacrifice the ability to dispose the origin when you use the {@code cache} * Observer so be careful not to use this Observer on ObservableSources 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 of cache(). *


     * AtomicBoolean shouldStop = new AtomicBoolean();
     *
     * source.takeUntil(v -> shouldStop.get())
     *       .cache()
     *       .takeUntil(v -> shouldStop.get())
     *       .subscribe(...);
     * 
* Since the operator doesn't allow clearing the cached values either, the possible workaround is * to forget all references to it via {@link #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:
*
{@code cache} does not operate by default on a particular {@link Scheduler}.
*
* * @return an Observable that, when first subscribed to, caches all of its items and notifications for the * benefit of subsequent subscribers * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable cache() { return cacheWithInitialCapacity(16); } /** * Returns an Observable that subscribes to this ObservableSource lazily, caches all of its events * and replays them, in the same order as received, to all the downstream subscribers. *

* *

* This is useful when you want an ObservableSource to cache responses and you can't control the * subscribe/dispose behavior of all the {@link Observer}s. *

* The operator subscribes only when the first downstream subscriber subscribes and maintains * a single subscription towards this ObservableSource. In contrast, the operator family of {@link #replay()} * that return a {@link ConnectableObservable} require an explicit call to {@link ConnectableObservable#connect()}. *

* Note: You sacrifice the ability to dispose the origin when you use the {@code cache} * Observer so be careful not to use this Observer on ObservableSources 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 of cache(). *


     * AtomicBoolean shouldStop = new AtomicBoolean();
     *
     * source.takeUntil(v -> shouldStop.get())
     *       .cache()
     *       .takeUntil(v -> shouldStop.get())
     *       .subscribe(...);
     * 
* Since the operator doesn't allow clearing the cached values either, the possible workaround is * to forget all references to it via {@link #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:
*
{@code cacheWithInitialCapacity} does not operate by default on a particular {@link Scheduler}.
*
*

* Note: The capacity hint is not an upper bound on cache size. For that, consider * {@link #replay(int)} in combination with {@link ConnectableObservable#autoConnect()} or similar. * * @param initialCapacity hint for number of items to cache (for optimizing underlying data structure) * @return an Observable that, when first subscribed to, caches all of its items and notifications for the * benefit of subsequent subscribers * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable cacheWithInitialCapacity(int initialCapacity) { ObjectHelper.verifyPositive(initialCapacity, "initialCapacity"); return RxJavaPlugins.onAssembly(new ObservableCache(this, initialCapacity)); } /** * Returns an Observable that emits the items emitted by the source ObservableSource, converted to the specified * type. *

* *

*
Scheduler:
*
{@code cast} does not operate by default on a particular {@link Scheduler}.
*
* * @param the output value type cast to * @param clazz * the target class type that {@code cast} will cast the items emitted by the source ObservableSource * into before emitting them from the resulting ObservableSource * @return an Observable that emits each item from the source ObservableSource after converting it to the * specified type * @see ReactiveX operators documentation: Map */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable cast(final Class clazz) { ObjectHelper.requireNonNull(clazz, "clazz is null"); return map(Functions.castFunction(clazz)); } /** * Collects items emitted by the finite source ObservableSource into a single mutable data structure and returns * a Single that emits this structure. *

* *

* This is a simplified version of {@code reduce} that does not need to return the state on each pass. *

* Note that this operator requires the upstream to signal {@code onComplete} for 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code collect} does not operate by default on a particular {@link Scheduler}.
*
* * @param the accumulator and output type * @param initialValueSupplier * the mutable data structure that will collect the items * @param collector * a function that accepts the {@code state} and an emitted item, and modifies {@code state} * accordingly * @return a Single that emits the result of collecting the values emitted by the source ObservableSource * into a single mutable data structure * @see ReactiveX operators documentation: Reduce */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single collect(Callable initialValueSupplier, BiConsumer collector) { ObjectHelper.requireNonNull(initialValueSupplier, "initialValueSupplier is null"); ObjectHelper.requireNonNull(collector, "collector is null"); return RxJavaPlugins.onAssembly(new ObservableCollectSingle(this, initialValueSupplier, collector)); } /** * Collects items emitted by the finite source ObservableSource into a single mutable data structure and returns * a Single that emits this structure. *

* *

* This is a simplified version of {@code reduce} that does not need to return the state on each pass. *

* Note that this operator requires the upstream to signal {@code onComplete} for 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code collectInto} does not operate by default on a particular {@link Scheduler}.
*
* * @param the accumulator and output type * @param initialValue * the mutable data structure that will collect the items * @param collector * a function that accepts the {@code state} and an emitted item, and modifies {@code state} * accordingly * @return a Single that emits the result of collecting the values emitted by the source ObservableSource * into a single mutable data structure * @see ReactiveX operators documentation: Reduce */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single collectInto(final U initialValue, BiConsumer collector) { ObjectHelper.requireNonNull(initialValue, "initialValue is null"); return collect(Functions.justCallable(initialValue), collector); } /** * Transform an ObservableSource by applying a particular Transformer function to it. *

* This method operates on the ObservableSource itself whereas {@link #lift} operates on the ObservableSource's * Observers. *

* If the operator you are creating is designed to act on the individual items emitted by a source * ObservableSource, use {@link #lift}. If your operator is designed to transform the source ObservableSource as a whole * (for instance, by applying a particular set of existing RxJava operators to it) use {@code compose}. *

*
Scheduler:
*
{@code compose} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the output ObservableSource * @param composer implements the function that transforms the source ObservableSource * @return the source ObservableSource, transformed by the transformer function * @see RxJava wiki: Implementing Your Own Operators */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable compose(ObservableTransformer composer) { return wrap(((ObservableTransformer) ObjectHelper.requireNonNull(composer, "composer is null")).apply(this)); } /** * Returns a new Observable that emits items resulting from applying a function that you supply to each item * emitted by the source ObservableSource, where that function returns an ObservableSource, and then emitting the items * that result from concatenating those resulting ObservableSources. *

* *

*
Scheduler:
*
{@code concatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the type of the inner ObservableSource sources and thus the output type * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns an * ObservableSource * @return an Observable that emits the result of applying the transformation function to each item emitted * by the source ObservableSource and concatenating the ObservableSources obtained from this transformation * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMap(Function> mapper) { return concatMap(mapper, 2); } /** * Returns a new Observable that emits items resulting from applying a function that you supply to each item * emitted by the source ObservableSource, where that function returns an ObservableSource, and then emitting the items * that result from concatenating those resulting ObservableSources. *

* *

*
Scheduler:
*
{@code concatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the type of the inner ObservableSource sources and thus the output type * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns an * ObservableSource * @param prefetch * the number of elements to prefetch from the current Observable * @return an Observable that emits the result of applying the transformation function to each item emitted * by the source ObservableSource and concatenating the ObservableSources obtained from this transformation * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMap(Function> mapper, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); if (this instanceof ScalarCallable) { @SuppressWarnings("unchecked") T v = ((ScalarCallable)this).call(); if (v == null) { return empty(); } return ObservableScalarXMap.scalarXMap(v, mapper); } return RxJavaPlugins.onAssembly(new ObservableConcatMap(this, mapper, prefetch, ErrorMode.IMMEDIATE)); } /** * Maps each of the items into an ObservableSource, 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 inner ObservableSources * till all of them terminate. *

* *

*
Scheduler:
*
{@code concatMapDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the result value type * @param mapper the function that maps the items of this ObservableSource into the inner ObservableSources. * @return the new ObservableSource instance with the concatenation behavior */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapDelayError(Function> mapper) { return concatMapDelayError(mapper, bufferSize(), true); } /** * Maps each of the items into an ObservableSource, 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 inner ObservableSources * till all of them terminate. *

* *

*
Scheduler:
*
{@code concatMapDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the result value type * @param mapper the function that maps the items of this ObservableSource into the inner ObservableSources. * @param prefetch * the number of elements to prefetch from the current Observable * @param tillTheEnd * if true, all errors from the outer and inner ObservableSource sources are delayed until the end, * if false, an error from the main source is signalled when the current ObservableSource source terminates * @return the new ObservableSource instance with the concatenation behavior */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapDelayError(Function> mapper, int prefetch, boolean tillTheEnd) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); if (this instanceof ScalarCallable) { @SuppressWarnings("unchecked") T v = ((ScalarCallable)this).call(); if (v == null) { return empty(); } return ObservableScalarXMap.scalarXMap(v, mapper); } return RxJavaPlugins.onAssembly(new ObservableConcatMap(this, mapper, prefetch, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY)); } /** * Maps a sequence of values into ObservableSources and concatenates these ObservableSources eagerly into a single * ObservableSource. *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them in * order, each one after the previous one completes. *

* *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param mapper the function that maps a sequence of values into a sequence of ObservableSources that will be * eagerly concatenated * @return the new ObservableSource instance with the specified concatenation behavior * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapEager(Function> mapper) { return concatMapEager(mapper, Integer.MAX_VALUE, bufferSize()); } /** * Maps a sequence of values into ObservableSources and concatenates these ObservableSources eagerly into a single * ObservableSource. *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them in * order, each one after the previous one completes. *

* *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param mapper the function that maps a sequence of values into a sequence of ObservableSources that will be * eagerly concatenated * @param maxConcurrency the maximum number of concurrent subscribed ObservableSources * @param prefetch hints about the number of expected values from each inner ObservableSource, must be positive * @return the new ObservableSource instance with the specified concatenation behavior * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapEager(Function> mapper, int maxConcurrency, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency"); ObjectHelper.verifyPositive(prefetch, "prefetch"); return RxJavaPlugins.onAssembly(new ObservableConcatMapEager(this, mapper, ErrorMode.IMMEDIATE, maxConcurrency, prefetch)); } /** * Maps a sequence of values into ObservableSources and concatenates these ObservableSources eagerly into a single * ObservableSource. *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them in * order, each one after the previous one completes. *

* *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param mapper the function that maps a sequence of values into a sequence of ObservableSources that will be * eagerly concatenated * @param tillTheEnd * if true, all errors from the outer and inner ObservableSource sources are delayed until the end, * if false, an error from the main source is signalled when the current ObservableSource source terminates * @return the new ObservableSource instance with the specified concatenation behavior * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapEagerDelayError(Function> mapper, boolean tillTheEnd) { return concatMapEagerDelayError(mapper, Integer.MAX_VALUE, bufferSize(), tillTheEnd); } /** * Maps a sequence of values into ObservableSources and concatenates these ObservableSources eagerly into a single * ObservableSource. *

* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the * source ObservableSources. The operator buffers the values emitted by these ObservableSources and then drains them in * order, each one after the previous one completes. *

* *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* @param the value type * @param mapper the function that maps a sequence of values into a sequence of ObservableSources that will be * eagerly concatenated * @param maxConcurrency the maximum number of concurrent subscribed ObservableSources * @param prefetch * the number of elements to prefetch from each source ObservableSource * @param tillTheEnd * if true, exceptions from the current Observable and all the inner ObservableSources are delayed until * all of them terminate, if false, exception from the current Observable is delayed until the * currently running ObservableSource terminates * @return the new ObservableSource instance with the specified concatenation behavior * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapEagerDelayError(Function> mapper, int maxConcurrency, int prefetch, boolean tillTheEnd) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency"); ObjectHelper.verifyPositive(prefetch, "prefetch"); return RxJavaPlugins.onAssembly(new ObservableConcatMapEager(this, mapper, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY, maxConcurrency, prefetch)); } /** * Maps each element of the upstream Observable into CompletableSources, subscribes to them one at a time in * order and waits until the upstream and all CompletableSources complete. *

* *

*
Scheduler:
*
{@code concatMapCompletable} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.6 - experimental * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns a CompletableSource * @return a Completable that signals {@code onComplete} when the upstream and all CompletableSources complete * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable concatMapCompletable(Function mapper) { return concatMapCompletable(mapper, 2); } /** * Maps each element of the upstream Observable into CompletableSources, subscribes to them one at a time in * order and waits until the upstream and all CompletableSources complete. *

* *

*
Scheduler:
*
{@code concatMapCompletable} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.6 - experimental * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns a CompletableSource * * @param capacityHint * the number of upstream items expected to be buffered until the current CompletableSource, mapped from * the current item, completes. * @return a Completable that signals {@code onComplete} when the upstream and all CompletableSources complete * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable concatMapCompletable(Function mapper, int capacityHint) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(capacityHint, "capacityHint"); return RxJavaPlugins.onAssembly(new ObservableConcatMapCompletable(this, mapper, ErrorMode.IMMEDIATE, capacityHint)); } /** * Maps the upstream items into {@link CompletableSource}s and subscribes to them one after the * other terminates, delaying all errors till both this {@code Observable} and all * inner {@code CompletableSource}s terminate. *

* *

*
Scheduler:
*
{@code concatMapCompletableDelayError} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param mapper the function called with the upstream item and should return * a {@code CompletableSource} to become the next source to * be subscribed to * @return a new Completable instance * @see #concatMapCompletable(Function, int) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable concatMapCompletableDelayError(Function mapper) { return concatMapCompletableDelayError(mapper, true, 2); } /** * Maps the upstream items into {@link CompletableSource}s and subscribes to them one after the * other terminates, optionally delaying all errors till both this {@code Observable} and all * inner {@code CompletableSource}s terminate. *

* *

*
Scheduler:
*
{@code concatMapCompletableDelayError} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param mapper the function called with the upstream item and should return * a {@code CompletableSource} to become the next source to * be subscribed to * @param tillTheEnd If {@code true}, errors from this {@code Observable} or any of the * inner {@code CompletableSource}s are delayed until all * of them terminate. If {@code false}, an error from this * {@code Observable} is delayed until the current inner * {@code CompletableSource} terminates and only then is * it emitted to the downstream. * @return a new Completable instance * @see #concatMapCompletable(Function) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable concatMapCompletableDelayError(Function mapper, boolean tillTheEnd) { return concatMapCompletableDelayError(mapper, tillTheEnd, 2); } /** * Maps the upstream items into {@link CompletableSource}s and subscribes to them one after the * other terminates, optionally delaying all errors till both this {@code Observable} and all * inner {@code CompletableSource}s terminate. *

* *

*
Scheduler:
*
{@code concatMapCompletableDelayError} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param mapper the function called with the upstream item and should return * a {@code CompletableSource} to become the next source to * be subscribed to * @param tillTheEnd If {@code true}, errors from this {@code Observable} or any of the * inner {@code CompletableSource}s are delayed until all * of them terminate. If {@code false}, an error from this * {@code Observable} is delayed until the current inner * {@code CompletableSource} terminates and only then is * it emitted to the downstream. * @param prefetch The number of upstream items to prefetch so that fresh items are * ready to be mapped when a previous {@code CompletableSource} terminates. * The operator replenishes after half of the prefetch amount has been consumed * and turned into {@code CompletableSource}s. * @return a new Completable instance * @see #concatMapCompletable(Function, int) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable concatMapCompletableDelayError(Function mapper, boolean tillTheEnd, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); return RxJavaPlugins.onAssembly(new ObservableConcatMapCompletable(this, mapper, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY, prefetch)); } /** * Returns an Observable that concatenate each item emitted by the source ObservableSource with the values in an * Iterable corresponding to that item that is generated by a selector. *

* * *

*
Scheduler:
*
{@code concatMapIterable} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of item emitted by the resulting ObservableSource * @param mapper * a function that returns an Iterable sequence of values for when given an item emitted by the * source ObservableSource * @return an Observable that emits the results of concatenating the items emitted by the source ObservableSource with * the values in the Iterables corresponding to those items, as generated by {@code collectionSelector} * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapIterable(final Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableFlattenIterable(this, mapper)); } /** * Returns an Observable that concatenate each item emitted by the source ObservableSource with the values in an * Iterable corresponding to that item that is generated by a selector. *

* * *

*
Scheduler:
*
{@code concatMapIterable} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of item emitted by the resulting ObservableSource * @param mapper * a function that returns an Iterable sequence of values for when given an item emitted by the * source ObservableSource * @param prefetch * the number of elements to prefetch from the current Observable * @return an Observable that emits the results of concatenating the items emitted by the source ObservableSource with * the values in the Iterables corresponding to those items, as generated by {@code collectionSelector} * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapIterable(final Function> mapper, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); return concatMap(ObservableInternalHelper.flatMapIntoIterable(mapper), prefetch); } /** * Maps the upstream items into {@link MaybeSource}s and subscribes to them one after the * other succeeds or completes, emits their success value if available or terminates immediately if * either this {@code Observable} or the current inner {@code MaybeSource} fail. *

* *

*
Scheduler:
*
{@code concatMapMaybe} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to * be subscribed to * @return a new Observable instance * @see #concatMapMaybeDelayError(Function) * @see #concatMapMaybe(Function, int) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapMaybe(Function> mapper) { return concatMapMaybe(mapper, 2); } /** * Maps the upstream items into {@link MaybeSource}s and subscribes to them one after the * other succeeds or completes, emits their success value if available or terminates immediately if * either this {@code Observable} or the current inner {@code MaybeSource} fail. *

* *

*
Scheduler:
*
{@code concatMapMaybe} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to * be subscribed to * @param prefetch The number of upstream items to prefetch so that fresh items are * ready to be mapped when a previous {@code MaybeSource} terminates. * The operator replenishes after half of the prefetch amount has been consumed * and turned into {@code MaybeSource}s. * @return a new Observable instance * @see #concatMapMaybe(Function) * @see #concatMapMaybeDelayError(Function, boolean, int) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapMaybe(Function> mapper, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); return RxJavaPlugins.onAssembly(new ObservableConcatMapMaybe(this, mapper, ErrorMode.IMMEDIATE, prefetch)); } /** * Maps the upstream items into {@link MaybeSource}s and subscribes to them one after the * other terminates, emits their success value if available and delaying all errors * till both this {@code Observable} and all inner {@code MaybeSource}s terminate. *

* *

*
Scheduler:
*
{@code concatMapMaybeDelayError} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to * be subscribed to * @return a new Observable instance * @see #concatMapMaybe(Function) * @see #concatMapMaybeDelayError(Function, boolean) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapMaybeDelayError(Function> mapper) { return concatMapMaybeDelayError(mapper, true, 2); } /** * Maps the upstream items into {@link MaybeSource}s and subscribes to them one after the * other terminates, emits their success value if available and optionally delaying all errors * till both this {@code Observable} and all inner {@code MaybeSource}s terminate. *

* *

*
Scheduler:
*
{@code concatMapMaybeDelayError} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to * be subscribed to * @param tillTheEnd If {@code true}, errors from this {@code Observable} or any of the * inner {@code MaybeSource}s are delayed until all * of them terminate. If {@code false}, an error from this * {@code Observable} is delayed until the current inner * {@code MaybeSource} terminates and only then is * it emitted to the downstream. * @return a new Observable instance * @see #concatMapMaybe(Function, int) * @see #concatMapMaybeDelayError(Function, boolean, int) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapMaybeDelayError(Function> mapper, boolean tillTheEnd) { return concatMapMaybeDelayError(mapper, tillTheEnd, 2); } /** * Maps the upstream items into {@link MaybeSource}s and subscribes to them one after the * other terminates, emits their success value if available and optionally delaying all errors * till both this {@code Observable} and all inner {@code MaybeSource}s terminate. *

* *

*
Scheduler:
*
{@code concatMapMaybeDelayError} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param the result type of the inner {@code MaybeSource}s * @param mapper the function called with the upstream item and should return * a {@code MaybeSource} to become the next source to * be subscribed to * @param tillTheEnd If {@code true}, errors from this {@code Observable} or any of the * inner {@code MaybeSource}s are delayed until all * of them terminate. If {@code false}, an error from this * {@code Observable} is delayed until the current inner * {@code MaybeSource} terminates and only then is * it emitted to the downstream. * @param prefetch The number of upstream items to prefetch so that fresh items are * ready to be mapped when a previous {@code MaybeSource} terminates. * The operator replenishes after half of the prefetch amount has been consumed * and turned into {@code MaybeSource}s. * @return a new Observable instance * @see #concatMapMaybe(Function, int) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapMaybeDelayError(Function> mapper, boolean tillTheEnd, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); return RxJavaPlugins.onAssembly(new ObservableConcatMapMaybe(this, mapper, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY, prefetch)); } /** * Maps the upstream items into {@link SingleSource}s and subscribes to them one after the * other succeeds, emits their success values or terminates immediately if * either this {@code Observable} or the current inner {@code SingleSource} fail. *

* *

*
Scheduler:
*
{@code concatMapSingle} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to * be subscribed to * @return a new Observable instance * @see #concatMapSingleDelayError(Function) * @see #concatMapSingle(Function, int) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapSingle(Function> mapper) { return concatMapSingle(mapper, 2); } /** * Maps the upstream items into {@link SingleSource}s and subscribes to them one after the * other succeeds, emits their success values or terminates immediately if * either this {@code Observable} or the current inner {@code SingleSource} fail. *

* *

*
Scheduler:
*
{@code concatMapSingle} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to * be subscribed to * @param prefetch The number of upstream items to prefetch so that fresh items are * ready to be mapped when a previous {@code SingleSource} terminates. * The operator replenishes after half of the prefetch amount has been consumed * and turned into {@code SingleSource}s. * @return a new Observable instance * @see #concatMapSingle(Function) * @see #concatMapSingleDelayError(Function, boolean, int) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapSingle(Function> mapper, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); return RxJavaPlugins.onAssembly(new ObservableConcatMapSingle(this, mapper, ErrorMode.IMMEDIATE, prefetch)); } /** * Maps the upstream items into {@link SingleSource}s and subscribes to them one after the * other succeeds or fails, emits their success values and delays all errors * till both this {@code Observable} and all inner {@code SingleSource}s terminate. *

* *

*
Scheduler:
*
{@code concatMapSingleDelayError} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to * be subscribed to * @return a new Observable instance * @see #concatMapSingle(Function) * @see #concatMapSingleDelayError(Function, boolean) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapSingleDelayError(Function> mapper) { return concatMapSingleDelayError(mapper, true, 2); } /** * Maps the upstream items into {@link SingleSource}s and subscribes to them one after the * other succeeds or fails, emits their success values and optionally delays all errors * till both this {@code Observable} and all inner {@code SingleSource}s terminate. *

* *

*
Scheduler:
*
{@code concatMapSingleDelayError} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to * be subscribed to * @param tillTheEnd If {@code true}, errors from this {@code Observable} or any of the * inner {@code SingleSource}s are delayed until all * of them terminate. If {@code false}, an error from this * {@code Observable} is delayed until the current inner * {@code SingleSource} terminates and only then is * it emitted to the downstream. * @return a new Observable instance * @see #concatMapSingle(Function, int) * @see #concatMapSingleDelayError(Function, boolean, int) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapSingleDelayError(Function> mapper, boolean tillTheEnd) { return concatMapSingleDelayError(mapper, tillTheEnd, 2); } /** * Maps the upstream items into {@link SingleSource}s and subscribes to them one after the * other succeeds or fails, emits their success values and optionally delays errors * till both this {@code Observable} and all inner {@code SingleSource}s terminate. *

* *

*
Scheduler:
*
{@code concatMapSingleDelayError} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param the result type of the inner {@code SingleSource}s * @param mapper the function called with the upstream item and should return * a {@code SingleSource} to become the next source to * be subscribed to * @param tillTheEnd If {@code true}, errors from this {@code Observable} or any of the * inner {@code SingleSource}s are delayed until all * of them terminate. If {@code false}, an error from this * {@code Observable} is delayed until the current inner * {@code SingleSource} terminates and only then is * it emitted to the downstream. * @param prefetch The number of upstream items to prefetch so that fresh items are * ready to be mapped when a previous {@code SingleSource} terminates. * The operator replenishes after half of the prefetch amount has been consumed * and turned into {@code SingleSource}s. * @return a new Observable instance * @see #concatMapSingle(Function, int) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatMapSingleDelayError(Function> mapper, boolean tillTheEnd, int prefetch) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); return RxJavaPlugins.onAssembly(new ObservableConcatMapSingle(this, mapper, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY, prefetch)); } /** * Returns an Observable that emits the items emitted from the current ObservableSource, then the next, one after * the other, without interleaving them. *

* *

*
Scheduler:
*
{@code concatWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param other * an ObservableSource to be concatenated after the current * @return an Observable that emits items emitted by the two source ObservableSources, one after the other, * without interleaving them * @see ReactiveX operators documentation: Concat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatWith(ObservableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return concat(this, other); } /** * Returns an {@code Observable} that emits the items from this {@code Observable} followed by the success item or error event * of the other {@link SingleSource}. *

* *

*
Scheduler:
*
{@code concatWith} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.10 - experimental * @param other the SingleSource whose signal should be emitted after this {@code Observable} completes normally. * @return the new Observable instance * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatWith(@NonNull SingleSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableConcatWithSingle(this, other)); } /** * Returns an {@code Observable} that emits the items from this {@code Observable} followed by the success item or terminal events * of the other {@link MaybeSource}. *

* *

*
Scheduler:
*
{@code concatWith} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.10 - experimental * @param other the MaybeSource whose signal should be emitted after this Observable completes normally. * @return the new Observable instance * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatWith(@NonNull MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableConcatWithMaybe(this, other)); } /** * Returns an {@code Observable} that emits items from this {@code Observable} and when it completes normally, the * other {@link CompletableSource} is subscribed to and the returned {@code Observable} emits its terminal events. *

* *

*
Scheduler:
*
{@code concatWith} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.10 - experimental * @param other the {@code CompletableSource} to subscribe to once the current {@code Observable} completes normally * @return the new Observable instance * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable concatWith(@NonNull CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableConcatWithCompletable(this, other)); } /** * Returns a Single that emits a Boolean that indicates whether the source ObservableSource emitted a * specified item. *

* *

*
Scheduler:
*
{@code contains} does not operate by default on a particular {@link Scheduler}.
*
* * @param element * the item to search for in the emissions from the source ObservableSource * @return a Single that emits {@code true} if the specified item is emitted by the source ObservableSource, * or {@code false} if the source ObservableSource completes without emitting that item * @see ReactiveX operators documentation: Contains */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single contains(final Object element) { ObjectHelper.requireNonNull(element, "element is null"); return any(Functions.equalsWith(element)); } /** * Returns a Single that counts the total number of items emitted by the source ObservableSource and emits * this count as a 64-bit Long. *

* *

*
Scheduler:
*
{@code count} does not operate by default on a particular {@link Scheduler}.
*
* * @return a Single that emits a single item: the number of items emitted by the source ObservableSource as a * 64-bit Long item * @see ReactiveX operators documentation: Count */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single count() { return RxJavaPlugins.onAssembly(new ObservableCountSingle(this)); } /** * Returns an Observable that mirrors the source ObservableSource, except that it drops items emitted by the * source ObservableSource that are followed by another item within a computed debounce duration. *

* *

* The delivery of the item happens on the thread of the first {@code onNext} or {@code onComplete} * signal of the generated {@code ObservableSource} sequence, * 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 an {@code InterruptedException}). It is recommended processing items * that may take long time to be moved to another thread via {@link #observeOn} applied after * {@code debounce} itself. *

*
Scheduler:
*
This version of {@code debounce} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the debounce value type (ignored) * @param debounceSelector * function to retrieve a sequence that indicates the throttle duration for each item * @return an Observable that omits items emitted by the source ObservableSource that are followed by another item * within a computed debounce duration * @see ReactiveX operators documentation: Debounce */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable debounce(Function> debounceSelector) { ObjectHelper.requireNonNull(debounceSelector, "debounceSelector is null"); return RxJavaPlugins.onAssembly(new ObservableDebounce(this, debounceSelector)); } /** * Returns an Observable that mirrors the source ObservableSource, except that it drops items emitted by the * source ObservableSource that are followed by newer items before a timeout value expires. The timer resets on * each emission. *

* Note: If items keep being emitted by the source ObservableSource faster than the timeout then no items * will be emitted by the resulting ObservableSource. *

* *

* Delivery of the item after the grace period happens on the {@code computation} {@code Scheduler}'s * {@code Worker} which if takes too long, a newer item may arrive from the upstream, causing the * {@code Worker}'s task to get disposed, which may also interrupt any downstream blocking operation * (yielding an {@code InterruptedException}). It is recommended processing items * that may take long time to be moved to another thread via {@link #observeOn} applied after * {@code debounce} itself. *

*
Scheduler:
*
{@code debounce} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param timeout * the length of the window of time that must pass after the emission of an item from the source * ObservableSource in which that ObservableSource emits no items in order for the item to be emitted by the * resulting ObservableSource * @param unit * the unit of time for the specified {@code timeout} * @return an Observable that filters out items from the source ObservableSource that are too quickly followed by * newer items * @see ReactiveX operators documentation: Debounce * @see #throttleWithTimeout(long, TimeUnit) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable debounce(long timeout, TimeUnit unit) { return debounce(timeout, unit, Schedulers.computation()); } /** * Returns an Observable that mirrors the source ObservableSource, except that it drops items emitted by the * source ObservableSource that are followed by newer items before a timeout value expires on a specified * Scheduler. The timer resets on each emission. *

* Note: If items keep being emitted by the source ObservableSource faster than the timeout then no items * will be emitted by the resulting ObservableSource. *

* *

* Delivery of the item after the grace period happens on the given {@code Scheduler}'s * {@code Worker} which if takes too long, a newer item may arrive from the upstream, causing the * {@code Worker}'s task to get disposed, which may also interrupt any downstream blocking operation * (yielding an {@code InterruptedException}). It is recommended processing items * that may take long time to be moved to another thread via {@link #observeOn} applied after * {@code debounce} itself. *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param timeout * the time each item has to be "the most recent" of those emitted by the source ObservableSource to * ensure that it's not dropped * @param unit * the unit of time for the specified {@code timeout} * @param scheduler * the {@link Scheduler} to use internally to manage the timers that handle the timeout for each * item * @return an Observable that filters out items from the source ObservableSource that are too quickly followed by * newer items * @see ReactiveX operators documentation: Debounce * @see #throttleWithTimeout(long, TimeUnit, Scheduler) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable debounce(long timeout, TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new ObservableDebounceTimed(this, timeout, unit, scheduler)); } /** * Returns an Observable that emits the items emitted by the source ObservableSource or a specified default item * if the source ObservableSource is empty. *

* *

*
Scheduler:
*
{@code defaultIfEmpty} does not operate by default on a particular {@link Scheduler}.
*
* * @param defaultItem * the item to emit if the source ObservableSource emits no items * @return an Observable that emits either the specified default item if the source ObservableSource emits no * items, or the items emitted by the source ObservableSource * @see ReactiveX operators documentation: DefaultIfEmpty */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable defaultIfEmpty(T defaultItem) { ObjectHelper.requireNonNull(defaultItem, "defaultItem is null"); return switchIfEmpty(just(defaultItem)); } /** * Returns an Observable that delays the emissions of the source ObservableSource via another ObservableSource on a * per-item basis. *

* *

* Note: the resulting ObservableSource will immediately propagate any {@code onError} notification * from the source ObservableSource. *

*
Scheduler:
*
This version of {@code delay} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the item delay value type (ignored) * @param itemDelay * a function that returns an ObservableSource for each item emitted by the source ObservableSource, which is * then used to delay the emission of that item by the resulting ObservableSource until the ObservableSource * returned from {@code itemDelay} emits an item * @return an Observable that delays the emissions of the source ObservableSource via another ObservableSource on a * per-item basis * @see ReactiveX operators documentation: Delay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable delay(final Function> itemDelay) { ObjectHelper.requireNonNull(itemDelay, "itemDelay is null"); return flatMap(ObservableInternalHelper.itemDelay(itemDelay)); } /** * Returns an Observable that emits the items emitted by the source ObservableSource shifted forward in time by a * specified delay. Error notifications from the source ObservableSource are not delayed. *

* *

*
Scheduler:
*
This version of {@code delay} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param delay * the delay to shift the source by * @param unit * the {@link TimeUnit} in which {@code period} is defined * @return the source ObservableSource shifted in time by the specified delay * @see ReactiveX operators documentation: Delay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable delay(long delay, TimeUnit unit) { return delay(delay, unit, Schedulers.computation(), false); } /** * Returns an Observable that emits the items emitted by the source ObservableSource shifted forward in time by a * specified delay. If {@code delayError} is true, error notifications will also be delayed. *

* *

*
Scheduler:
*
This version of {@code delay} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param delay * the delay to shift the source by * @param unit * the {@link TimeUnit} in which {@code period} is defined * @param delayError * if true, the upstream exception is signalled with the given delay, after all preceding normal elements, * if false, the upstream exception is signalled immediately * @return the source ObservableSource shifted in time by the specified delay * @see ReactiveX operators documentation: Delay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable delay(long delay, TimeUnit unit, boolean delayError) { return delay(delay, unit, Schedulers.computation(), delayError); } /** * Returns an Observable that emits the items emitted by the source ObservableSource shifted forward in time by a * specified delay. Error notifications from the source ObservableSource are not delayed. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param delay * the delay to shift the source by * @param unit * the time unit of {@code delay} * @param scheduler * the {@link Scheduler} to use for delaying * @return the source ObservableSource shifted in time by the specified delay * @see ReactiveX operators documentation: Delay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable delay(long delay, TimeUnit unit, Scheduler scheduler) { return delay(delay, unit, scheduler, false); } /** * Returns an Observable that emits the items emitted by the source ObservableSource shifted forward in time by a * specified delay. If {@code delayError} is true, error notifications will also be delayed. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param delay * the delay to shift the source by * @param unit * the time unit of {@code delay} * @param scheduler * the {@link Scheduler} to use for delaying * @param delayError * if true, the upstream exception is signalled with the given delay, after all preceding normal elements, * if false, the upstream exception is signalled immediately * @return the source ObservableSource shifted in time by the specified delay * @see ReactiveX operators documentation: Delay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable delay(long delay, TimeUnit unit, Scheduler scheduler, boolean delayError) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new ObservableDelay(this, delay, unit, scheduler, delayError)); } /** * Returns an Observable that delays the subscription to and emissions from the source ObservableSource via another * ObservableSource on a per-item basis. *

* *

* Note: the resulting ObservableSource will immediately propagate any {@code onError} notification * from the source ObservableSource. *

*
Scheduler:
*
This version of {@code delay} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the subscription delay value type (ignored) * @param * the item delay value type (ignored) * @param subscriptionDelay * a function that returns an ObservableSource that triggers the subscription to the source ObservableSource * once it emits any item * @param itemDelay * a function that returns an ObservableSource for each item emitted by the source ObservableSource, which is * then used to delay the emission of that item by the resulting ObservableSource until the ObservableSource * returned from {@code itemDelay} emits an item * @return an Observable that delays the subscription and emissions of the source ObservableSource via another * ObservableSource on a per-item basis * @see ReactiveX operators documentation: Delay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable delay(ObservableSource subscriptionDelay, Function> itemDelay) { return delaySubscription(subscriptionDelay).delay(itemDelay); } /** * Returns an Observable that delays the subscription to this Observable * until the other Observable emits an element or completes normally. *

* *

*
Scheduler:
*
This method does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the other Observable, irrelevant * @param other the other Observable that should trigger the subscription * to this Observable. * @return an Observable that delays the subscription to this Observable * until the other Observable emits an element or completes normally. * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable delaySubscription(ObservableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableDelaySubscriptionOther(this, other)); } /** * Returns an Observable that delays the subscription to the source ObservableSource by a given amount of time. *

* *

*
Scheduler:
*
This version of {@code delaySubscription} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param delay * the time to delay the subscription * @param unit * the time unit of {@code delay} * @return an Observable that delays the subscription to the source ObservableSource by the given amount * @see ReactiveX operators documentation: Delay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable delaySubscription(long delay, TimeUnit unit) { return delaySubscription(delay, unit, Schedulers.computation()); } /** * Returns an Observable that delays the subscription to the source ObservableSource by a given amount of time, * both waiting and subscribing on a given Scheduler. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param delay * the time to delay the subscription * @param unit * the time unit of {@code delay} * @param scheduler * the Scheduler on which the waiting and subscription will happen * @return an Observable that delays the subscription to the source ObservableSource by a given * amount, waiting and subscribing on the given Scheduler * @see ReactiveX operators documentation: Delay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable delaySubscription(long delay, TimeUnit unit, Scheduler scheduler) { return delaySubscription(timer(delay, unit, scheduler)); } /** * Returns an Observable that reverses the effect of {@link #materialize materialize} by transforming the * {@link Notification} objects emitted by the source ObservableSource into the items or notifications they * represent. *

* *

* When the upstream signals an {@link Notification#createOnError(Throwable) onError} or * {@link Notification#createOnComplete() onComplete} item, the * returned Observable disposes of the flow and terminates with that type of terminal event: *


     * Observable.just(createOnNext(1), createOnComplete(), createOnNext(2))
     * .doOnDispose(() -> System.out.println("Disposed!"));
     * .dematerialize()
     * .test()
     * .assertResult(1);
     * 
* If the upstream signals {@code onError} or {@code onComplete} directly, the flow is terminated * with the same event. *

     * Observable.just(createOnNext(1), createOnNext(2))
     * .dematerialize()
     * .test()
     * .assertResult(1, 2);
     * 
* If this behavior is not desired, the completion can be suppressed by applying {@link #concatWith(ObservableSource)} * with a {@link #never()} source. *
*
Scheduler:
*
{@code dematerialize} does not operate by default on a particular {@link Scheduler}.
*
* * @param the output value type * @return an Observable that emits the items and notifications embedded in the {@link Notification} objects * emitted by the source ObservableSource * @see ReactiveX operators documentation: Dematerialize * @see #dematerialize(Function) * @deprecated in 2.2.4; inherently type-unsafe as it overrides the output generic type. Use {@link #dematerialize(Function)} instead. */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @Deprecated @SuppressWarnings({ "unchecked", "rawtypes" }) public final Observable dematerialize() { return RxJavaPlugins.onAssembly(new ObservableDematerialize(this, Functions.identity())); } /** * Returns an Observable that reverses the effect of {@link #materialize materialize} by transforming the * {@link Notification} objects extracted from the source items via a selector function * into their respective {@code Observer} signal types. *

* *

* The intended use of the {@code selector} function is to perform a * type-safe identity mapping (see example) on a source that is already of type * {@code Notification}. 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 {@link Notification#createOnError(Throwable) onError} or * {@link Notification#createOnComplete() onComplete} item, the * returned Observable disposes of the flow and terminates with that type of terminal event: *


     * Observable.just(createOnNext(1), createOnComplete(), createOnNext(2))
     * .doOnDispose(() -> System.out.println("Disposed!"));
     * .dematerialize(notification -> notification)
     * .test()
     * .assertResult(1);
     * 
* If the upstream signals {@code onError} or {@code onComplete} directly, the flow is terminated * with the same event. *

     * Observable.just(createOnNext(1), createOnNext(2))
     * .dematerialize(notification -> notification)
     * .test()
     * .assertResult(1, 2);
     * 
* If this behavior is not desired, the completion can be suppressed by applying {@link #concatWith(ObservableSource)} * with a {@link #never()} source. *
*
Scheduler:
*
{@code dematerialize} does not operate by default on a particular {@link Scheduler}.
*
* * @param the output value type * @param selector function that returns the upstream item and should return a Notification to signal * the corresponding {@code Observer} event to the downstream. * @return an Observable that emits the items and notifications embedded in the {@link Notification} objects * selected from the items emitted by the source ObservableSource * @see ReactiveX operators documentation: Dematerialize * @since 2.2.4 - experimental */ @Experimental @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable dematerialize(Function> selector) { ObjectHelper.requireNonNull(selector, "selector is null"); return RxJavaPlugins.onAssembly(new ObservableDematerialize(this, selector)); } /** * Returns an Observable that emits all items emitted by the source ObservableSource that are distinct * based on {@link Object#equals(Object)} comparison. *

* *

* It is recommended the elements' class {@code T} in the flow overrides the default {@code Object.equals()} * and {@link Object#hashCode()} to provide meaningful comparison between items as the default Java * implementation only considers reference equivalence. *

* By default, {@code distinct()} uses an internal {@link java.util.HashSet} per Observer to remember * previously seen items and uses {@link java.util.Set#add(Object)} returning {@code false} as the * indicator for duplicates. *

* Note that this internal {@code HashSet} may 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 * to {@code OutOfMemoryError}. *

* Customizing the retention policy can happen only by providing a custom {@link java.util.Collection} implementation * to the {@link #distinct(Function, Callable)} overload. *

*
Scheduler:
*
{@code distinct} does not operate by default on a particular {@link Scheduler}.
*
* * @return an Observable that emits only those items emitted by the source ObservableSource that are distinct from * each other * @see ReactiveX operators documentation: Distinct * @see #distinct(Function) * @see #distinct(Function, Callable) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable distinct() { return distinct(Functions.identity(), Functions.createHashSet()); } /** * Returns an Observable that emits all items emitted by the source ObservableSource that are distinct according * to a key selector function and based on {@link Object#equals(Object)} comparison of the objects * returned by the key selector function. *

* *

* It is recommended the keys' class {@code K} overrides the default {@code Object.equals()} * and {@link Object#hashCode()} to provide meaningful comparison between the key objects as the default * Java implementation only considers reference equivalence. *

* By default, {@code distinct()} uses an internal {@link java.util.HashSet} per Observer to remember * previously seen keys and uses {@link java.util.Set#add(Object)} returning {@code false} as the * indicator for duplicates. *

* Note that this internal {@code HashSet} may 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 * to {@code OutOfMemoryError}. *

* Customizing the retention policy can happen only by providing a custom {@link java.util.Collection} implementation * to the {@link #distinct(Function, Callable)} overload. *

*
Scheduler:
*
{@code distinct} does not operate by default on a particular {@link Scheduler}.
*
* * @param the key type * @param 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 * @return an Observable that emits those items emitted by the source ObservableSource that have distinct keys * @see ReactiveX operators documentation: Distinct * @see #distinct(Function, Callable) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable distinct(Function keySelector) { return distinct(keySelector, Functions.createHashSet()); } /** * Returns an Observable that emits all items emitted by the source ObservableSource that are distinct according * to a key selector function and based on {@link Object#equals(Object)} comparison of the objects * returned by the key selector function. *

* *

* It is recommended the keys' class {@code K} overrides the default {@code Object.equals()} * and {@link Object#hashCode()} to provide meaningful comparison between the key objects as * the default Java implementation only considers reference equivalence. *

*
Scheduler:
*
{@code distinct} does not operate by default on a particular {@link Scheduler}.
*
* * @param the key type * @param 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 * @param collectionSupplier * function called for each individual Observer to return a Collection subtype for holding the extracted * keys and whose add() method's return indicates uniqueness. * @return an Observable that emits those items emitted by the source ObservableSource that have distinct keys * @see ReactiveX operators documentation: Distinct */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable distinct(Function keySelector, Callable> collectionSupplier) { ObjectHelper.requireNonNull(keySelector, "keySelector is null"); ObjectHelper.requireNonNull(collectionSupplier, "collectionSupplier is null"); return RxJavaPlugins.onAssembly(new ObservableDistinct(this, keySelector, collectionSupplier)); } /** * Returns an Observable that emits all items emitted by the source ObservableSource that are distinct from their * immediate predecessors based on {@link Object#equals(Object)} comparison. *

* *

* It is recommended the elements' class {@code T} in the flow overrides the default {@code Object.equals()} to provide * meaningful comparison between items as the default Java implementation only considers reference equivalence. * Alternatively, use the {@link #distinctUntilChanged(BiPredicate)} overload and provide a comparison function * in case the class {@code T} can't be overridden with custom {@code equals()} or the comparison itself * should happen on different terms or properties of the class {@code T}. *

* 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 {@code T} in 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 mutable * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, * for example using {@code map(CharSequence::toString)} or {@code map(list -> Collections.unmodifiableList(new ArrayList<>(list)))}. *

*
Scheduler:
*
{@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.
*
* * @return an Observable that emits those items from the source ObservableSource that are distinct from their * immediate predecessors * @see ReactiveX operators documentation: Distinct * @see #distinctUntilChanged(BiPredicate) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable distinctUntilChanged() { return distinctUntilChanged(Functions.identity()); } /** * Returns an Observable that emits all items emitted by the source ObservableSource that are distinct from their * immediate predecessors, according to a key selector function and based on {@link Object#equals(Object)} comparison * of those objects returned by the key selector function. *

* *

* It is recommended the keys' class {@code K} overrides the default {@code Object.equals()} to provide * meaningful comparison between the key objects as the default Java implementation only considers reference equivalence. * Alternatively, use the {@link #distinctUntilChanged(BiPredicate)} overload and provide a comparison function * in case the class {@code K} can't be overridden with custom {@code equals()} or the comparison itself * should happen on different terms or properties of the item class {@code T} (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 {@code T} in 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 mutable * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, * for example using {@code map(CharSequence::toString)} or {@code map(list -> Collections.unmodifiableList(new ArrayList<>(list)))}. *

*
Scheduler:
*
{@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.
*
* * @param the key type * @param 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 * @return an Observable that emits those items from the source ObservableSource whose keys are distinct from * those of their immediate predecessors * @see ReactiveX operators documentation: Distinct */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable distinctUntilChanged(Function keySelector) { ObjectHelper.requireNonNull(keySelector, "keySelector is null"); return RxJavaPlugins.onAssembly(new ObservableDistinctUntilChanged(this, keySelector, ObjectHelper.equalsPredicate())); } /** * Returns an Observable that emits all items emitted by the source ObservableSource that 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 {@code T} in 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 mutable * {@code CharSequence}s or {@code List}s where the objects will actually have the same * references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same. * To avoid such situation, it is recommended that mutable data is converted to an immutable one, * for example using {@code map(CharSequence::toString)} or {@code map(list -> Collections.unmodifiableList(new ArrayList<>(list)))}. *

*
Scheduler:
*
{@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.
*
* * @param comparer the function that receives the previous item and the current item and is * expected to return true if the two are equal, thus skipping the current value. * @return an Observable that emits those items from the source ObservableSource that are distinct from their * immediate predecessors * @see ReactiveX operators documentation: Distinct * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable distinctUntilChanged(BiPredicate comparer) { ObjectHelper.requireNonNull(comparer, "comparer is null"); return RxJavaPlugins.onAssembly(new ObservableDistinctUntilChanged(this, Functions.identity(), comparer)); } /** * Calls the specified consumer with the current item after this item has been emitted to the downstream. *

Note that the {@code onAfterNext} action is shared between subscriptions and as such * should be thread-safe. *

* *

*
Scheduler:
*
{@code doAfterNext} does not operate by default on a particular {@link Scheduler}.
*
Operator-fusion:
*
This operator supports boundary-limited synchronous or asynchronous queue-fusion.
*
*

History: 2.0.1 - experimental * @param onAfterNext the Consumer that will be called after emitting an item from upstream to the downstream * @return the new Observable instance * @since 2.1 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable doAfterNext(Consumer onAfterNext) { ObjectHelper.requireNonNull(onAfterNext, "onAfterNext is null"); return RxJavaPlugins.onAssembly(new ObservableDoAfterNext(this, onAfterNext)); } /** * Registers an {@link Action} to be called when this ObservableSource invokes either * {@link Observer#onComplete onComplete} or {@link Observer#onError onError}. *

* *

*
Scheduler:
*
{@code doAfterTerminate} does not operate by default on a particular {@link Scheduler}.
*
* * @param onFinally * an {@link Action} to be invoked when the source ObservableSource finishes * @return an Observable that emits the same items as the source ObservableSource, then invokes the * {@link Action} * @see ReactiveX operators documentation: Do * @see #doOnTerminate(Action) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable doAfterTerminate(Action onFinally) { ObjectHelper.requireNonNull(onFinally, "onFinally is null"); return doOnEach(Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.EMPTY_ACTION, onFinally); } /** * Calls the specified action after this Observable signals onError or onCompleted or gets disposed by * the downstream. *

In case of a race between a terminal event and a dispose call, the provided {@code onFinally} action * is executed once per subscription. *

Note that the {@code onFinally} action is shared between subscriptions and as such * should be thread-safe. *

* *

*
Scheduler:
*
{@code doFinally} does not operate by default on a particular {@link Scheduler}.
*
Operator-fusion:
*
This operator supports boundary-limited synchronous or asynchronous queue-fusion.
*
*

History: 2.0.1 - experimental * @param onFinally the action called when this Observable terminates or gets disposed * @return the new Observable instance * @since 2.1 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable doFinally(Action onFinally) { ObjectHelper.requireNonNull(onFinally, "onFinally is null"); return RxJavaPlugins.onAssembly(new ObservableDoFinally(this, onFinally)); } /** * Calls the dispose {@code Action} if 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 {@code dispose()} call, * sometimes as a {@code CompositeException} if there were multiple exceptions along the way. *

* *

*
Scheduler:
*
{@code doOnDispose} does not operate by default on a particular {@link Scheduler}.
*
* * @param onDispose * the action that gets called when the source {@code ObservableSource}'s Disposable is disposed * @return the source {@code ObservableSource} modified so as to call this Action when appropriate * @throws NullPointerException if onDispose is null * @see ReactiveX operators documentation: Do */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable doOnDispose(Action onDispose) { return doOnLifecycle(Functions.emptyConsumer(), onDispose); } /** * Modifies the source ObservableSource so that it invokes an action when it calls {@code onComplete}. *

* *

*
Scheduler:
*
{@code doOnComplete} does not operate by default on a particular {@link Scheduler}.
*
* * @param onComplete * the action to invoke when the source ObservableSource calls {@code onComplete} * @return the source ObservableSource with the side-effecting behavior applied * @see ReactiveX operators documentation: Do */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable doOnComplete(Action onComplete) { return doOnEach(Functions.emptyConsumer(), Functions.emptyConsumer(), onComplete, Functions.EMPTY_ACTION); } /** * Calls the appropriate onXXX consumer (shared between all subscribers) whenever a signal with the same type * passes through, before forwarding them to downstream. *

* *

*
Scheduler:
*
{@code doOnEach} does not operate by default on a particular {@link Scheduler}.
*
* * @return the source ObservableSource with the side-effecting behavior applied * @see ReactiveX operators documentation: Do */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) private Observable doOnEach(Consumer onNext, Consumer onError, Action onComplete, Action onAfterTerminate) { ObjectHelper.requireNonNull(onNext, "onNext is null"); ObjectHelper.requireNonNull(onError, "onError is null"); ObjectHelper.requireNonNull(onComplete, "onComplete is null"); ObjectHelper.requireNonNull(onAfterTerminate, "onAfterTerminate is null"); return RxJavaPlugins.onAssembly(new ObservableDoOnEach(this, onNext, onError, onComplete, onAfterTerminate)); } /** * Modifies the source ObservableSource so that it invokes an action for each item it emits. *

* *

*
Scheduler:
*
{@code doOnEach} does not operate by default on a particular {@link Scheduler}.
*
* * @param onNotification * the action to invoke for each item emitted by the source ObservableSource * @return the source ObservableSource with the side-effecting behavior applied * @see ReactiveX operators documentation: Do */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable doOnEach(final Consumer> onNotification) { ObjectHelper.requireNonNull(onNotification, "onNotification is null"); return doOnEach( Functions.notificationOnNext(onNotification), Functions.notificationOnError(onNotification), Functions.notificationOnComplete(onNotification), Functions.EMPTY_ACTION ); } /** * Modifies the source ObservableSource so that it notifies an Observer for each item and terminal event it emits. *

* In case the {@code onError} of the supplied observer throws, the downstream will receive a composite * exception containing the original exception and the exception thrown by {@code onError}. If either the * {@code onNext} or the {@code onComplete} method of the supplied observer throws, the downstream will be * terminated and will receive this thrown exception. *

* *

*
Scheduler:
*
{@code doOnEach} does not operate by default on a particular {@link Scheduler}.
*
* * @param observer * the observer to be notified about onNext, onError and onComplete events on its * respective methods before the actual downstream Observer gets notified. * @return the source ObservableSource with the side-effecting behavior applied * @see ReactiveX operators documentation: Do */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable doOnEach(final Observer observer) { ObjectHelper.requireNonNull(observer, "observer is null"); return doOnEach( ObservableInternalHelper.observerOnNext(observer), ObservableInternalHelper.observerOnError(observer), ObservableInternalHelper.observerOnComplete(observer), Functions.EMPTY_ACTION); } /** * Modifies the source ObservableSource so that it invokes an action if it calls {@code onError}. *

* In case the {@code onError} action throws, the downstream will receive a composite exception containing * the original exception and the exception thrown by {@code onError}. *

* *

*
Scheduler:
*
{@code doOnError} does not operate by default on a particular {@link Scheduler}.
*
* * @param onError * the action to invoke if the source ObservableSource calls {@code onError} * @return the source ObservableSource with the side-effecting behavior applied * @see ReactiveX operators documentation: Do */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable doOnError(Consumer onError) { return doOnEach(Functions.emptyConsumer(), onError, Functions.EMPTY_ACTION, Functions.EMPTY_ACTION); } /** * Calls the appropriate onXXX method (shared between all Observer) for the lifecycle events of * the sequence (subscription, disposal). *

* *

*
Scheduler:
*
{@code doOnLifecycle} does not operate by default on a particular {@link Scheduler}.
*
* * @param onSubscribe * a Consumer called with the Disposable sent via Observer.onSubscribe() * @param onDispose * called when the downstream disposes the Disposable via dispose() * @return the source ObservableSource with the side-effecting behavior applied * @see ReactiveX operators documentation: Do */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable doOnLifecycle(final Consumer onSubscribe, final Action onDispose) { ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null"); ObjectHelper.requireNonNull(onDispose, "onDispose is null"); return RxJavaPlugins.onAssembly(new ObservableDoOnLifecycle(this, onSubscribe, onDispose)); } /** * Modifies the source ObservableSource so that it invokes an action when it calls {@code onNext}. *

* *

*
Scheduler:
*
{@code doOnNext} does not operate by default on a particular {@link Scheduler}.
*
* * @param onNext * the action to invoke when the source ObservableSource calls {@code onNext} * @return the source ObservableSource with the side-effecting behavior applied * @see ReactiveX operators documentation: Do */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable doOnNext(Consumer onNext) { return doOnEach(onNext, Functions.emptyConsumer(), Functions.EMPTY_ACTION, Functions.EMPTY_ACTION); } /** * Modifies the source {@code ObservableSource} so that it invokes the given action when it is subscribed from * its subscribers. Each subscription will result in an invocation of the given action except when the * source {@code ObservableSource} is reference counted, in which case the source {@code ObservableSource} will invoke * the given action for the first subscription. *

* *

*
Scheduler:
*
{@code doOnSubscribe} does not operate by default on a particular {@link Scheduler}.
*
* * @param onSubscribe * the Consumer that gets called when an Observer subscribes to the current {@code Observable} * @return the source {@code ObservableSource} modified so as to call this Consumer when appropriate * @see ReactiveX operators documentation: Do */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable doOnSubscribe(Consumer onSubscribe) { return doOnLifecycle(onSubscribe, Functions.EMPTY_ACTION); } /** * Modifies the source ObservableSource so that it invokes an action when it calls {@code onComplete} or * {@code onError}. *

* *

* This differs from {@code doAfterTerminate} in that this happens before the {@code onComplete} or * {@code onError} notification. *

*
Scheduler:
*
{@code doOnTerminate} does not operate by default on a particular {@link Scheduler}.
*
* * @param onTerminate * the action to invoke when the source ObservableSource calls {@code onComplete} or {@code onError} * @return the source ObservableSource with the side-effecting behavior applied * @see ReactiveX operators documentation: Do * @see #doAfterTerminate(Action) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable doOnTerminate(final Action onTerminate) { ObjectHelper.requireNonNull(onTerminate, "onTerminate is null"); return doOnEach(Functions.emptyConsumer(), Functions.actionConsumer(onTerminate), onTerminate, Functions.EMPTY_ACTION); } /** * Returns a Maybe that emits the single item at a specified index in a sequence of emissions from * this Observable or completes if this Observable signals fewer elements than index. *

* *

*
Scheduler:
*
{@code elementAt} does not operate by default on a particular {@link Scheduler}.
*
* * @param index * the zero-based index of the item to retrieve * @return a Maybe that emits a single item: the item at the specified position in the sequence of * those emitted by the source ObservableSource * @throws IndexOutOfBoundsException * if {@code index} is less than 0 * @see ReactiveX operators documentation: ElementAt */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe elementAt(long index) { if (index < 0) { throw new IndexOutOfBoundsException("index >= 0 required but it was " + index); } return RxJavaPlugins.onAssembly(new ObservableElementAtMaybe(this, index)); } /** * Returns a Single that emits the item found at a specified index in a sequence of emissions from * this Observable, or a default item if that index is out of range. *

* *

*
Scheduler:
*
{@code elementAt} does not operate by default on a particular {@link Scheduler}.
*
* * @param index * the zero-based index of the item to retrieve * @param defaultItem * the default item * @return a Single that emits the item at the specified position in the sequence emitted by the source * ObservableSource, or the default item if that index is outside the bounds of the source sequence * @throws IndexOutOfBoundsException * if {@code index} is less than 0 * @see ReactiveX operators documentation: ElementAt */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single elementAt(long index, T defaultItem) { if (index < 0) { throw new IndexOutOfBoundsException("index >= 0 required but it was " + index); } ObjectHelper.requireNonNull(defaultItem, "defaultItem is null"); return RxJavaPlugins.onAssembly(new ObservableElementAtSingle(this, index, defaultItem)); } /** * Returns a Single that emits the item found at a specified index in a sequence of emissions from this Observable * or signals a {@link NoSuchElementException} if this Observable signals fewer elements than index. *

* *

*
Scheduler:
*
{@code elementAtOrError} does not operate by default on a particular {@link Scheduler}.
*
* * @param index * the zero-based index of the item to retrieve * @return a Single that emits the item at the specified position in the sequence emitted by the source * ObservableSource, or the default item if that index is outside the bounds of the source sequence * @throws IndexOutOfBoundsException * if {@code index} is less than 0 * @see ReactiveX operators documentation: ElementAt */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single elementAtOrError(long index) { if (index < 0) { throw new IndexOutOfBoundsException("index >= 0 required but it was " + index); } return RxJavaPlugins.onAssembly(new ObservableElementAtSingle(this, index, null)); } /** * Filters items emitted by an ObservableSource by only emitting those that satisfy a specified predicate. *

* *

*
Scheduler:
*
{@code filter} does not operate by default on a particular {@link Scheduler}.
*
* * @param predicate * a function that evaluates each item emitted by the source ObservableSource, returning {@code true} * if it passes the filter * @return an Observable that emits only those items emitted by the source ObservableSource that the filter * evaluates as {@code true} * @see ReactiveX operators documentation: Filter */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable filter(Predicate predicate) { ObjectHelper.requireNonNull(predicate, "predicate is null"); return RxJavaPlugins.onAssembly(new ObservableFilter(this, predicate)); } /** * Returns a Maybe that emits only the very first item emitted by the source ObservableSource, or * completes if the source ObservableSource is empty. *

* *

*
Scheduler:
*
{@code firstElement} does not operate by default on a particular {@link Scheduler}.
*
* * @return the new Maybe instance * @see ReactiveX operators documentation: First */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe firstElement() { return elementAt(0L); } /** * Returns a Single that emits only the very first item emitted by the source ObservableSource, or a default item * if the source ObservableSource completes without emitting any items. *

* *

*
Scheduler:
*
{@code first} does not operate by default on a particular {@link Scheduler}.
*
* * @param defaultItem * the default item to emit if the source ObservableSource doesn't emit anything * @return the new Single instance * @see ReactiveX operators documentation: First */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single first(T defaultItem) { return elementAt(0L, defaultItem); } /** * Returns a Single that emits only the very first item emitted by this Observable or * signals a {@link NoSuchElementException} if this Observable is empty. *

* *

*
Scheduler:
*
{@code firstOrError} does not operate by default on a particular {@link Scheduler}.
*
* * @return the new Single instance * @see ReactiveX operators documentation: First */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single firstOrError() { return elementAtOrError(0L); } /** * Returns an Observable that emits items based on applying a function that you supply to each item emitted * by the source ObservableSource, where that function returns an ObservableSource, and then merging those resulting * ObservableSources and emitting the results of this merger. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the inner ObservableSources and the output type * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns an * ObservableSource * @return an Observable that emits the result of applying the transformation function to each item emitted * by the source ObservableSource and merging the results of the ObservableSources obtained from this * transformation * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMap(Function> mapper) { return flatMap(mapper, false); } /** * Returns an Observable that emits items based on applying a function that you supply to each item emitted * by the source ObservableSource, where that function returns an ObservableSource, and then merging those resulting * ObservableSources and emitting the results of this merger. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the inner ObservableSources and the output type * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns an * ObservableSource * @param delayErrors * if true, exceptions from the current Observable and all inner ObservableSources are delayed until all of them terminate * if false, the first one signalling an exception will terminate the whole sequence immediately * @return an Observable that emits the result of applying the transformation function to each item emitted * by the source ObservableSource and merging the results of the ObservableSources obtained from this * transformation * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMap(Function> mapper, boolean delayErrors) { return flatMap(mapper, delayErrors, Integer.MAX_VALUE); } /** * Returns an Observable that emits items based on applying a function that you supply to each item emitted * by the source ObservableSource, where that function returns an ObservableSource, and then merging those resulting * ObservableSources and emitting the results of this merger, while limiting the maximum number of concurrent * subscriptions to these ObservableSources. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the inner ObservableSources and the output type * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns an * ObservableSource * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @param delayErrors * if true, exceptions from the current Observable and all inner ObservableSources are delayed until all of them terminate * if false, the first one signalling an exception will terminate the whole sequence immediately * @return an Observable that emits the result of applying the transformation function to each item emitted * by the source ObservableSource and merging the results of the ObservableSources obtained from this * transformation * @see ReactiveX operators documentation: FlatMap * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMap(Function> mapper, boolean delayErrors, int maxConcurrency) { return flatMap(mapper, delayErrors, maxConcurrency, bufferSize()); } /** * Returns an Observable that emits items based on applying a function that you supply to each item emitted * by the source ObservableSource, where that function returns an ObservableSource, and then merging those resulting * ObservableSources and emitting the results of this merger, while limiting the maximum number of concurrent * subscriptions to these ObservableSources. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the inner ObservableSources and the output type * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns an * ObservableSource * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @param delayErrors * if true, exceptions from the current Observable and all inner ObservableSources are delayed until all of them terminate * if false, the first one signalling an exception will terminate the whole sequence immediately * @param bufferSize * the number of elements to prefetch from each inner ObservableSource * @return an Observable that emits the result of applying the transformation function to each item emitted * by the source ObservableSource and merging the results of the ObservableSources obtained from this * transformation * @see ReactiveX operators documentation: FlatMap * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMap(Function> mapper, boolean delayErrors, int maxConcurrency, int bufferSize) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); if (this instanceof ScalarCallable) { @SuppressWarnings("unchecked") T v = ((ScalarCallable)this).call(); if (v == null) { return empty(); } return ObservableScalarXMap.scalarXMap(v, mapper); } return RxJavaPlugins.onAssembly(new ObservableFlatMap(this, mapper, delayErrors, maxConcurrency, bufferSize)); } /** * Returns an Observable that applies a function to each item emitted or notification raised by the source * ObservableSource and then flattens the ObservableSources returned from these functions and emits the resulting items. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the result type * @param onNextMapper * a function that returns an ObservableSource to merge for each item emitted by the source ObservableSource * @param onErrorMapper * a function that returns an ObservableSource to merge for an onError notification from the source * ObservableSource * @param onCompleteSupplier * a function that returns an ObservableSource to merge for an onComplete notification from the source * ObservableSource * @return an Observable that emits the results of merging the ObservableSources returned from applying the * specified functions to the emissions and notifications of the source ObservableSource * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMap( Function> onNextMapper, Function> onErrorMapper, Callable> onCompleteSupplier) { ObjectHelper.requireNonNull(onNextMapper, "onNextMapper is null"); ObjectHelper.requireNonNull(onErrorMapper, "onErrorMapper is null"); ObjectHelper.requireNonNull(onCompleteSupplier, "onCompleteSupplier is null"); return merge(new ObservableMapNotification(this, onNextMapper, onErrorMapper, onCompleteSupplier)); } /** * Returns an Observable that applies a function to each item emitted or notification raised by the source * ObservableSource and then flattens the ObservableSources returned from these functions and emits the resulting items, * while limiting the maximum number of concurrent subscriptions to these ObservableSources. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the result type * @param onNextMapper * a function that returns an ObservableSource to merge for each item emitted by the source ObservableSource * @param onErrorMapper * a function that returns an ObservableSource to merge for an onError notification from the source * ObservableSource * @param onCompleteSupplier * a function that returns an ObservableSource to merge for an onComplete notification from the source * ObservableSource * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @return an Observable that emits the results of merging the ObservableSources returned from applying the * specified functions to the emissions and notifications of the source ObservableSource * @see ReactiveX operators documentation: FlatMap * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMap( Function> onNextMapper, Function> onErrorMapper, Callable> onCompleteSupplier, int maxConcurrency) { ObjectHelper.requireNonNull(onNextMapper, "onNextMapper is null"); ObjectHelper.requireNonNull(onErrorMapper, "onErrorMapper is null"); ObjectHelper.requireNonNull(onCompleteSupplier, "onCompleteSupplier is null"); return merge(new ObservableMapNotification(this, onNextMapper, onErrorMapper, onCompleteSupplier), maxConcurrency); } /** * Returns an Observable that emits items based on applying a function that you supply to each item emitted * by the source ObservableSource, where that function returns an ObservableSource, and then merging those resulting * ObservableSources and emitting the results of this merger, while limiting the maximum number of concurrent * subscriptions to these ObservableSources. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the inner ObservableSources and the output type * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns an * ObservableSource * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @return an Observable that emits the result of applying the transformation function to each item emitted * by the source ObservableSource and merging the results of the ObservableSources obtained from this * transformation * @see ReactiveX operators documentation: FlatMap * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMap(Function> mapper, int maxConcurrency) { return flatMap(mapper, false, maxConcurrency, bufferSize()); } /** * Returns an Observable that emits the results of a specified function to the pair of values emitted by the * source ObservableSource and a specified collection ObservableSource. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items emitted by the collection ObservableSource * @param * the type of items emitted by the resulting ObservableSource * @param mapper * a function that returns an ObservableSource for each item emitted by the source ObservableSource * @param resultSelector * a function that combines one item emitted by each of the source and collection ObservableSources and * returns an item to be emitted by the resulting ObservableSource * @return an Observable that emits the results of applying a function to a pair of values emitted by the * source ObservableSource and the collection ObservableSource * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMap(Function> mapper, BiFunction resultSelector) { return flatMap(mapper, resultSelector, false, bufferSize(), bufferSize()); } /** * Returns an Observable that emits the results of a specified function to the pair of values emitted by the * source ObservableSource and a specified collection ObservableSource. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items emitted by the collection ObservableSource * @param * the type of items emitted by the resulting ObservableSource * @param mapper * a function that returns an ObservableSource for each item emitted by the source ObservableSource * @param combiner * a function that combines one item emitted by each of the source and collection ObservableSources and * returns an item to be emitted by the resulting ObservableSource * @param delayErrors * if true, exceptions from the current Observable and all inner ObservableSources are delayed until all of them terminate * if false, the first one signalling an exception will terminate the whole sequence immediately * @return an Observable that emits the results of applying a function to a pair of values emitted by the * source ObservableSource and the collection ObservableSource * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMap(Function> mapper, BiFunction combiner, boolean delayErrors) { return flatMap(mapper, combiner, delayErrors, bufferSize(), bufferSize()); } /** * Returns an Observable that emits the results of a specified function to the pair of values emitted by the * source ObservableSource and a specified collection ObservableSource, while limiting the maximum number of concurrent * subscriptions to these ObservableSources. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items emitted by the collection ObservableSource * @param * the type of items emitted by the resulting ObservableSource * @param mapper * a function that returns an ObservableSource for each item emitted by the source ObservableSource * @param combiner * a function that combines one item emitted by each of the source and collection ObservableSources and * returns an item to be emitted by the resulting ObservableSource * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @param delayErrors * if true, exceptions from the current Observable and all inner ObservableSources are delayed until all of them terminate * if false, the first one signalling an exception will terminate the whole sequence immediately * @return an Observable that emits the results of applying a function to a pair of values emitted by the * source ObservableSource and the collection ObservableSource * @see ReactiveX operators documentation: FlatMap * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMap(Function> mapper, BiFunction combiner, boolean delayErrors, int maxConcurrency) { return flatMap(mapper, combiner, delayErrors, maxConcurrency, bufferSize()); } /** * Returns an Observable that emits the results of a specified function to the pair of values emitted by the * source ObservableSource and a specified collection ObservableSource, while limiting the maximum number of concurrent * subscriptions to these ObservableSources. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items emitted by the collection ObservableSource * @param * the type of items emitted by the resulting ObservableSource * @param mapper * a function that returns an ObservableSource for each item emitted by the source ObservableSource * @param combiner * a function that combines one item emitted by each of the source and collection ObservableSources and * returns an item to be emitted by the resulting ObservableSource * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @param delayErrors * if true, exceptions from the current Observable and all inner ObservableSources are delayed until all of them terminate * if false, the first one signalling an exception will terminate the whole sequence immediately * @param bufferSize * the number of elements to prefetch from the inner ObservableSources. * @return an Observable that emits the results of applying a function to a pair of values emitted by the * source ObservableSource and the collection ObservableSource * @see ReactiveX operators documentation: FlatMap * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMap(final Function> mapper, final BiFunction combiner, boolean delayErrors, int maxConcurrency, int bufferSize) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.requireNonNull(combiner, "combiner is null"); return flatMap(ObservableInternalHelper.flatMapWithCombiner(mapper, combiner), delayErrors, maxConcurrency, bufferSize); } /** * Returns an Observable that emits the results of a specified function to the pair of values emitted by the * source ObservableSource and a specified collection ObservableSource, while limiting the maximum number of concurrent * subscriptions to these ObservableSources. *

* *

*
Scheduler:
*
{@code flatMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items emitted by the collection ObservableSource * @param * the type of items emitted by the resulting ObservableSource * @param mapper * a function that returns an ObservableSource for each item emitted by the source ObservableSource * @param combiner * a function that combines one item emitted by each of the source and collection ObservableSources and * returns an item to be emitted by the resulting ObservableSource * @param maxConcurrency * the maximum number of ObservableSources that may be subscribed to concurrently * @return an Observable that emits the results of applying a function to a pair of values emitted by the * source ObservableSource and the collection ObservableSource * @see ReactiveX operators documentation: FlatMap * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMap(Function> mapper, BiFunction combiner, int maxConcurrency) { return flatMap(mapper, combiner, false, maxConcurrency, bufferSize()); } /** * Maps each element of the upstream Observable into CompletableSources, subscribes to them and * waits until the upstream and all CompletableSources complete. *

* *

*
Scheduler:
*
{@code flatMapCompletable} does not operate by default on a particular {@link Scheduler}.
*
* @param mapper the function that received each source value and transforms them into CompletableSources. * @return the new Completable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable flatMapCompletable(Function mapper) { return flatMapCompletable(mapper, false); } /** * Maps each element of the upstream Observable into CompletableSources, subscribes to them and * waits until the upstream and all CompletableSources complete, optionally delaying all errors. *

* *

*
Scheduler:
*
{@code flatMapCompletable} does not operate by default on a particular {@link Scheduler}.
*
* @param mapper the function that received each source value and transforms them into CompletableSources. * @param delayErrors if true errors from the upstream and inner CompletableSources are delayed until each of them * terminates. * @return the new Completable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable flatMapCompletable(Function mapper, boolean delayErrors) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableFlatMapCompletableCompletable(this, mapper, delayErrors)); } /** * Returns an Observable that merges each item emitted by the source ObservableSource with the values in an * Iterable corresponding to that item that is generated by a selector. *

* *

*
Scheduler:
*
{@code flatMapIterable} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of item emitted by the resulting Iterable * @param mapper * a function that returns an Iterable sequence of values for when given an item emitted by the * source ObservableSource * @return an Observable that emits the results of merging the items emitted by the source ObservableSource with * the values in the Iterables corresponding to those items, as generated by {@code collectionSelector} * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMapIterable(final Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableFlattenIterable(this, mapper)); } /** * Returns an Observable that emits the results of applying a function to the pair of values from the source * ObservableSource and an Iterable corresponding to that item that is generated by a selector. *

* *

*
Scheduler:
*
{@code flatMapIterable} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the collection element type * @param * the type of item emitted by the resulting Iterable * @param mapper * a function that returns an Iterable sequence of values for each item emitted by the source * ObservableSource * @param resultSelector * a function that returns an item based on the item emitted by the source ObservableSource and the * Iterable returned for that item by the {@code collectionSelector} * @return an Observable that emits the items returned by {@code resultSelector} for each item in the source * ObservableSource * @see ReactiveX operators documentation: FlatMap */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMapIterable(final Function> mapper, BiFunction resultSelector) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.requireNonNull(resultSelector, "resultSelector is null"); return flatMap(ObservableInternalHelper.flatMapIntoIterable(mapper), resultSelector, false, bufferSize(), bufferSize()); } /** * Maps each element of the upstream Observable into MaybeSources, subscribes to all of them * and merges their onSuccess values, in no particular order, into a single Observable sequence. *

* *

*
Scheduler:
*
{@code flatMapMaybe} does not operate by default on a particular {@link Scheduler}.
*
* @param the result value type * @param mapper the function that received each source value and transforms them into MaybeSources. * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMapMaybe(Function> mapper) { return flatMapMaybe(mapper, false); } /** * Maps each element of the upstream Observable into MaybeSources, subscribes to them * and merges their onSuccess values, in no particular order, into a single Observable sequence, * optionally delaying all errors. *

* *

*
Scheduler:
*
{@code flatMapMaybe} does not operate by default on a particular {@link Scheduler}.
*
* @param the result value type * @param mapper the function that received each source value and transforms them into MaybeSources. * @param delayErrors if true errors from the upstream and inner MaybeSources are delayed until each of them * terminates. * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMapMaybe(Function> mapper, boolean delayErrors) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableFlatMapMaybe(this, mapper, delayErrors)); } /** * Maps each element of the upstream Observable into SingleSources, subscribes to all of them * and merges their onSuccess values, in no particular order, into a single Observable sequence. *

* *

*
Scheduler:
*
{@code flatMapSingle} does not operate by default on a particular {@link Scheduler}.
*
* @param the result value type * @param mapper the function that received each source value and transforms them into SingleSources. * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMapSingle(Function> mapper) { return flatMapSingle(mapper, false); } /** * Maps each element of the upstream Observable into SingleSources, subscribes to them * and merges their onSuccess values, in no particular order, into a single Observable sequence, * optionally delaying all errors. *

* *

*
Scheduler:
*
{@code flatMapSingle} does not operate by default on a particular {@link Scheduler}.
*
* @param the result value type * @param mapper the function that received each source value and transforms them into SingleSources. * @param delayErrors if true errors from the upstream and inner SingleSources are delayed until each of them * terminates. * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable flatMapSingle(Function> mapper, boolean delayErrors) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableFlatMapSingle(this, mapper, delayErrors)); } /** * Subscribes to the {@link ObservableSource} and receives notifications for each element. *

* *

* Alias to {@link #subscribe(Consumer)} *

*
Scheduler:
*
{@code forEach} does not operate by default on a particular {@link Scheduler}.
*
* * @param onNext * {@link Consumer} to execute for each item. * @return * a Disposable that allows disposing of an asynchronous sequence * @throws NullPointerException * if {@code onNext} is null * @see ReactiveX operators documentation: Subscribe */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Disposable forEach(Consumer onNext) { return subscribe(onNext); } /** * Subscribes to the {@link ObservableSource} and receives notifications for each element until the * onNext Predicate returns false. *

* *

* If the Observable emits an error, it is wrapped into an * {@link io.reactivex.exceptions.OnErrorNotImplementedException OnErrorNotImplementedException} * and routed to the RxJavaPlugins.onError handler. *

*
Scheduler:
*
{@code forEachWhile} does not operate by default on a particular {@link Scheduler}.
*
* * @param onNext * {@link Predicate} to execute for each item. * @return * a Disposable that allows disposing of an asynchronous sequence * @throws NullPointerException * if {@code onNext} is null * @see ReactiveX operators documentation: Subscribe */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Disposable forEachWhile(Predicate onNext) { return forEachWhile(onNext, Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION); } /** * Subscribes to the {@link ObservableSource} and receives notifications for each element and error events until the * onNext Predicate returns false. *
*
Scheduler:
*
{@code forEachWhile} does not operate by default on a particular {@link Scheduler}.
*
* * @param onNext * {@link Predicate} to execute for each item. * @param onError * {@link Consumer} to execute when an error is emitted. * @return * a Disposable that allows disposing of an asynchronous sequence * @throws NullPointerException * if {@code onNext} is null, or * if {@code onError} is null * @see ReactiveX operators documentation: Subscribe */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Disposable forEachWhile(Predicate onNext, Consumer onError) { return forEachWhile(onNext, onError, Functions.EMPTY_ACTION); } /** * Subscribes to the {@link ObservableSource} and receives notifications for each element and the terminal events until the * onNext Predicate returns false. *
*
Scheduler:
*
{@code forEachWhile} does not operate by default on a particular {@link Scheduler}.
*
* * @param onNext * {@link Predicate} to execute for each item. * @param onError * {@link Consumer} to execute when an error is emitted. * @param onComplete * {@link Action} to execute when completion is signalled. * @return * a Disposable that allows disposing of an asynchronous sequence * @throws NullPointerException * if {@code onNext} is null, or * if {@code onError} is null, or * if {@code onComplete} is null * @see ReactiveX operators documentation: Subscribe */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Disposable forEachWhile(final Predicate onNext, Consumer onError, final Action onComplete) { ObjectHelper.requireNonNull(onNext, "onNext is null"); ObjectHelper.requireNonNull(onError, "onError is null"); ObjectHelper.requireNonNull(onComplete, "onComplete is null"); ForEachWhileObserver o = new ForEachWhileObserver(onNext, onError, onComplete); subscribe(o); return o; } /** * Groups the items emitted by an {@code ObservableSource} according to a specified criterion, and emits these * grouped items as {@link GroupedObservable}s. The emitted {@code GroupedObservableSource} allows only a single * {@link Observer} during its lifetime and if this {@code Observer} calls dispose() before the * source terminates, the next emission by the source having the same key will trigger a new * {@code GroupedObservableSource} emission. *

* *

* Note: A {@link GroupedObservable} will 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 those * {@code GroupedObservableSource}s that do not concern you. Instead, you can signal to them that they may * discard their buffers by applying an operator like {@link #ignoreElements} to them. *

*
Scheduler:
*
{@code groupBy} does not operate by default on a particular {@link Scheduler}.
*
* * @param keySelector * a function that extracts the key for each item * @param * the key type * @return an {@code ObservableSource} that emits {@link GroupedObservable}s, each of which corresponds to a * unique key value and each of which emits those items from the source ObservableSource that share that * key value * @see ReactiveX operators documentation: GroupBy */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> groupBy(Function keySelector) { return groupBy(keySelector, (Function)Functions.identity(), false, bufferSize()); } /** * Groups the items emitted by an {@code ObservableSource} according to a specified criterion, and emits these * grouped items as {@link GroupedObservable}s. The emitted {@code GroupedObservableSource} allows only a single * {@link Observer} during its lifetime and if this {@code Observer} calls dispose() before the * source terminates, the next emission by the source having the same key will trigger a new * {@code GroupedObservableSource} emission. *

* *

* Note: A {@link GroupedObservable} will 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 those * {@code GroupedObservableSource}s that do not concern you. Instead, you can signal to them that they may * discard their buffers by applying an operator like {@link #ignoreElements} to them. *

*
Scheduler:
*
{@code groupBy} does not operate by default on a particular {@link Scheduler}.
*
* * @param keySelector * a function that extracts the key for each item * @param * the key type * @param delayError * if true, the exception from the current Observable is delayed in each group until that specific group emitted * the normal values; if false, the exception bypasses values in the groups and is reported immediately. * @return an {@code ObservableSource} that emits {@link GroupedObservable}s, each of which corresponds to a * unique key value and each of which emits those items from the source ObservableSource that share that * key value * @see ReactiveX operators documentation: GroupBy */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> groupBy(Function keySelector, boolean delayError) { return groupBy(keySelector, (Function)Functions.identity(), delayError, bufferSize()); } /** * Groups the items emitted by an {@code ObservableSource} according to a specified criterion, and emits these * grouped items as {@link GroupedObservable}s. The emitted {@code GroupedObservableSource} allows only a single * {@link Observer} during its lifetime and if this {@code Observer} calls dispose() before the * source terminates, the next emission by the source having the same key will trigger a new * {@code GroupedObservableSource} emission. *

* *

* Note: A {@link GroupedObservable} will 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 those * {@code GroupedObservableSource}s that do not concern you. Instead, you can signal to them that they may * discard their buffers by applying an operator like {@link #ignoreElements} to them. *

*
Scheduler:
*
{@code groupBy} does not operate by default on a particular {@link Scheduler}.
*
* * @param keySelector * a function that extracts the key for each item * @param valueSelector * a function that extracts the return element for each item * @param * the key type * @param * the element type * @return an {@code ObservableSource} that emits {@link GroupedObservable}s, each of which corresponds to a * unique key value and each of which emits those items from the source ObservableSource that share that * key value * @see ReactiveX operators documentation: GroupBy */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> groupBy(Function keySelector, Function valueSelector) { return groupBy(keySelector, valueSelector, false, bufferSize()); } /** * Groups the items emitted by an {@code ObservableSource} according to a specified criterion, and emits these * grouped items as {@link GroupedObservable}s. The emitted {@code GroupedObservableSource} allows only a single * {@link Observer} during its lifetime and if this {@code Observer} calls dispose() before the * source terminates, the next emission by the source having the same key will trigger a new * {@code GroupedObservableSource} emission. *

* *

* Note: A {@link GroupedObservable} will 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 those * {@code GroupedObservableSource}s that do not concern you. Instead, you can signal to them that they may * discard their buffers by applying an operator like {@link #ignoreElements} to them. *

*
Scheduler:
*
{@code groupBy} does not operate by default on a particular {@link Scheduler}.
*
* * @param keySelector * a function that extracts the key for each item * @param valueSelector * a function that extracts the return element for each item * @param * the key type * @param * the element type * @param delayError * if true, the exception from the current Observable is delayed in each group until that specific group emitted * the normal values; if false, the exception bypasses values in the groups and is reported immediately. * @return an {@code ObservableSource} that emits {@link GroupedObservable}s, each of which corresponds to a * unique key value and each of which emits those items from the source ObservableSource that share that * key value * @see ReactiveX operators documentation: GroupBy */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> groupBy(Function keySelector, Function valueSelector, boolean delayError) { return groupBy(keySelector, valueSelector, delayError, bufferSize()); } /** * Groups the items emitted by an {@code ObservableSource} according to a specified criterion, and emits these * grouped items as {@link GroupedObservable}s. The emitted {@code GroupedObservableSource} allows only a single * {@link Observer} during its lifetime and if this {@code Observer} calls dispose() before the * source terminates, the next emission by the source having the same key will trigger a new * {@code GroupedObservableSource} emission. *

* *

* Note: A {@link GroupedObservable} will 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 those * {@code GroupedObservableSource}s that do not concern you. Instead, you can signal to them that they may * discard their buffers by applying an operator like {@link #ignoreElements} to them. *

*
Scheduler:
*
{@code groupBy} does not operate by default on a particular {@link Scheduler}.
*
* * @param keySelector * a function that extracts the key for each item * @param valueSelector * a function that extracts the return element for each item * @param delayError * if true, the exception from the current Observable is delayed in each group until that specific group emitted * the normal values; if false, the exception bypasses values in the groups and is reported immediately. * @param bufferSize * the hint for how many {@link GroupedObservable}s and element in each {@link GroupedObservable} should be buffered * @param * the key type * @param * the element type * @return an {@code ObservableSource} that emits {@link GroupedObservable}s, each of which corresponds to a * unique key value and each of which emits those items from the source ObservableSource that share that * key value * @see ReactiveX operators documentation: GroupBy */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> groupBy(Function keySelector, Function valueSelector, boolean delayError, int bufferSize) { ObjectHelper.requireNonNull(keySelector, "keySelector is null"); ObjectHelper.requireNonNull(valueSelector, "valueSelector is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return RxJavaPlugins.onAssembly(new ObservableGroupBy(this, keySelector, valueSelector, bufferSize, delayError)); } /** * Returns an Observable that correlates two ObservableSources 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:
*
{@code groupJoin} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the right ObservableSource source * @param the element type of the left duration ObservableSources * @param the element type of the right duration ObservableSources * @param the result type * @param other * the other ObservableSource to correlate items from the source ObservableSource with * @param leftEnd * a function that returns an ObservableSource whose emissions indicate the duration of the values of * the source ObservableSource * @param rightEnd * a function that returns an ObservableSource whose emissions indicate the duration of the values of * the {@code right} ObservableSource * @param resultSelector * a function that takes an item emitted by each ObservableSource and returns the value to be emitted * by the resulting ObservableSource * @return an Observable that emits items based on combining those items emitted by the source ObservableSources * whose durations overlap * @see ReactiveX operators documentation: Join */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable groupJoin( ObservableSource other, Function> leftEnd, Function> rightEnd, BiFunction, ? extends R> resultSelector ) { ObjectHelper.requireNonNull(other, "other is null"); ObjectHelper.requireNonNull(leftEnd, "leftEnd is null"); ObjectHelper.requireNonNull(rightEnd, "rightEnd is null"); ObjectHelper.requireNonNull(resultSelector, "resultSelector is null"); return RxJavaPlugins.onAssembly(new ObservableGroupJoin( this, other, leftEnd, rightEnd, resultSelector)); } /** * Hides the identity of this Observable and its Disposable. *

Allows hiding extra features such as {@link io.reactivex.subjects.Subject}'s * {@link Observer} methods or preventing certain identity-based * optimizations (fusion). *

* *

*
Scheduler:
*
{@code hide} does not operate by default on a particular {@link Scheduler}.
*
* @return the new Observable instance * * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable hide() { return RxJavaPlugins.onAssembly(new ObservableHide(this)); } /** * Ignores all items emitted by the source ObservableSource and only calls {@code onComplete} or {@code onError}. *

* *

*
Scheduler:
*
{@code ignoreElements} does not operate by default on a particular {@link Scheduler}.
*
* * @return the new Completable instance * @see ReactiveX operators documentation: IgnoreElements */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable ignoreElements() { return RxJavaPlugins.onAssembly(new ObservableIgnoreElementsCompletable(this)); } /** * Returns a Single that emits {@code true} if the source ObservableSource is empty, otherwise {@code false}. *

* In Rx.Net this is negated as the {@code any} Observer but we renamed this in RxJava to better match Java * naming idioms. *

* *

*
Scheduler:
*
{@code isEmpty} does not operate by default on a particular {@link Scheduler}.
*
* * @return a Single that emits a Boolean * @see ReactiveX operators documentation: Contains */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single isEmpty() { return all(Functions.alwaysFalse()); } /** * Correlates the items emitted by two ObservableSources 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:
*
{@code join} does not operate by default on a particular {@link Scheduler}.
*
* * @param the value type of the right ObservableSource source * @param the element type of the left duration ObservableSources * @param the element type of the right duration ObservableSources * @param the result type * @param other * the second ObservableSource to join items from * @param leftEnd * a function to select a duration for each item emitted by the source ObservableSource, used to * determine overlap * @param rightEnd * a function to select a duration for each item emitted by the {@code right} ObservableSource, used to * determine overlap * @param resultSelector * a function that computes an item to be emitted by the resulting ObservableSource for any two * overlapping items emitted by the two ObservableSources * @return an Observable that emits items correlating to items emitted by the source ObservableSources that have * overlapping durations * @see ReactiveX operators documentation: Join */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable join( ObservableSource other, Function> leftEnd, Function> rightEnd, BiFunction resultSelector ) { ObjectHelper.requireNonNull(other, "other is null"); ObjectHelper.requireNonNull(leftEnd, "leftEnd is null"); ObjectHelper.requireNonNull(rightEnd, "rightEnd is null"); ObjectHelper.requireNonNull(resultSelector, "resultSelector is null"); return RxJavaPlugins.onAssembly(new ObservableJoin( this, other, leftEnd, rightEnd, resultSelector)); } /** * Returns a Maybe that emits the last item emitted by this Observable or * completes if this Observable is empty. *

* *

*
Scheduler:
*
{@code lastElement} does not operate by default on a particular {@link Scheduler}.
*
* * @return a Maybe that emits the last item from the source ObservableSource or notifies observers of an * error * @see ReactiveX operators documentation: Last */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe lastElement() { return RxJavaPlugins.onAssembly(new ObservableLastMaybe(this)); } /** * Returns a Single that emits only the last item emitted by this Observable, or a default item * if this Observable completes without emitting any items. *

* *

*
Scheduler:
*
{@code last} does not operate by default on a particular {@link Scheduler}.
*
* * @param defaultItem * the default item to emit if the source ObservableSource is empty * @return a Single that emits only the last item emitted by the source ObservableSource, or a default item * if the source ObservableSource is empty * @see ReactiveX operators documentation: Last */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single last(T defaultItem) { ObjectHelper.requireNonNull(defaultItem, "defaultItem is null"); return RxJavaPlugins.onAssembly(new ObservableLastSingle(this, defaultItem)); } /** * Returns a Single that emits only the last item emitted by this Observable or * signals a {@link NoSuchElementException} if this Observable is empty. *

* *

*
Scheduler:
*
{@code lastOrError} does not operate by default on a particular {@link Scheduler}.
*
* * @return a Single that emits only the last item emitted by the source ObservableSource. * If the source ObservableSource completes without emitting any items a {@link NoSuchElementException} will be thrown. * @see ReactiveX operators documentation: Last */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single lastOrError() { return RxJavaPlugins.onAssembly(new ObservableLastSingle(this, null)); } /** * This method requires advanced knowledge about building operators, please consider * other standard composition methods first; * Returns an {@code Observable} which, when subscribed to, invokes the {@link ObservableOperator#apply(Observer) apply(Observer)} method * of the provided {@link ObservableOperator} for each individual downstream {@link Observer} and allows the * insertion of a custom operator by accessing the downstream's {@link Observer} during this subscription phase * and providing a new {@code Observer}, containing the custom operator's intended business logic, that will be * used in the subscription process going further upstream. *

* Generally, such a new {@code Observer} will wrap the downstream's {@code Observer} and forwards the * {@code onNext}, {@code onError} and {@code onComplete} events 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 of {@code dispose} and {@code isDisposed} that 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 {@code lift()} method adds slightly more overhead by requiring * an additional allocation and indirection per assembled flows. Instead, extending the abstract {@code Observable} * class and creating an {@link ObservableTransformer} with it is recommended. *

* Note also that it is not possible to stop the subscription phase in {@code lift()} as the {@code apply()} method * requires a non-null {@code Observer} instance to be returned, which is then unconditionally subscribed to * the upstream {@code Observable}. 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 an {@code Observer} that should immediately dispose the upstream's {@code Disposable} in its * {@code onSubscribe} method. Again, using an {@code ObservableTransformer} and extending the {@code Observable} is * a better option as {@link #subscribeActual} can decide to not subscribe to its upstream after all. *

*
Scheduler:
*
{@code lift} does not operate by default on a particular {@link Scheduler}, however, the * {@link ObservableOperator} may use a {@code Scheduler} to support its own asynchronous behavior.
*
* * @param the output value type * @param lifter the {@link ObservableOperator} that receives the downstream's {@code Observer} and should return * an {@code Observer} with custom behavior to be used as the consumer for the current * {@code Observable}. * @return the new Observable instance * @see RxJava wiki: Writing operators * @see #compose(ObservableTransformer) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable lift(ObservableOperator lifter) { ObjectHelper.requireNonNull(lifter, "lifter is null"); return RxJavaPlugins.onAssembly(new ObservableLift(this, lifter)); } /** * Returns an Observable that applies a specified function to each item emitted by the source ObservableSource and * emits the results of these function applications. *

* *

*
Scheduler:
*
{@code map} does not operate by default on a particular {@link Scheduler}.
*
* * @param the output type * @param mapper * a function to apply to each item emitted by the ObservableSource * @return an Observable that emits the items from the source ObservableSource, transformed by the specified * function * @see ReactiveX operators documentation: Map */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable map(Function mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableMap(this, mapper)); } /** * Returns an Observable that represents all of the emissions and notifications from the source * ObservableSource into emissions marked with their original types within {@link Notification} objects. *

* *

*
Scheduler:
*
{@code materialize} does not operate by default on a particular {@link Scheduler}.
*
* * @return an Observable that emits items that are the result of materializing the items and notifications * of the source ObservableSource * @see ReactiveX operators documentation: Materialize * @see #dematerialize(Function) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> materialize() { return RxJavaPlugins.onAssembly(new ObservableMaterialize(this)); } /** * Flattens this and another ObservableSource into a single ObservableSource, without any transformation. *

* *

* You can combine items emitted by multiple ObservableSources so that they appear as a single ObservableSource, by * using the {@code mergeWith} method. *

*
Scheduler:
*
{@code mergeWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param other * an ObservableSource to be merged * @return an Observable that emits all of the items emitted by the source ObservableSources * @see ReactiveX operators documentation: Merge */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable mergeWith(ObservableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return merge(this, other); } /** * Merges the sequence of items of this Observable with the success value of the other SingleSource. *

* *

* The success value of the other {@code SingleSource} can get interleaved at any point of this * {@code Observable} sequence. *

*
Scheduler:
*
{@code mergeWith} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.10 - experimental * @param other the {@code SingleSource} whose success value to merge with * @return the new Observable instance * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable mergeWith(@NonNull SingleSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableMergeWithSingle(this, other)); } /** * Merges the sequence of items of this Observable with the success value of the other MaybeSource * or waits both to complete normally if the MaybeSource is empty. *

* *

* The success value of the other {@code MaybeSource} can get interleaved at any point of this * {@code Observable} sequence. *

*
Scheduler:
*
{@code mergeWith} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.10 - experimental * @param other the {@code MaybeSource} which provides a success value to merge with or completes * @return the new Observable instance * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable mergeWith(@NonNull MaybeSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableMergeWithMaybe(this, other)); } /** * Relays the items of this Observable and completes only when the other CompletableSource completes * as well. *

* *

*
Scheduler:
*
{@code mergeWith} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.10 - experimental * @param other the {@code CompletableSource} to await for completion * @return the new Observable instance * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable mergeWith(@NonNull CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableMergeWithCompletable(this, other)); } /** * Modifies an ObservableSource to perform its emissions and notifications on a specified {@link Scheduler}, * asynchronously with an unbounded buffer with {@link Flowable#bufferSize()} "island size". * *

Note that onError notifications will cut ahead of onNext notifications on the emission thread if Scheduler is truly * asynchronous. If strict event ordering is required, consider using the {@link #observeOn(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 {@link Scheduler} this 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. * * @param scheduler * the {@link Scheduler} to notify {@link Observer}s on * @return the source ObservableSource modified so that its {@link Observer}s are notified on the specified * {@link Scheduler} * @see ReactiveX operators documentation: ObserveOn * @see RxJava Threading Examples * @see #subscribeOn * @see #observeOn(Scheduler, boolean) * @see #observeOn(Scheduler, boolean, int) * @see #delay(long, TimeUnit, Scheduler) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable observeOn(Scheduler scheduler) { return observeOn(scheduler, false, bufferSize()); } /** * Modifies an ObservableSource to perform its emissions and notifications on a specified {@link Scheduler}, * asynchronously with an unbounded buffer with {@link Flowable#bufferSize()} "island size" and optionally delays onError notifications. *

* *

* 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 {@link Scheduler} this 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. * * @param scheduler * the {@link Scheduler} to notify {@link Observer}s on * @param delayError * indicates if the onError notification may not cut ahead of onNext notification on the other side of the * scheduling boundary. If true a sequence ending in onError will be replayed in the same order as was received * from upstream * @return the source ObservableSource modified so that its {@link Observer}s are notified on the specified * {@link Scheduler} * @see ReactiveX operators documentation: ObserveOn * @see RxJava Threading Examples * @see #subscribeOn * @see #observeOn(Scheduler) * @see #observeOn(Scheduler, boolean, int) * @see #delay(long, TimeUnit, Scheduler, boolean) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable observeOn(Scheduler scheduler, boolean delayError) { return observeOn(scheduler, delayError, bufferSize()); } /** * Modifies an ObservableSource to perform its emissions and notifications on a specified {@link Scheduler}, * asynchronously with an unbounded buffer of configurable "island size" and optionally delays onError notifications. *

* *

* 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 {@link Scheduler} this 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. * * @param scheduler * the {@link Scheduler} to notify {@link Observer}s on * @param delayError * indicates if the onError notification may not cut ahead of onNext notification on the other side of the * scheduling boundary. If true a sequence ending in onError will be replayed in the same order as was received * from upstream * @param bufferSize the size of the buffer. * @return the source ObservableSource modified so that its {@link Observer}s are notified on the specified * {@link Scheduler} * @see ReactiveX operators documentation: ObserveOn * @see RxJava Threading Examples * @see #subscribeOn * @see #observeOn(Scheduler) * @see #observeOn(Scheduler, boolean) * @see #delay(long, TimeUnit, Scheduler, boolean) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable observeOn(Scheduler scheduler, boolean delayError, int bufferSize) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return RxJavaPlugins.onAssembly(new ObservableObserveOn(this, scheduler, delayError, bufferSize)); } /** * Filters the items emitted by an ObservableSource, only emitting those of the specified type. *

* *

*
Scheduler:
*
{@code ofType} does not operate by default on a particular {@link Scheduler}.
*
* * @param the output type * @param clazz * the class type to filter the items emitted by the source ObservableSource * @return an Observable that emits items from the source ObservableSource of type {@code clazz} * @see ReactiveX operators documentation: Filter */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable ofType(final Class clazz) { ObjectHelper.requireNonNull(clazz, "clazz is null"); return filter(Functions.isInstanceOf(clazz)).cast(clazz); } /** * Instructs an ObservableSource to pass control to another ObservableSource rather than invoking * {@link Observer#onError onError} if it encounters an error. *

* *

* By default, when an ObservableSource encounters an error that prevents it from emitting the expected item to * its {@link Observer}, the ObservableSource invokes its Observer's {@code onError} method, and then quits * without invoking any more of its Observer's methods. The {@code onErrorResumeNext} method changes this * behavior. If you pass a function that returns an ObservableSource ({@code resumeFunction}) to * {@code onErrorResumeNext}, if the original ObservableSource encounters an error, instead of invoking its * Observer's {@code onError} method, it will instead relinquish control to the ObservableSource returned from * {@code resumeFunction}, which will invoke the Observer's {@link Observer#onNext onNext} method if it is * able to do so. In such a case, because no ObservableSource necessarily invokes {@code onError}, the Observer * may 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:
*
{@code onErrorResumeNext} does not operate by default on a particular {@link Scheduler}.
*
* * @param resumeFunction * a function that returns an ObservableSource that will take over if the source ObservableSource encounters * an error * @return the original ObservableSource, with appropriately modified behavior * @see ReactiveX operators documentation: Catch */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable onErrorResumeNext(Function> resumeFunction) { ObjectHelper.requireNonNull(resumeFunction, "resumeFunction is null"); return RxJavaPlugins.onAssembly(new ObservableOnErrorNext(this, resumeFunction, false)); } /** * Instructs an ObservableSource to pass control to another ObservableSource rather than invoking * {@link Observer#onError onError} if it encounters an error. *

* *

* By default, when an ObservableSource encounters an error that prevents it from emitting the expected item to * its {@link Observer}, the ObservableSource invokes its Observer's {@code onError} method, and then quits * without invoking any more of its Observer's methods. The {@code onErrorResumeNext} method changes this * behavior. If you pass another ObservableSource ({@code resumeSequence}) to an ObservableSource's * {@code onErrorResumeNext} method, if the original ObservableSource encounters an error, instead of invoking its * Observer's {@code onError} method, it will instead relinquish control to {@code resumeSequence} which * will invoke the Observer's {@link Observer#onNext onNext} method if it is able to do so. In such a case, * because no ObservableSource necessarily invokes {@code onError}, the Observer may 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:
*
{@code onErrorResumeNext} does not operate by default on a particular {@link Scheduler}.
*
* * @param next * the next ObservableSource source that will take over if the source ObservableSource encounters * an error * @return the original ObservableSource, with appropriately modified behavior * @see ReactiveX operators documentation: Catch */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable onErrorResumeNext(final ObservableSource next) { ObjectHelper.requireNonNull(next, "next is null"); return onErrorResumeNext(Functions.justFunction(next)); } /** * Instructs an ObservableSource to emit an item (returned by a specified function) rather than invoking * {@link Observer#onError onError} if it encounters an error. *

* *

* By default, when an ObservableSource encounters an error that prevents it from emitting the expected item to * its {@link Observer}, the ObservableSource invokes its Observer's {@code onError} method, and then quits * without invoking any more of its Observer's methods. The {@code onErrorReturn} method changes this * behavior. If you pass a function ({@code resumeFunction}) to an ObservableSource's {@code onErrorReturn} * method, if the original ObservableSource encounters an error, instead of invoking its Observer's * {@code onError} method, it will instead emit the return value of {@code resumeFunction}. *

* You can use this to prevent errors from propagating or to supply fallback data should errors be * encountered. *

*
Scheduler:
*
{@code onErrorReturn} does not operate by default on a particular {@link Scheduler}.
*
* * @param valueSupplier * a function that returns a single value that will be emitted along with a regular onComplete in case * the current Observable signals an onError event * @return the original ObservableSource with appropriately modified behavior * @see ReactiveX operators documentation: Catch */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable onErrorReturn(Function valueSupplier) { ObjectHelper.requireNonNull(valueSupplier, "valueSupplier is null"); return RxJavaPlugins.onAssembly(new ObservableOnErrorReturn(this, valueSupplier)); } /** * Instructs an ObservableSource to emit an item (returned by a specified function) rather than invoking * {@link Observer#onError onError} if it encounters an error. *

* *

* By default, when an ObservableSource encounters an error that prevents it from emitting the expected item to * its {@link Observer}, the ObservableSource invokes its Observer's {@code onError} method, and then quits * without invoking any more of its Observer's methods. The {@code onErrorReturn} method changes this * behavior. If you pass a function ({@code resumeFunction}) to an ObservableSource's {@code onErrorReturn} * method, if the original ObservableSource encounters an error, instead of invoking its Observer's * {@code onError} method, it will instead emit the return value of {@code resumeFunction}. *

* You can use this to prevent errors from propagating or to supply fallback data should errors be * encountered. *

*
Scheduler:
*
{@code onErrorReturnItem} does not operate by default on a particular {@link Scheduler}.
*
* * @param item * the value that is emitted along with a regular onComplete in case the current * Observable signals an exception * @return the original ObservableSource with appropriately modified behavior * @see ReactiveX operators documentation: Catch */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable onErrorReturnItem(final T item) { ObjectHelper.requireNonNull(item, "item is null"); return onErrorReturn(Functions.justFunction(item)); } /** * Instructs an ObservableSource to pass control to another ObservableSource rather than invoking * {@link Observer#onError onError} if it encounters an {@link java.lang.Exception}. *

* This differs from {@link #onErrorResumeNext} in that this one does not handle {@link java.lang.Throwable} * or {@link java.lang.Error} but lets those continue through. *

* *

* By default, when an ObservableSource encounters an exception that prevents it from emitting the expected item * to its {@link Observer}, the ObservableSource invokes its Observer's {@code onError} method, and then quits * without invoking any more of its Observer's methods. The {@code onExceptionResumeNext} method changes * this behavior. If you pass another ObservableSource ({@code resumeSequence}) to an ObservableSource's * {@code onExceptionResumeNext} method, if the original ObservableSource encounters an exception, instead of * invoking its Observer's {@code onError} method, it will instead relinquish control to * {@code resumeSequence} which will invoke the Observer's {@link Observer#onNext onNext} method if it is * able to do so. In such a case, because no ObservableSource necessarily invokes {@code onError}, the Observer * may never know that an exception happened. *

* You can use this to prevent exceptions from propagating or to supply fallback data should exceptions be * encountered. *

*
Scheduler:
*
{@code onExceptionResumeNext} does not operate by default on a particular {@link Scheduler}.
*
* * @param next * the next ObservableSource that will take over if the source ObservableSource encounters * an exception * @return the original ObservableSource, with appropriately modified behavior * @see ReactiveX operators documentation: Catch */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable onExceptionResumeNext(final ObservableSource next) { ObjectHelper.requireNonNull(next, "next is null"); return RxJavaPlugins.onAssembly(new ObservableOnErrorNext(this, Functions.justFunction(next), true)); } /** * Nulls out references to the upstream producer and downstream Observer if * the sequence is terminated or downstream calls dispose(). *

* *

*
Scheduler:
*
{@code onTerminateDetach} does not operate by default on a particular {@link Scheduler}.
*
* @return an Observable which nulls out references to the upstream producer and downstream Observer if * the sequence is terminated or downstream calls dispose() * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable onTerminateDetach() { return RxJavaPlugins.onAssembly(new ObservableDetach(this)); } /** * Returns a {@link ConnectableObservable}, which is a variety of ObservableSource that waits until its * {@link ConnectableObservable#connect connect} method is called before it begins emitting items to those * {@link Observer}s that have subscribed to it. *

* *

*
Scheduler:
*
{@code publish} does not operate by default on a particular {@link Scheduler}.
*
* * @return a {@link ConnectableObservable} that upon connection causes the source ObservableSource to emit items * to its {@link Observer}s * @see ReactiveX operators documentation: Publish */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final ConnectableObservable publish() { return ObservablePublish.create(this); } /** * Returns an Observable that emits the results of invoking a specified selector on items emitted by a * {@link ConnectableObservable} that shares a single subscription to the underlying sequence. *

* *

*
Scheduler:
*
{@code publish} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items emitted by the resulting ObservableSource * @param 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. * @return an Observable that emits the results of invoking the selector on the items emitted by a {@link ConnectableObservable} that shares a single subscription to the underlying sequence * @see ReactiveX operators documentation: Publish */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable publish(Function, ? extends ObservableSource> selector) { ObjectHelper.requireNonNull(selector, "selector is null"); return RxJavaPlugins.onAssembly(new ObservablePublishSelector(this, selector)); } /** * Returns a Maybe that applies a specified accumulator function to the first item emitted by a source * ObservableSource, then feeds the result of that function along with the second item emitted by the source * ObservableSource into the same function, and so on until all items have been emitted by the finite source ObservableSource, * 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 {@code inject} method * that does a similar operation on lists. *

* Note that this operator requires the upstream to signal {@code onComplete} for 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code reduce} does not operate by default on a particular {@link Scheduler}.
*
* * @param reducer * an accumulator function to be invoked on each item emitted by the source ObservableSource, whose * result will be used in the next accumulator call * @return a Maybe that emits a single item that is the result of accumulating the items emitted by * the source ObservableSource * @see ReactiveX operators documentation: Reduce * @see Wikipedia: Fold (higher-order function) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe reduce(BiFunction reducer) { ObjectHelper.requireNonNull(reducer, "reducer is null"); return RxJavaPlugins.onAssembly(new ObservableReduceMaybe(this, reducer)); } /** * Returns a Single that applies a specified accumulator function to the first item emitted by a source * ObservableSource and a specified seed value, then feeds the result of that function along with the second item * emitted by an ObservableSource into the same function, and so on until all items have been emitted by the * finite source ObservableSource, 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 {@code inject} method * that does a similar operation on lists. *

* Note that the {@code seed} is shared among all subscribers to the resulting ObservableSource * and may cause problems if it is mutable. To make sure each subscriber gets its own value, defer * the application of this operator via {@link #defer(Callable)}: *


     * 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 {@code onComplete} for 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code reduce} does not operate by default on a particular {@link Scheduler}.
*
* * @param the accumulator and output value type * @param seed * the initial (seed) accumulator value * @param reducer * an accumulator function to be invoked on each item emitted by the source ObservableSource, the * result of which will be used in the next accumulator call * @return a Single that emits a single item that is the result of accumulating the output from the * items emitted by the source ObservableSource * @see ReactiveX operators documentation: Reduce * @see Wikipedia: Fold (higher-order function) * @see #reduceWith(Callable, BiFunction) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single reduce(R seed, BiFunction reducer) { ObjectHelper.requireNonNull(seed, "seed is null"); ObjectHelper.requireNonNull(reducer, "reducer is null"); return RxJavaPlugins.onAssembly(new ObservableReduceSeedSingle(this, seed, reducer)); } /** * Returns a Single that applies a specified accumulator function to the first item emitted by a source * ObservableSource and a seed value derived from calling a specified seedSupplier, then feeds the result * of that function along with the second item emitted by an ObservableSource into the same function, * and so on until all items have been emitted by the finite source ObservableSource, 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 {@code inject} method * that does a similar operation on lists. *

* Note that this operator requires the upstream to signal {@code onComplete} for 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code reduceWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param the accumulator and output value type * @param seedSupplier * the Callable that provides the initial (seed) accumulator value for each individual Observer * @param reducer * an accumulator function to be invoked on each item emitted by the source ObservableSource, the * result of which will be used in the next accumulator call * @return a Single that emits a single item that is the result of accumulating the output from the * items emitted by the source ObservableSource * @see ReactiveX operators documentation: Reduce * @see Wikipedia: Fold (higher-order function) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single reduceWith(Callable seedSupplier, BiFunction reducer) { ObjectHelper.requireNonNull(seedSupplier, "seedSupplier is null"); ObjectHelper.requireNonNull(reducer, "reducer is null"); return RxJavaPlugins.onAssembly(new ObservableReduceWithSingle(this, seedSupplier, reducer)); } /** * Returns an Observable that repeats the sequence of items emitted by the source ObservableSource indefinitely. *

* *

*
Scheduler:
*
{@code repeat} does not operate by default on a particular {@link Scheduler}.
*
* * @return an Observable that emits the items emitted by the source ObservableSource repeatedly and in sequence * @see ReactiveX operators documentation: Repeat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable repeat() { return repeat(Long.MAX_VALUE); } /** * Returns an Observable that repeats the sequence of items emitted by the source ObservableSource at most * {@code count} times. *

* *

*
Scheduler:
*
{@code repeat} does not operate by default on a particular {@link Scheduler}.
*
* * @param times * the number of times the source ObservableSource items are repeated, a count of 0 will yield an empty * sequence * @return an Observable that repeats the sequence of items emitted by the source ObservableSource at most * {@code count} times * @throws IllegalArgumentException * if {@code count} is less than zero * @see ReactiveX operators documentation: Repeat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable repeat(long times) { if (times < 0) { throw new IllegalArgumentException("times >= 0 required but it was " + times); } if (times == 0) { return empty(); } return RxJavaPlugins.onAssembly(new ObservableRepeat(this, times)); } /** * Returns an Observable that repeats the sequence of items emitted by the source ObservableSource until * the provided stop function returns true. *

* *

*
Scheduler:
*
{@code repeatUntil} does not operate by default on a particular {@link Scheduler}.
*
* * @param stop * a boolean supplier that is called when the current Observable completes; * if it returns true, the returned Observable completes; if it returns false, * the upstream Observable is resubscribed. * @return the new Observable instance * @throws NullPointerException * if {@code stop} is null * @see ReactiveX operators documentation: Repeat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable repeatUntil(BooleanSupplier stop) { ObjectHelper.requireNonNull(stop, "stop is null"); return RxJavaPlugins.onAssembly(new ObservableRepeatUntil(this, stop)); } /** * Returns an Observable that emits the same values as the source ObservableSource with the exception of an * {@code onComplete}. An {@code onComplete} notification from the source will result in the emission of * a {@code void} item to the ObservableSource provided as an argument to the {@code notificationHandler} * function. If that ObservableSource calls {@code onComplete} or {@code onError} then {@code repeatWhen} will * call {@code onComplete} or {@code onError} on the child subscription. Otherwise, this ObservableSource will * resubscribe to the source ObservableSource. *

* *

*
Scheduler:
*
{@code repeatWhen} does not operate by default on a particular {@link Scheduler}.
*
* * @param handler * receives an ObservableSource of notifications with which a user can complete or error, aborting the repeat. * @return the source ObservableSource modified with repeat logic * @see ReactiveX operators documentation: Repeat */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable repeatWhen(final Function, ? extends ObservableSource> handler) { ObjectHelper.requireNonNull(handler, "handler is null"); return RxJavaPlugins.onAssembly(new ObservableRepeatWhen(this, handler)); } /** * Returns a {@link ConnectableObservable} that shares a single subscription to the underlying ObservableSource * that will replay all of its items and notifications to any future {@link Observer}. A Connectable * ObservableSource resembles an ordinary ObservableSource, except that it does not begin emitting items when it is * subscribed to, but only when its {@code connect} method is called. *

* *

*
Scheduler:
*
This version of {@code replay} does not operate by default on a particular {@link Scheduler}.
*
* * @return a {@link ConnectableObservable} that upon connection causes the source ObservableSource to emit its * items to its {@link Observer}s * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final ConnectableObservable replay() { return ObservableReplay.createFrom(this); } /** * Returns an Observable that emits items that are the results of invoking a specified selector on the items * emitted by a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource. *

* *

*
Scheduler:
*
This version of {@code replay} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items emitted by the resulting ObservableSource * @param selector * the selector function, which can use the multicasted sequence as many times as needed, without * causing multiple subscriptions to the ObservableSource * @return an Observable that emits items that are the results of invoking the selector on a * {@link ConnectableObservable} that shares a single subscription to the source ObservableSource * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable replay(Function, ? extends ObservableSource> selector) { ObjectHelper.requireNonNull(selector, "selector is null"); return ObservableReplay.multicastSelector(ObservableInternalHelper.replayCallable(this), selector); } /** * Returns an Observable that emits items that are the results of invoking a specified selector on items * emitted by a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource, * replaying {@code bufferSize} notifications. *

* Note that due to concurrency requirements, {@code replay(bufferSize)} may hold strong references to more than * {@code bufferSize} source emissions. *

* *

*
Scheduler:
*
This version of {@code replay} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items emitted by the resulting ObservableSource * @param selector * the selector function, which can use the multicasted sequence as many times as needed, without * causing multiple subscriptions to the ObservableSource * @param bufferSize * the buffer size that limits the number of items the connectable ObservableSource can replay * @return an Observable that emits items that are the results of invoking the selector on items emitted by * a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource * replaying no more than {@code bufferSize} items * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable replay(Function, ? extends ObservableSource> selector, final int bufferSize) { ObjectHelper.requireNonNull(selector, "selector is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return ObservableReplay.multicastSelector(ObservableInternalHelper.replayCallable(this, bufferSize), selector); } /** * Returns an Observable that emits items that are the results of invoking a specified selector on items * emitted by a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource, * replaying no more than {@code bufferSize} items that were emitted within a specified time window. *

* Note that due to concurrency requirements, {@code replay(bufferSize)} may hold strong references to more than * {@code bufferSize} source emissions. *

* *

*
Scheduler:
*
This version of {@code replay} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param * the type of items emitted by the resulting ObservableSource * @param selector * a selector function, which can use the multicasted sequence as many times as needed, without * causing multiple subscriptions to the ObservableSource * @param bufferSize * the buffer size that limits the number of items the connectable ObservableSource can replay * @param time * the duration of the window in which the replayed items must have been emitted * @param unit * the time unit of {@code time} * @return an Observable that emits items that are the results of invoking the selector on items emitted by * a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource, and * replays no more than {@code bufferSize} items that were emitted within the window defined by * {@code time} * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable replay(Function, ? extends ObservableSource> selector, int bufferSize, long time, TimeUnit unit) { return replay(selector, bufferSize, time, unit, Schedulers.computation()); } /** * Returns an Observable that emits items that are the results of invoking a specified selector on items * emitted by a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource, * replaying no more than {@code bufferSize} items that were emitted within a specified time window. *

* Note that due to concurrency requirements, {@code replay(bufferSize)} may hold strong references to more than * {@code bufferSize} source emissions. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param * the type of items emitted by the resulting ObservableSource * @param selector * a selector function, which can use the multicasted sequence as many times as needed, without * causing multiple subscriptions to the ObservableSource * @param bufferSize * the buffer size that limits the number of items the connectable ObservableSource can replay * @param time * the duration of the window in which the replayed items must have been emitted * @param unit * the time unit of {@code time} * @param scheduler * the Scheduler that is the time source for the window * @return an Observable that emits items that are the results of invoking the selector on items emitted by * a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource, and * replays no more than {@code bufferSize} items that were emitted within the window defined by * {@code time} * @throws IllegalArgumentException * if {@code bufferSize} is less than zero * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable replay(Function, ? extends ObservableSource> selector, final int bufferSize, final long time, final TimeUnit unit, final Scheduler scheduler) { ObjectHelper.requireNonNull(selector, "selector is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return ObservableReplay.multicastSelector( ObservableInternalHelper.replayCallable(this, bufferSize, time, unit, scheduler), selector); } /** * Returns an Observable that emits items that are the results of invoking a specified selector on items * emitted by a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource, * replaying a maximum of {@code bufferSize} items. *

* Note that due to concurrency requirements, {@code replay(bufferSize)} may hold strong references to more than * {@code bufferSize} source emissions. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param * the type of items emitted by the resulting ObservableSource * @param selector * a selector function, which can use the multicasted sequence as many times as needed, without * causing multiple subscriptions to the ObservableSource * @param bufferSize * the buffer size that limits the number of items the connectable ObservableSource can replay * @param scheduler * the Scheduler on which the replay is observed * @return an Observable that emits items that are the results of invoking the selector on items emitted by * a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource, * replaying no more than {@code bufferSize} notifications * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable replay(final Function, ? extends ObservableSource> selector, final int bufferSize, final Scheduler scheduler) { ObjectHelper.requireNonNull(selector, "selector is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return ObservableReplay.multicastSelector(ObservableInternalHelper.replayCallable(this, bufferSize), ObservableInternalHelper.replayFunction(selector, scheduler)); } /** * Returns an Observable that emits items that are the results of invoking a specified selector on items * emitted by a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource, * replaying all items that were emitted within a specified time window. *

* *

*
Scheduler:
*
This version of {@code replay} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param * the type of items emitted by the resulting ObservableSource * @param selector * a selector function, which can use the multicasted sequence as many times as needed, without * causing multiple subscriptions to the ObservableSource * @param time * the duration of the window in which the replayed items must have been emitted * @param unit * the time unit of {@code time} * @return an Observable that emits items that are the results of invoking the selector on items emitted by * a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource, * replaying all items that were emitted within the window defined by {@code time} * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable replay(Function, ? extends ObservableSource> selector, long time, TimeUnit unit) { return replay(selector, time, unit, Schedulers.computation()); } /** * Returns an Observable that emits items that are the results of invoking a specified selector on items * emitted by a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource, * replaying all items that were emitted within a specified time window. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param * the type of items emitted by the resulting ObservableSource * @param selector * a selector function, which can use the multicasted sequence as many times as needed, without * causing multiple subscriptions to the ObservableSource * @param time * the duration of the window in which the replayed items must have been emitted * @param unit * the time unit of {@code time} * @param scheduler * the scheduler that is the time source for the window * @return an Observable that emits items that are the results of invoking the selector on items emitted by * a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource, * replaying all items that were emitted within the window defined by {@code time} * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable replay(Function, ? extends ObservableSource> selector, final long time, final TimeUnit unit, final Scheduler scheduler) { ObjectHelper.requireNonNull(selector, "selector is null"); ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return ObservableReplay.multicastSelector(ObservableInternalHelper.replayCallable(this, time, unit, scheduler), selector); } /** * Returns an Observable that emits items that are the results of invoking a specified selector on items * emitted by a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param * the type of items emitted by the resulting ObservableSource * @param selector * a selector function, which can use the multicasted sequence as many times as needed, without * causing multiple subscriptions to the ObservableSource * @param scheduler * the Scheduler where the replay is observed * @return an Observable that emits items that are the results of invoking the selector on items emitted by * a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource, * replaying all items * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable replay(final Function, ? extends ObservableSource> selector, final Scheduler scheduler) { ObjectHelper.requireNonNull(selector, "selector is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return ObservableReplay.multicastSelector(ObservableInternalHelper.replayCallable(this), ObservableInternalHelper.replayFunction(selector, scheduler)); } /** * Returns a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource that * replays at most {@code bufferSize} items emitted by that ObservableSource. A Connectable ObservableSource resembles * an ordinary ObservableSource, except that it does not begin emitting items when it is subscribed to, but only * when its {@code connect} method is called. *

* Note that due to concurrency requirements, {@code replay(bufferSize)} may hold strong references to more than * {@code bufferSize} source emissions. *

* *

*
Scheduler:
*
This version of {@code replay} does not operate by default on a particular {@link Scheduler}.
*
* * @param bufferSize * the buffer size that limits the number of items that can be replayed * @return a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource and * replays at most {@code bufferSize} items emitted by that ObservableSource * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final ConnectableObservable replay(final int bufferSize) { ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return ObservableReplay.create(this, bufferSize); } /** * Returns a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource and * replays at most {@code bufferSize} items that were emitted during a specified time window. A Connectable * ObservableSource resembles an ordinary ObservableSource, except that it does not begin emitting items when it is * subscribed to, but only when its {@code connect} method is called. *

* Note that due to concurrency requirements, {@code replay(bufferSize)} may hold strong references to more than * {@code bufferSize} source emissions. *

* *

*
Scheduler:
*
This version of {@code replay} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param bufferSize * the buffer size that limits the number of items that can be replayed * @param time * the duration of the window in which the replayed items must have been emitted * @param unit * the time unit of {@code time} * @return a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource and * replays at most {@code bufferSize} items that were emitted during the window defined by * {@code time} * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final ConnectableObservable replay(int bufferSize, long time, TimeUnit unit) { return replay(bufferSize, time, unit, Schedulers.computation()); } /** * Returns a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource and * that replays a maximum of {@code bufferSize} items that are emitted within a specified time window. A * Connectable ObservableSource resembles an ordinary ObservableSource, except that it does not begin emitting items * when it is subscribed to, but only when its {@code connect} method is called. *

* Note that due to concurrency requirements, {@code replay(bufferSize)} may hold strong references to more than * {@code bufferSize} source emissions. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param bufferSize * the buffer size that limits the number of items that can be replayed * @param time * the duration of the window in which the replayed items must have been emitted * @param unit * the time unit of {@code time} * @param scheduler * the scheduler that is used as a time source for the window * @return a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource and * replays at most {@code bufferSize} items that were emitted during the window defined by * {@code time} * @throws IllegalArgumentException * if {@code bufferSize} is less than zero * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final ConnectableObservable replay(final int bufferSize, final long time, final TimeUnit unit, final Scheduler scheduler) { ObjectHelper.verifyPositive(bufferSize, "bufferSize"); ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return ObservableReplay.create(this, time, unit, scheduler, bufferSize); } /** * Returns a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource and * replays at most {@code bufferSize} items emitted by that ObservableSource. A Connectable ObservableSource resembles * an ordinary ObservableSource, except that it does not begin emitting items when it is subscribed to, but only * when its {@code connect} method is called. *

* Note that due to concurrency requirements, {@code replay(bufferSize)} may hold strong references to more than * {@code bufferSize} source emissions. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param bufferSize * the buffer size that limits the number of items that can be replayed * @param scheduler * the scheduler on which the Observers will observe the emitted items * @return a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource and * replays at most {@code bufferSize} items that were emitted by the ObservableSource * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final ConnectableObservable replay(final int bufferSize, final Scheduler scheduler) { ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return ObservableReplay.observeOn(replay(bufferSize), scheduler); } /** * Returns a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource and * replays all items emitted by that ObservableSource within a specified time window. A Connectable ObservableSource * resembles an ordinary ObservableSource, except that it does not begin emitting items when it is subscribed to, * but only when its {@code connect} method is called. *

* *

*
Scheduler:
*
This version of {@code replay} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param time * the duration of the window in which the replayed items must have been emitted * @param unit * the time unit of {@code time} * @return a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource and * replays the items that were emitted during the window defined by {@code time} * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final ConnectableObservable replay(long time, TimeUnit unit) { return replay(time, unit, Schedulers.computation()); } /** * Returns a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource and * replays all items emitted by that ObservableSource within a specified time window. A Connectable ObservableSource * resembles an ordinary ObservableSource, except that it does not begin emitting items when it is subscribed to, * but only when its {@code connect} method is called. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param time * the duration of the window in which the replayed items must have been emitted * @param unit * the time unit of {@code time} * @param scheduler * the Scheduler that is the time source for the window * @return a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource and * replays the items that were emitted during the window defined by {@code time} * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final ConnectableObservable replay(final long time, final TimeUnit unit, final Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return ObservableReplay.create(this, time, unit, scheduler); } /** * Returns a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource that * will replay all of its items and notifications to any future {@link Observer} on the given * {@link Scheduler}. A Connectable ObservableSource resembles an ordinary ObservableSource, except that it does not * begin emitting items when it is subscribed to, but only when its {@code connect} method is called. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param scheduler * the Scheduler on which the Observers will observe the emitted items * @return a {@link ConnectableObservable} that shares a single subscription to the source ObservableSource that * will replay all of its items and notifications to any future {@link Observer} on the given * {@link Scheduler} * @see ReactiveX operators documentation: Replay */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final ConnectableObservable replay(final Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return ObservableReplay.observeOn(replay(), scheduler); } /** * Returns an Observable that mirrors the source ObservableSource, resubscribing to it if it calls {@code onError} * (infinite retry count). *

* *

* If the source ObservableSource calls {@link Observer#onError}, this method will resubscribe to the source * ObservableSource rather than propagating the {@code onError} call. *

* Any and all items emitted by the source ObservableSource will be emitted by the resulting ObservableSource, even * those emitted during failed subscriptions. For example, if an ObservableSource fails at first but emits * {@code [1, 2]} then succeeds the second time and emits {@code [1, 2, 3, 4, 5]} then the complete sequence * of emissions and notifications would be {@code [1, 2, 1, 2, 3, 4, 5, onComplete]}. *

*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
*
* * @return the source ObservableSource modified with retry logic * @see ReactiveX operators documentation: Retry */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable retry() { return retry(Long.MAX_VALUE, Functions.alwaysTrue()); } /** * Returns an Observable that mirrors the source ObservableSource, resubscribing to it if it calls {@code onError} * and the predicate returns true for that specific exception and retry count. *

* *

*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
*
* * @param predicate * the predicate that determines if a resubscription may happen in case of a specific exception * and retry count * @return the source ObservableSource modified with retry logic * @see #retry() * @see ReactiveX operators documentation: Retry */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable retry(BiPredicate predicate) { ObjectHelper.requireNonNull(predicate, "predicate is null"); return RxJavaPlugins.onAssembly(new ObservableRetryBiPredicate(this, predicate)); } /** * Returns an Observable that mirrors the source ObservableSource, resubscribing to it if it calls {@code onError} * up to a specified number of retries. *

* *

* If the source ObservableSource calls {@link Observer#onError}, this method will resubscribe to the source * ObservableSource for a maximum of {@code count} resubscriptions rather than propagating the * {@code onError} call. *

* Any and all items emitted by the source ObservableSource will be emitted by the resulting ObservableSource, even * those emitted during failed subscriptions. For example, if an ObservableSource fails at first but emits * {@code [1, 2]} then succeeds the second time and emits {@code [1, 2, 3, 4, 5]} then the complete sequence * of emissions and notifications would be {@code [1, 2, 1, 2, 3, 4, 5, onComplete]}. *

*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
*
* * @param times * the number of times to resubscribe if the current Observable fails * @return the source ObservableSource modified with retry logic * @see ReactiveX operators documentation: Retry */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable retry(long times) { return retry(times, Functions.alwaysTrue()); } /** * Retries at most times or until the predicate returns false, whichever happens first. *

* *

*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
*
* @param times the number of times to resubscribe if the current Observable fails * @param predicate the predicate called with the failure Throwable and should return true to trigger a retry. * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable retry(long times, Predicate predicate) { if (times < 0) { throw new IllegalArgumentException("times >= 0 required but it was " + times); } ObjectHelper.requireNonNull(predicate, "predicate is null"); return RxJavaPlugins.onAssembly(new ObservableRetryPredicate(this, times, predicate)); } /** * Retries the current Observable if the predicate returns true. *

* *

*
Scheduler:
*
{@code retry} does not operate by default on a particular {@link Scheduler}.
*
* * @param predicate the predicate that receives the failure Throwable and should return true to trigger a retry. * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable retry(Predicate predicate) { return retry(Long.MAX_VALUE, predicate); } /** * Retries until the given stop function returns true. *

* *

*
Scheduler:
*
{@code retryUntil} does not operate by default on a particular {@link Scheduler}.
*
* @param stop the function that should return true to stop retrying * @return the new Observable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable retryUntil(final BooleanSupplier stop) { ObjectHelper.requireNonNull(stop, "stop is null"); return retry(Long.MAX_VALUE, Functions.predicateReverseFor(stop)); } /** * Returns an Observable that emits the same values as the source ObservableSource with the exception of an * {@code onError}. An {@code onError} notification from the source will result in the emission of a * {@link Throwable} item to the ObservableSource provided as an argument to the {@code notificationHandler} * function. If that ObservableSource calls {@code onComplete} or {@code onError} then {@code retry} will call * {@code onComplete} or {@code onError} on the child subscription. Otherwise, this ObservableSource will * resubscribe to the source ObservableSource. *

* *

* Example: * * This retries 3 times, each time incrementing the number of seconds it waits. * *


     *  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);
     * 
* * Output is: * *
 {@code
     * subscribing
     * delay retry by 1 second(s)
     * subscribing
     * delay retry by 2 second(s)
     * subscribing
     * delay retry by 3 second(s)
     * subscribing
     * } 
*

* Note that the inner {@code ObservableSource} returned by the handler function should signal * either {@code onNext}, {@code onError} or {@code onComplete} in response to the received * {@code Throwable} to indicate the operator should retry or terminate. If the upstream to * the operator is asynchronous, signalling onNext followed by onComplete immediately may * result in the sequence to be completed immediately. Similarly, if this inner * {@code ObservableSource} signals {@code onError} or {@code onComplete} while 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:
*
{@code retryWhen} does not operate by default on a particular {@link Scheduler}.
*
* * @param handler * receives an ObservableSource of notifications with which a user can complete or error, aborting the * retry * @return the source ObservableSource modified with retry logic * @see ReactiveX operators documentation: Retry */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable retryWhen( final Function, ? extends ObservableSource> handler) { ObjectHelper.requireNonNull(handler, "handler is null"); return RxJavaPlugins.onAssembly(new ObservableRetryWhen(this, handler)); } /** * Subscribes to the current Observable and wraps the given Observer into a SafeObserver * (if not already a SafeObserver) that * deals with exceptions thrown by a misbehaving Observer (that doesn't follow the * Reactive Streams specification). *
*
Scheduler:
*
{@code safeSubscribe} does not operate by default on a particular {@link Scheduler}.
*
* @param observer the incoming Observer instance * @throws NullPointerException if s is null */ @SchedulerSupport(SchedulerSupport.NONE) public final void safeSubscribe(Observer observer) { ObjectHelper.requireNonNull(observer, "observer is null"); if (observer instanceof SafeObserver) { subscribe(observer); } else { subscribe(new SafeObserver(observer)); } } /** * Returns an Observable that emits the most recently emitted item (if any) emitted by the source ObservableSource * within periodic time intervals. *

* *

*
Scheduler:
*
{@code sample} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param period * the sampling rate * @param unit * the {@link TimeUnit} in which {@code period} is defined * @return an Observable that emits the results of sampling the items emitted by the source ObservableSource at * the specified time interval * @see ReactiveX operators documentation: Sample * @see #throttleLast(long, TimeUnit) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable sample(long period, TimeUnit unit) { return sample(period, unit, Schedulers.computation()); } /** * Returns an Observable that emits the most recently emitted item (if any) emitted by the source ObservableSource * within periodic time intervals and optionally emit the very last upstream item when the upstream completes. *

* *

*
Scheduler:
*
{@code sample} operates by default on the {@code computation} {@link Scheduler}.
*
* *

History: 2.0.5 - experimental * @param period * the sampling rate * @param unit * the {@link TimeUnit} in which {@code period} is defined * @return an Observable that emits the results of sampling the items emitted by the source ObservableSource at * the specified time interval * @param emitLast * if true and the upstream completes while there is still an unsampled item available, * that item is emitted to downstream before completion * if false, an unsampled last item is ignored. * @see ReactiveX operators documentation: Sample * @see #throttleLast(long, TimeUnit) * @since 2.1 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable sample(long period, TimeUnit unit, boolean emitLast) { return sample(period, unit, Schedulers.computation(), emitLast); } /** * Returns an Observable that emits the most recently emitted item (if any) emitted by the source ObservableSource * within periodic time intervals, where the intervals are defined on a particular Scheduler. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param period * the sampling rate * @param unit * the {@link TimeUnit} in which {@code period} is defined * @param scheduler * the {@link Scheduler} to use when sampling * @return an Observable that emits the results of sampling the items emitted by the source ObservableSource at * the specified time interval * @see ReactiveX operators documentation: Sample * @see #throttleLast(long, TimeUnit, Scheduler) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable sample(long period, TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new ObservableSampleTimed(this, period, unit, scheduler, false)); } /** * Returns an Observable that emits the most recently emitted item (if any) emitted by the source ObservableSource * within periodic time intervals, where the intervals are defined on a particular Scheduler * and optionally emit the very last upstream item when the upstream completes. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* *

History: 2.0.5 - experimental * @param period * the sampling rate * @param unit * the {@link TimeUnit} in which {@code period} is defined * @param scheduler * the {@link Scheduler} to use when sampling * @param emitLast * if true and the upstream completes while there is still an unsampled item available, * that item is emitted to downstream before completion * if false, an unsampled last item is ignored. * @return an Observable that emits the results of sampling the items emitted by the source ObservableSource at * the specified time interval * @see ReactiveX operators documentation: Sample * @see #throttleLast(long, TimeUnit, Scheduler) * @since 2.1 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable sample(long period, TimeUnit unit, Scheduler scheduler, boolean emitLast) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new ObservableSampleTimed(this, period, unit, scheduler, emitLast)); } /** * Returns an Observable that, when the specified {@code sampler} ObservableSource emits an item or completes, * emits the most recently emitted item (if any) emitted by the source ObservableSource since the previous * emission from the {@code sampler} ObservableSource. *

* *

*
Scheduler:
*
This version of {@code sample} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the sampler ObservableSource * @param sampler * the ObservableSource to use for sampling the source ObservableSource * @return an Observable that emits the results of sampling the items emitted by this ObservableSource whenever * the {@code sampler} ObservableSource emits an item or completes * @see ReactiveX operators documentation: Sample */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable sample(ObservableSource sampler) { ObjectHelper.requireNonNull(sampler, "sampler is null"); return RxJavaPlugins.onAssembly(new ObservableSampleWithObservable(this, sampler, false)); } /** * Returns an Observable that, when the specified {@code sampler} ObservableSource emits an item or completes, * emits the most recently emitted item (if any) emitted by the source ObservableSource since the previous * emission from the {@code sampler} ObservableSource * and optionally emit the very last upstream item when the upstream or other ObservableSource complete. *

* *

*
Scheduler:
*
This version of {@code sample} does not operate by default on a particular {@link Scheduler}.
*
* *

History: 2.0.5 - experimental * @param the element type of the sampler ObservableSource * @param sampler * the ObservableSource to use for sampling the source ObservableSource * @param emitLast * if true and the upstream completes while there is still an unsampled item available, * that item is emitted to downstream before completion * if false, an unsampled last item is ignored. * @return an Observable that emits the results of sampling the items emitted by this ObservableSource whenever * the {@code sampler} ObservableSource emits an item or completes * @see ReactiveX operators documentation: Sample * @since 2.1 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable sample(ObservableSource sampler, boolean emitLast) { ObjectHelper.requireNonNull(sampler, "sampler is null"); return RxJavaPlugins.onAssembly(new ObservableSampleWithObservable(this, sampler, emitLast)); } /** * Returns an Observable that applies a specified accumulator function to the first item emitted by a source * ObservableSource, then feeds the result of that function along with the second item emitted by the source * ObservableSource into the same function, and so on until all items have been emitted by the source ObservableSource, * emitting the result of each of these iterations. *

* *

* This sort of function is sometimes called an accumulator. *

*
Scheduler:
*
{@code scan} does not operate by default on a particular {@link Scheduler}.
*
* * @param accumulator * an accumulator function to be invoked on each item emitted by the source ObservableSource, whose * result will be emitted to {@link Observer}s via {@link Observer#onNext onNext} and used in the * next accumulator call * @return an Observable that emits the results of each call to the accumulator function * @see ReactiveX operators documentation: Scan */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable scan(BiFunction accumulator) { ObjectHelper.requireNonNull(accumulator, "accumulator is null"); return RxJavaPlugins.onAssembly(new ObservableScan(this, accumulator)); } /** * Returns an Observable that applies a specified accumulator function to the first item emitted by a source * ObservableSource and a seed value, then feeds the result of that function along with the second item emitted by * the source ObservableSource into the same function, and so on until all items have been emitted by the source * ObservableSource, emitting the result of each of these iterations. *

* *

* This sort of function is sometimes called an accumulator. *

* Note that the ObservableSource that results from this method will emit {@code initialValue} as its first * emitted item. *

* Note that the {@code initialValue} is shared among all subscribers to the resulting ObservableSource * and may cause problems if it is mutable. To make sure each subscriber gets its own value, defer * the application of this operator via {@link #defer(Callable)}: *


     * 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:
*
{@code scan} does not operate by default on a particular {@link Scheduler}.
*
* * @param the initial, accumulator and result type * @param initialValue * the initial (seed) accumulator item * @param accumulator * an accumulator function to be invoked on each item emitted by the source ObservableSource, whose * result will be emitted to {@link Observer}s via {@link Observer#onNext onNext} and used in the * next accumulator call * @return an Observable that emits {@code initialValue} followed by the results of each call to the * accumulator function * @see ReactiveX operators documentation: Scan */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable scan(final R initialValue, BiFunction accumulator) { ObjectHelper.requireNonNull(initialValue, "initialValue is null"); return scanWith(Functions.justCallable(initialValue), accumulator); } /** * Returns an Observable that applies a specified accumulator function to the first item emitted by a source * ObservableSource and a seed value, then feeds the result of that function along with the second item emitted by * the source ObservableSource into the same function, and so on until all items have been emitted by the source * ObservableSource, emitting the result of each of these iterations. *

* *

* This sort of function is sometimes called an accumulator. *

* Note that the ObservableSource that results from this method will emit the value returned * by the {@code seedSupplier} as its first item. *

*
Scheduler:
*
{@code scanWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param the initial, accumulator and result type * @param seedSupplier * a Callable that returns the initial (seed) accumulator item for each individual Observer * @param accumulator * an accumulator function to be invoked on each item emitted by the source ObservableSource, whose * result will be emitted to {@link Observer}s via {@link Observer#onNext onNext} and used in the * next accumulator call * @return an Observable that emits {@code initialValue} followed by the results of each call to the * accumulator function * @see ReactiveX operators documentation: Scan */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable scanWith(Callable seedSupplier, BiFunction accumulator) { ObjectHelper.requireNonNull(seedSupplier, "seedSupplier is null"); ObjectHelper.requireNonNull(accumulator, "accumulator is null"); return RxJavaPlugins.onAssembly(new ObservableScanSeed(this, seedSupplier, accumulator)); } /** * Forces an ObservableSource's emissions and notifications to be serialized and for it to obey * the ObservableSource contract in other ways. *

* It is possible for an ObservableSource to invoke its Observers' methods asynchronously, perhaps from * different threads. This could make such an ObservableSource poorly-behaved, in that it might try to invoke * {@code onComplete} or {@code onError} before one of its {@code onNext} invocations, or it might call * {@code onNext} from two different threads concurrently. You can force such an ObservableSource to be * well-behaved and sequential by applying the {@code serialize} method to it. *

* *

*
Scheduler:
*
{@code serialize} does not operate by default on a particular {@link Scheduler}.
*
* * @return an {@link ObservableSource} that is guaranteed to be well-behaved and to make only serialized calls to * its observers * @see ReactiveX operators documentation: Serialize */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable serialize() { return RxJavaPlugins.onAssembly(new ObservableSerialized(this)); } /** * Returns a new {@link ObservableSource} that multicasts (and shares a single subscription to) the original {@link ObservableSource}. As long as * there is at least one {@link Observer} this {@link ObservableSource} will be subscribed and emitting data. * When all subscribers have disposed it will dispose the source {@link ObservableSource}. *

* This is an alias for {@link #publish()}.{@link ConnectableObservable#refCount() refCount()}. *

* *

*
Scheduler:
*
{@code share} does not operate by default on a particular {@link Scheduler}.
*
* * @return an {@code ObservableSource} that upon connection causes the source {@code ObservableSource} to emit items * to its {@link Observer}s * @see ReactiveX operators documentation: RefCount */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable share() { return publish().refCount(); } /** * Returns a Maybe that completes if this Observable is empty or emits the single item emitted by this Observable, * or signals an {@code IllegalArgumentException} if this Observable emits more than one item. *

* *

*
Scheduler:
*
{@code singleElement} does not operate by default on a particular {@link Scheduler}.
*
* * @return a {@link Maybe} that emits the single item emitted by the source ObservableSource * @see ReactiveX operators documentation: First */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Maybe singleElement() { return RxJavaPlugins.onAssembly(new ObservableSingleMaybe(this)); } /** * Returns a Single that emits the single item emitted by this Observable, if this Observable * emits only a single item, or a default item if the source ObservableSource emits no items. If the source * ObservableSource emits more than one item, an {@code IllegalArgumentException} is signalled instead. *

* *

*
Scheduler:
*
{@code single} does not operate by default on a particular {@link Scheduler}.
*
* * @param defaultItem * a default value to emit if the source ObservableSource emits no item * @return the new Single instance * @see ReactiveX operators documentation: First */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single single(T defaultItem) { ObjectHelper.requireNonNull(defaultItem, "defaultItem is null"); return RxJavaPlugins.onAssembly(new ObservableSingleSingle(this, defaultItem)); } /** * Returns a Single that emits the single item emitted by this Observable if this Observable * emits only a single item, otherwise * if this Observable completes without emitting any items or emits more than one item a * {@link NoSuchElementException} or {@code IllegalArgumentException} will be signalled respectively. *

* *

*
Scheduler:
*
{@code singleOrError} does not operate by default on a particular {@link Scheduler}.
*
* * @return the new Single instance * @see ReactiveX operators documentation: First */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single singleOrError() { return RxJavaPlugins.onAssembly(new ObservableSingleSingle(this, null)); } /** * Returns an Observable that skips the first {@code count} items emitted by the source ObservableSource and emits * the remainder. *

* *

*
Scheduler:
*
This version of {@code skip} does not operate by default on a particular {@link Scheduler}.
*
* * @param count * the number of items to skip * @return an Observable that is identical to the source ObservableSource except that it does not emit the first * {@code count} items that the source ObservableSource emits * @see ReactiveX operators documentation: Skip */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable skip(long count) { if (count <= 0) { return RxJavaPlugins.onAssembly(this); } return RxJavaPlugins.onAssembly(new ObservableSkip(this, count)); } /** * Returns an Observable that skips values emitted by the source ObservableSource before a specified time window * elapses. *

* *

*
Scheduler:
*
{@code skip} does not operate on any particular scheduler but uses the current time * from the {@code computation} {@link Scheduler}.
*
* * @param time * the length of the time window to skip * @param unit * the time unit of {@code time} * @return an Observable that skips values emitted by the source ObservableSource before the time window defined * by {@code time} elapses and the emits the remainder * @see ReactiveX operators documentation: Skip */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable skip(long time, TimeUnit unit) { return skipUntil(timer(time, unit)); } /** * Returns an Observable that skips values emitted by the source ObservableSource before a specified time window * on a specified {@link Scheduler} elapses. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use for the timed skipping
*
* * @param time * the length of the time window to skip * @param unit * the time unit of {@code time} * @param scheduler * the {@link Scheduler} on which the timed wait happens * @return an Observable that skips values emitted by the source ObservableSource before the time window defined * by {@code time} and {@code scheduler} elapses, and then emits the remainder * @see ReactiveX operators documentation: Skip */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable skip(long time, TimeUnit unit, Scheduler scheduler) { return skipUntil(timer(time, unit, scheduler)); } /** * Returns an Observable that drops a specified number of items from the end of the sequence emitted by the * source ObservableSource. *

* *

* This Observer accumulates a queue long enough to store the first {@code count} items. As more items are * received, items are taken from the front of the queue and emitted by the returned ObservableSource. This causes * such items to be delayed. *

*
Scheduler:
*
This version of {@code skipLast} does not operate by default on a particular {@link Scheduler}.
*
* * @param count * number of items to drop from the end of the source sequence * @return an Observable that emits the items emitted by the source ObservableSource except for the dropped ones * at the end * @throws IndexOutOfBoundsException * if {@code count} is less than zero * @see ReactiveX operators documentation: SkipLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable skipLast(int count) { if (count < 0) { throw new IndexOutOfBoundsException("count >= 0 required but it was " + count); } if (count == 0) { return RxJavaPlugins.onAssembly(this); } return RxJavaPlugins.onAssembly(new ObservableSkipLast(this, count)); } /** * Returns an Observable that drops items emitted by the source ObservableSource during a specified time window * before the source completes. *

* *

* Note: this action will cache the latest items arriving in the specified time window. *

*
Scheduler:
*
{@code skipLast} does not operate on any particular scheduler but uses the current time * from the {@code computation} {@link Scheduler}.
*
* * @param time * the length of the time window * @param unit * the time unit of {@code time} * @return an Observable that drops those items emitted by the source ObservableSource in a time window before the * source completes defined by {@code time} * @see ReactiveX operators documentation: SkipLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.TRAMPOLINE) public final Observable skipLast(long time, TimeUnit unit) { return skipLast(time, unit, Schedulers.trampoline(), false, bufferSize()); } /** * Returns an Observable that drops items emitted by the source ObservableSource during a specified time window * before the source completes. *

* *

* Note: this action will cache the latest items arriving in the specified time window. *

*
Scheduler:
*
{@code skipLast} does not operate on any particular scheduler but uses the current time * from the {@code computation} {@link Scheduler}.
*
* * @param time * the length of the time window * @param unit * the time unit of {@code time} * @param delayError * if true, an exception signalled by the current Observable is delayed until the regular elements are consumed * by the downstream; if false, an exception is immediately signalled and all regular elements dropped * @return an Observable that drops those items emitted by the source ObservableSource in a time window before the * source completes defined by {@code time} * @see ReactiveX operators documentation: SkipLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.TRAMPOLINE) public final Observable skipLast(long time, TimeUnit unit, boolean delayError) { return skipLast(time, unit, Schedulers.trampoline(), delayError, bufferSize()); } /** * Returns an Observable that drops items emitted by the source ObservableSource during 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 {@link Scheduler} this operator will use for tracking the current time
*
* * @param time * the length of the time window * @param unit * the time unit of {@code time} * @param scheduler * the scheduler used as the time source * @return an Observable that drops those items emitted by the source ObservableSource in a time window before the * source completes defined by {@code time} and {@code scheduler} * @see ReactiveX operators documentation: SkipLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable skipLast(long time, TimeUnit unit, Scheduler scheduler) { return skipLast(time, unit, scheduler, false, bufferSize()); } /** * Returns an Observable that drops items emitted by the source ObservableSource during 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 {@link Scheduler} this operator will use to track the current time
*
* * @param time * the length of the time window * @param unit * the time unit of {@code time} * @param scheduler * the scheduler used as the time source * @param delayError * if true, an exception signalled by the current Observable is delayed until the regular elements are consumed * by the downstream; if false, an exception is immediately signalled and all regular elements dropped * @return an Observable that drops those items emitted by the source ObservableSource in a time window before the * source completes defined by {@code time} and {@code scheduler} * @see ReactiveX operators documentation: SkipLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable skipLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError) { return skipLast(time, unit, scheduler, delayError, bufferSize()); } /** * Returns an Observable that drops items emitted by the source ObservableSource during 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 {@link Scheduler} this operator will use.
*
* * @param time * the length of the time window * @param unit * the time unit of {@code time} * @param scheduler * the scheduler used as the time source * @param delayError * if true, an exception signalled by the current Observable is delayed until the regular elements are consumed * by the downstream; if false, an exception is immediately signalled and all regular elements dropped * @param bufferSize * the hint about how many elements to expect to be skipped * @return an Observable that drops those items emitted by the source ObservableSource in a time window before the * source completes defined by {@code time} and {@code scheduler} * @see ReactiveX operators documentation: SkipLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable skipLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); // the internal buffer holds pairs of (timestamp, value) so double the default buffer size int s = bufferSize << 1; return RxJavaPlugins.onAssembly(new ObservableSkipLastTimed(this, time, unit, scheduler, s, delayError)); } /** * Returns an Observable that skips items emitted by the source ObservableSource until a second ObservableSource emits * an item. *

* *

*
Scheduler:
*
{@code skipUntil} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the other ObservableSource * @param other * the second ObservableSource that has to emit an item before the source ObservableSource's elements begin * to be mirrored by the resulting ObservableSource * @return an Observable that skips items from the source ObservableSource until the second ObservableSource emits an * item, then emits the remaining items * @see ReactiveX operators documentation: SkipUntil */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable skipUntil(ObservableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableSkipUntil(this, other)); } /** * Returns an Observable that skips all items emitted by the source ObservableSource as long as a specified * condition holds true, but emits all further source items as soon as the condition becomes false. *

* *

*
Scheduler:
*
{@code skipWhile} does not operate by default on a particular {@link Scheduler}.
*
* * @param predicate * a function to test each item emitted from the source ObservableSource * @return an Observable that begins emitting items emitted by the source ObservableSource when the specified * predicate becomes false * @see ReactiveX operators documentation: SkipWhile */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable skipWhile(Predicate predicate) { ObjectHelper.requireNonNull(predicate, "predicate is null"); return RxJavaPlugins.onAssembly(new ObservableSkipWhile(this, predicate)); } /** * Returns an Observable that emits the events emitted by source ObservableSource, in a * sorted order. Each item emitted by the ObservableSource must implement {@link Comparable} with respect to all * other items in the sequence. *

* *

* If any item emitted by this Observable does not implement {@link Comparable} with respect to * all other items emitted by this Observable, no items will be emitted and the * sequence is terminated with a {@link ClassCastException}. * *

Note that calling {@code sorted} with long, non-terminating or infinite sources * might cause {@link OutOfMemoryError} * *

*
Scheduler:
*
{@code sorted} does not operate by default on a particular {@link Scheduler}.
*
* @return an Observable that emits the items emitted by the source ObservableSource in sorted order */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable sorted() { return toList().toObservable().map(Functions.listSorter(Functions.naturalComparator())).flatMapIterable(Functions.>identity()); } /** * Returns an Observable that emits the events emitted by source ObservableSource, in a * sorted order based on a specified comparison function. * *

Note that calling {@code sorted} with long, non-terminating or infinite sources * might cause {@link OutOfMemoryError} * *

*
Scheduler:
*
{@code sorted} does not operate by default on a particular {@link Scheduler}.
*
* * @param sortFunction * a function that compares two items emitted by the source ObservableSource and returns an Integer * that indicates their sort order * @return an Observable that emits the items emitted by the source ObservableSource in sorted order */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable sorted(Comparator sortFunction) { ObjectHelper.requireNonNull(sortFunction, "sortFunction is null"); return toList().toObservable().map(Functions.listSorter(sortFunction)).flatMapIterable(Functions.>identity()); } /** * Returns an Observable that emits the items in a specified {@link Iterable} before it begins to emit items * emitted by the source ObservableSource. *

* *

*
Scheduler:
*
{@code startWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param items * an Iterable that contains the items you want the modified ObservableSource to emit first * @return an Observable that emits the items in the specified {@link Iterable} and then emits the items * emitted by the source ObservableSource * @see ReactiveX operators documentation: StartWith */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable startWith(Iterable items) { return concatArray(fromIterable(items), this); } /** * Returns an Observable that emits the items in a specified {@link ObservableSource} before it begins to emit * items emitted by the source ObservableSource. *

* *

*
Scheduler:
*
{@code startWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param other * an ObservableSource that contains the items you want the modified ObservableSource to emit first * @return an Observable that emits the items in the specified {@link ObservableSource} and then emits the items * emitted by the source ObservableSource * @see ReactiveX operators documentation: StartWith */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable startWith(ObservableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return concatArray(other, this); } /** * Returns an Observable that emits a specified item before it begins to emit items emitted by the source * ObservableSource. *

* *

*
Scheduler:
*
{@code startWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param item * the item to emit first * @return an Observable that emits the specified item before it begins to emit items emitted by the source * ObservableSource * @see ReactiveX operators documentation: StartWith */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable startWith(T item) { ObjectHelper.requireNonNull(item, "item is null"); return concatArray(just(item), this); } /** * Returns an Observable that emits the specified items before it begins to emit items emitted by the source * ObservableSource. *

* *

*
Scheduler:
*
{@code startWithArray} does not operate by default on a particular {@link Scheduler}.
*
* * @param items * the array of values to emit first * @return an Observable that emits the specified items before it begins to emit items emitted by the source * ObservableSource * @see ReactiveX operators documentation: StartWith */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable startWithArray(T... items) { Observable fromArray = fromArray(items); if (fromArray == empty()) { return RxJavaPlugins.onAssembly(this); } return concatArray(fromArray, this); } /** * Subscribes to an ObservableSource and ignores {@code onNext} and {@code onComplete} emissions. *

* If the Observable emits an error, it is wrapped into an * {@link io.reactivex.exceptions.OnErrorNotImplementedException OnErrorNotImplementedException} * and routed to the RxJavaPlugins.onError handler. *

*
Scheduler:
*
{@code subscribe} does not operate by default on a particular {@link Scheduler}.
*
* * @return a {@link Disposable} reference with which the caller can stop receiving items before * the ObservableSource has finished sending them * @see ReactiveX operators documentation: Subscribe */ @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe() { return subscribe(Functions.emptyConsumer(), Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION, Functions.emptyConsumer()); } /** * Subscribes to an ObservableSource and provides a callback to handle the items it emits. *

* If the Observable emits an error, it is wrapped into an * {@link io.reactivex.exceptions.OnErrorNotImplementedException OnErrorNotImplementedException} * and routed to the RxJavaPlugins.onError handler. *

*
Scheduler:
*
{@code subscribe} does not operate by default on a particular {@link Scheduler}.
*
* * @param onNext * the {@code Consumer} you have designed to accept emissions from the ObservableSource * @return a {@link Disposable} reference with which the caller can stop receiving items before * the ObservableSource has finished sending them * @throws NullPointerException * if {@code onNext} is null * @see ReactiveX operators documentation: Subscribe */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe(Consumer onNext) { return subscribe(onNext, Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION, Functions.emptyConsumer()); } /** * Subscribes to an ObservableSource and provides callbacks to handle the items it emits and any error * notification it issues. *
*
Scheduler:
*
{@code subscribe} does not operate by default on a particular {@link Scheduler}.
*
* * @param onNext * the {@code Consumer} you have designed to accept emissions from the ObservableSource * @param onError * the {@code Consumer} you have designed to accept any error notification from the * ObservableSource * @return a {@link Disposable} reference with which the caller can stop receiving items before * the ObservableSource has finished sending them * @see ReactiveX operators documentation: Subscribe * @throws NullPointerException * if {@code onNext} is null, or * if {@code onError} is null */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe(Consumer onNext, Consumer onError) { return subscribe(onNext, onError, Functions.EMPTY_ACTION, Functions.emptyConsumer()); } /** * Subscribes to an ObservableSource and provides callbacks to handle the items it emits and any error or * completion notification it issues. *
*
Scheduler:
*
{@code subscribe} does not operate by default on a particular {@link Scheduler}.
*
* * @param onNext * the {@code Consumer} you have designed to accept emissions from the ObservableSource * @param onError * the {@code Consumer} you have designed to accept any error notification from the * ObservableSource * @param onComplete * the {@code Action} you have designed to accept a completion notification from the * ObservableSource * @return a {@link Disposable} reference with which the caller can stop receiving items before * the ObservableSource has finished sending them * @throws NullPointerException * if {@code onNext} is null, or * if {@code onError} is null, or * if {@code onComplete} is null * @see ReactiveX operators documentation: Subscribe */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe(Consumer onNext, Consumer onError, Action onComplete) { return subscribe(onNext, onError, onComplete, Functions.emptyConsumer()); } /** * Subscribes to an ObservableSource and provides callbacks to handle the items it emits and any error or * completion notification it issues. *
*
Scheduler:
*
{@code subscribe} does not operate by default on a particular {@link Scheduler}.
*
* * @param onNext * the {@code Consumer} you have designed to accept emissions from the ObservableSource * @param onError * the {@code Consumer} you have designed to accept any error notification from the * ObservableSource * @param onComplete * the {@code Action} you have designed to accept a completion notification from the * ObservableSource * @param onSubscribe * the {@code Consumer} that receives the upstream's Disposable * @return a {@link Disposable} reference with which the caller can stop receiving items before * the ObservableSource has finished sending them * @throws NullPointerException * if {@code onNext} is null, or * if {@code onError} is null, or * if {@code onComplete} is null, or * if {@code onSubscribe} is null * @see ReactiveX operators documentation: Subscribe */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe(Consumer onNext, Consumer onError, Action onComplete, Consumer onSubscribe) { ObjectHelper.requireNonNull(onNext, "onNext is null"); ObjectHelper.requireNonNull(onError, "onError is null"); ObjectHelper.requireNonNull(onComplete, "onComplete is null"); ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null"); LambdaObserver ls = new LambdaObserver(onNext, onError, onComplete, onSubscribe); subscribe(ls); return ls; } @SchedulerSupport(SchedulerSupport.NONE) @Override public final void subscribe(Observer observer) { ObjectHelper.requireNonNull(observer, "observer is null"); try { observer = RxJavaPlugins.onSubscribe(this, observer); ObjectHelper.requireNonNull(observer, "The RxJavaPlugins.onSubscribe hook returned a null Observer. Please change the handler provided to RxJavaPlugins.setOnObservableSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins"); subscribeActual(observer); } catch (NullPointerException e) { // NOPMD throw e; } catch (Throwable e) { Exceptions.throwIfFatal(e); // can't call onError because no way to know if a Disposable has been set or not // can't call onSubscribe because the call might have set a Subscription already RxJavaPlugins.onError(e); NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS"); npe.initCause(e); throw npe; } } /** * Operator implementations (both source and intermediate) should implement this method that * performs the necessary business logic and handles the incoming {@link Observer}s. *

There is no need to call any of the plugin hooks on the current {@code Observable} instance or * the {@code Observer}; all hooks and basic safeguards have been * applied by {@link #subscribe(Observer)} before this method gets called. * @param observer the incoming Observer, never null */ protected abstract void subscribeActual(Observer observer); /** * Subscribes a given Observer (subclass) to this Observable and returns the given * Observer 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:
*
{@code subscribeWith} does not operate by default on a particular {@link Scheduler}.
*
* @param the type of the Observer to use and return * @param observer the Observer (subclass) to use and return, not null * @return the input {@code observer} * @throws NullPointerException if {@code observer} is null * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final > E subscribeWith(E observer) { subscribe(observer); return observer; } /** * Asynchronously subscribes Observers to this ObservableSource on the specified {@link Scheduler}. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param scheduler * the {@link Scheduler} to perform subscription actions on * @return the source ObservableSource modified so that its subscriptions happen on the * specified {@link Scheduler} * @see ReactiveX operators documentation: SubscribeOn * @see RxJava Threading Examples * @see #observeOn */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable subscribeOn(Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new ObservableSubscribeOn(this, scheduler)); } /** * Returns an Observable that emits the items emitted by the source ObservableSource or the items of an alternate * ObservableSource if the source ObservableSource is empty. *

* *

*
Scheduler:
*
{@code switchIfEmpty} does not operate by default on a particular {@link Scheduler}.
*
* * @param other * the alternate ObservableSource to subscribe to if the source does not emit any items * @return an ObservableSource that emits the items emitted by the source ObservableSource or the items of an * alternate ObservableSource if the source ObservableSource is empty. * @since 1.1.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable switchIfEmpty(ObservableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableSwitchIfEmpty(this, other)); } /** * Returns a new ObservableSource by applying a function that you supply to each item emitted by the source * ObservableSource that returns an ObservableSource, and then emitting the items emitted by the most recently emitted * of these ObservableSources. *

* The resulting ObservableSource completes if both the upstream ObservableSource and the last inner ObservableSource, if any, complete. * If the upstream ObservableSource signals an onError, the inner ObservableSource is disposed and the error delivered in-sequence. *

* *

*
Scheduler:
*
{@code switchMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the inner ObservableSources and the output * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns an * ObservableSource * @return an Observable that emits the items emitted by the ObservableSource returned from applying {@code func} to the most recently emitted item emitted by the source ObservableSource * @see ReactiveX operators documentation: FlatMap * @see #switchMapDelayError(Function) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable switchMap(Function> mapper) { return switchMap(mapper, bufferSize()); } /** * Returns a new ObservableSource by applying a function that you supply to each item emitted by the source * ObservableSource that returns an ObservableSource, and then emitting the items emitted by the most recently emitted * of these ObservableSources. *

* The resulting ObservableSource completes if both the upstream ObservableSource and the last inner ObservableSource, if any, complete. * If the upstream ObservableSource signals an onError, the inner ObservableSource is disposed and the error delivered in-sequence. *

* *

*
Scheduler:
*
{@code switchMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the inner ObservableSources and the output * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns an * ObservableSource * @param bufferSize * the number of elements to prefetch from the current active inner ObservableSource * @return an Observable that emits the items emitted by the ObservableSource returned from applying {@code func} to the most recently emitted item emitted by the source ObservableSource * @see ReactiveX operators documentation: FlatMap * @see #switchMapDelayError(Function, int) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable switchMap(Function> mapper, int bufferSize) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); if (this instanceof ScalarCallable) { @SuppressWarnings("unchecked") T v = ((ScalarCallable)this).call(); if (v == null) { return empty(); } return ObservableScalarXMap.scalarXMap(v, mapper); } return RxJavaPlugins.onAssembly(new ObservableSwitchMap(this, mapper, bufferSize, false)); } /** * Maps the upstream values into {@link CompletableSource}s, subscribes to the newer one while * disposing the subscription to the previous {@code CompletableSource}, thus keeping at most one * active {@code CompletableSource} running. *

* *

* Since a {@code CompletableSource} doesn't produce any items, the resulting reactive type of * this operator is a {@link Completable} that can only indicate successful completion or * a failure in any of the inner {@code CompletableSource}s or the failure of the current * {@link Observable}. *

*
Scheduler:
*
{@code switchMapCompletable} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
If either this {@code Observable} or the active {@code CompletableSource} signals an {@code onError}, * the resulting {@code Completable} is terminated immediately with that {@code Throwable}. * Use the {@link #switchMapCompletableDelayError(Function)} to delay such inner failures until * every inner {@code CompletableSource}s and the main {@code Observable} terminates in some fashion. * If they fail concurrently, the operator may combine the {@code Throwable}s into a * {@link io.reactivex.exceptions.CompositeException CompositeException} * and signal it to the downstream instead. If any inactivated (switched out) {@code CompletableSource} * signals an {@code onError} late, the {@code Throwable}s will be signalled to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. *
*
*

History: 2.1.11 - experimental * @param mapper the function called with each upstream item and should return a * {@link CompletableSource} to be subscribed to and awaited for * (non blockingly) for its terminal event * @return the new Completable instance * @see #switchMapCompletableDelayError(Function) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable switchMapCompletable(@NonNull Function mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableSwitchMapCompletable(this, mapper, false)); } /** * Maps the upstream values into {@link CompletableSource}s, subscribes to the newer one while * disposing the subscription to the previous {@code CompletableSource}, thus keeping at most one * active {@code CompletableSource} running and delaying any main or inner errors until all * of them terminate. *

* *

* Since a {@code CompletableSource} doesn't produce any items, the resulting reactive type of * this operator is a {@link Completable} that can only indicate successful completion or * a failure in any of the inner {@code CompletableSource}s or the failure of the current * {@link Observable}. *

*
Scheduler:
*
{@code switchMapCompletableDelayError} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
Errors of this {@code Observable} and all the {@code CompletableSource}s, 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 respective * {@code Throwable} is emitted to the downstream. It there were more than one failures, the * operator combines all {@code Throwable}s into a {@link io.reactivex.exceptions.CompositeException CompositeException} * and signals that to the downstream. * If any inactivated (switched out) {@code CompletableSource} * signals an {@code onError} late, the {@code Throwable}s will be signalled to the global error handler via * {@link RxJavaPlugins#onError(Throwable)} method as {@code UndeliverableException} errors. *
*
*

History: 2.1.11 - experimental * @param mapper the function called with each upstream item and should return a * {@link CompletableSource} to be subscribed to and awaited for * (non blockingly) for its terminal event * @return the new Completable instance * @see #switchMapCompletable(Function) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable switchMapCompletableDelayError(@NonNull Function mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableSwitchMapCompletable(this, mapper, true)); } /** * Maps the upstream items into {@link MaybeSource}s 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 this {@code Observable} or any of the * active inner {@code MaybeSource}s fail. *

* *

*
Scheduler:
*
{@code switchMapMaybe} does not operate by default on a particular {@link Scheduler}.
*
Error handling:
*
This operator terminates with an {@code onError} if this {@code Observable} or any of * the inner {@code MaybeSource}s fail while they are active. When this happens concurrently, their * individual {@code Throwable} errors may get combined and emitted as a single * {@link io.reactivex.exceptions.CompositeException CompositeException}. Otherwise, a late * (i.e., inactive or switched out) {@code onError} from this {@code Observable} or from any of * the inner {@code MaybeSource}s will be forwarded to the global error handler via * {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)} as * {@link io.reactivex.exceptions.UndeliverableException UndeliverableException}
*
*

History: 2.1.11 - experimental * @param the output value type * @param mapper the function called with the current upstream event and should * return a {@code MaybeSource} to replace the current active inner source * and get subscribed to. * @return the new Observable instance * @see #switchMapMaybeDelayError(Function) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable switchMapMaybe(@NonNull Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableSwitchMapMaybe(this, mapper, false)); } /** * Maps the upstream items into {@link MaybeSource}s 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 this {@code Observable} or the inner {@code MaybeSource}s until all terminate. *

* *

*
Scheduler:
*
{@code switchMapMaybeDelayError} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.1.11 - experimental * @param the output value type * @param mapper the function called with the current upstream event and should * return a {@code MaybeSource} to replace the current active inner source * and get subscribed to. * @return the new Observable instance * @see #switchMapMaybe(Function) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable switchMapMaybeDelayError(@NonNull Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableSwitchMapMaybe(this, mapper, true)); } /** * Returns a new ObservableSource by applying a function that you supply to each item emitted by the source * ObservableSource that returns a SingleSource, and then emitting the item emitted by the most recently emitted * of these SingleSources. *

* The resulting ObservableSource completes if both the upstream ObservableSource and the last inner SingleSource, if any, complete. * If the upstream ObservableSource signals an onError, the inner SingleSource is disposed and the error delivered in-sequence. *

* *

*
Scheduler:
*
{@code switchMapSingle} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.0.8 - experimental * @param the element type of the inner SingleSources and the output * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns a * SingleSource * @return an Observable that emits the item emitted by the SingleSource returned from applying {@code func} to the most recently emitted item emitted by the source ObservableSource * @see ReactiveX operators documentation: FlatMap * @see #switchMapSingleDelayError(Function) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @NonNull public final Observable switchMapSingle(@NonNull Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableSwitchMapSingle(this, mapper, false)); } /** * Returns a new ObservableSource by applying a function that you supply to each item emitted by the source * ObservableSource that returns a SingleSource, and then emitting the item emitted by the most recently emitted * of these SingleSources and delays any error until all SingleSources terminate. *

* The resulting ObservableSource completes if both the upstream ObservableSource and the last inner SingleSource, if any, complete. * If the upstream ObservableSource signals an onError, the termination of the last inner SingleSource will emit that error as is * or wrapped into a CompositeException along with the other possible errors the former inner SingleSources signalled. *

* *

*
Scheduler:
*
{@code switchMapSingleDelayError} does not operate by default on a particular {@link Scheduler}.
*
*

History: 2.0.8 - experimental * @param the element type of the inner SingleSources and the output * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns a * SingleSource * @return an Observable that emits the item emitted by the SingleSource returned from applying {@code func} to the most recently emitted item emitted by the source ObservableSource * @see ReactiveX operators documentation: FlatMap * @see #switchMapSingle(Function) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @NonNull public final Observable switchMapSingleDelayError(@NonNull Function> mapper) { ObjectHelper.requireNonNull(mapper, "mapper is null"); return RxJavaPlugins.onAssembly(new ObservableSwitchMapSingle(this, mapper, true)); } /** * Returns a new ObservableSource by applying a function that you supply to each item emitted by the source * ObservableSource that returns an ObservableSource, and then emitting the items emitted by the most recently emitted * of these ObservableSources and delays any error until all ObservableSources terminate. *

* The resulting ObservableSource completes if both the upstream ObservableSource and the last inner ObservableSource, if any, complete. * If the upstream ObservableSource signals an onError, the termination of the last inner ObservableSource will emit that error as is * or wrapped into a CompositeException along with the other possible errors the former inner ObservableSources signalled. *

* *

*
Scheduler:
*
{@code switchMapDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the inner ObservableSources and the output * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns an * ObservableSource * @return an Observable that emits the items emitted by the ObservableSource returned from applying {@code func} to the most recently emitted item emitted by the source ObservableSource * @see ReactiveX operators documentation: FlatMap * @see #switchMap(Function) * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable switchMapDelayError(Function> mapper) { return switchMapDelayError(mapper, bufferSize()); } /** * Returns a new ObservableSource by applying a function that you supply to each item emitted by the source * ObservableSource that returns an ObservableSource, and then emitting the items emitted by the most recently emitted * of these ObservableSources and delays any error until all ObservableSources terminate. *

* The resulting ObservableSource completes if both the upstream ObservableSource and the last inner ObservableSource, if any, complete. * If the upstream ObservableSource signals an onError, the termination of the last inner ObservableSource will emit that error as is * or wrapped into a CompositeException along with the other possible errors the former inner ObservableSources signalled. *

* *

*
Scheduler:
*
{@code switchMapDelayError} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the inner ObservableSources and the output * @param mapper * a function that, when applied to an item emitted by the source ObservableSource, returns an * ObservableSource * @param bufferSize * the number of elements to prefetch from the current active inner ObservableSource * @return an Observable that emits the items emitted by the ObservableSource returned from applying {@code func} to the most recently emitted item emitted by the source ObservableSource * @see ReactiveX operators documentation: FlatMap * @see #switchMap(Function, int) * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable switchMapDelayError(Function> mapper, int bufferSize) { ObjectHelper.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); if (this instanceof ScalarCallable) { @SuppressWarnings("unchecked") T v = ((ScalarCallable)this).call(); if (v == null) { return empty(); } return ObservableScalarXMap.scalarXMap(v, mapper); } return RxJavaPlugins.onAssembly(new ObservableSwitchMap(this, mapper, bufferSize, true)); } /** * Returns an Observable that emits only the first {@code count} items emitted by the source ObservableSource. If the source emits fewer than * {@code count} items then all of its items are emitted. *

* *

* This method returns an ObservableSource that will invoke a subscribing {@link Observer}'s * {@link Observer#onNext onNext} function a maximum of {@code count} times before invoking * {@link Observer#onComplete onComplete}. *

*
Scheduler:
*
This version of {@code take} does not operate by default on a particular {@link Scheduler}.
*
* * @param count * the maximum number of items to emit * @return an Observable that emits only the first {@code count} items emitted by the source ObservableSource, or * all of the items from the source ObservableSource if that ObservableSource emits fewer than {@code count} items * @see ReactiveX operators documentation: Take */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable take(long count) { if (count < 0) { throw new IllegalArgumentException("count >= 0 required but it was " + count); } return RxJavaPlugins.onAssembly(new ObservableTake(this, count)); } /** * Returns an Observable that emits those items emitted by source ObservableSource before a specified time runs * out. *

* If time runs out before the {@code Observable} completes normally, the {@code onComplete} event will be * signaled on the default {@code computation} {@link Scheduler}. *

* *

*
Scheduler:
*
This version of {@code take} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param time * the length of the time window * @param unit * the time unit of {@code time} * @return an Observable that emits those items emitted by the source ObservableSource before the time runs out * @see ReactiveX operators documentation: Take */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable take(long time, TimeUnit unit) { return takeUntil(timer(time, unit)); } /** * Returns an Observable that emits those items emitted by source ObservableSource before a specified time (on a * specified Scheduler) runs out. *

* If time runs out before the {@code Observable} completes normally, the {@code onComplete} event will be * signaled on the provided {@link Scheduler}. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param time * the length of the time window * @param unit * the time unit of {@code time} * @param scheduler * the Scheduler used for time source * @return an Observable that emits those items emitted by the source ObservableSource before the time runs out, * according to the specified Scheduler * @see ReactiveX operators documentation: Take */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable take(long time, TimeUnit unit, Scheduler scheduler) { return takeUntil(timer(time, unit, scheduler)); } /** * Returns an Observable that emits at most the last {@code count} items emitted by the source ObservableSource. If the source emits fewer than * {@code count} items then all of its items are emitted. *

* *

*
Scheduler:
*
This version of {@code takeLast} does not operate by default on a particular {@link Scheduler}.
*
* * @param count * the maximum number of items to emit from the end of the sequence of items emitted by the source * ObservableSource * @return an Observable that emits at most the last {@code count} items emitted by the source ObservableSource * @throws IndexOutOfBoundsException * if {@code count} is less than zero * @see ReactiveX operators documentation: TakeLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable takeLast(int count) { if (count < 0) { throw new IndexOutOfBoundsException("count >= 0 required but it was " + count); } if (count == 0) { return RxJavaPlugins.onAssembly(new ObservableIgnoreElements(this)); } if (count == 1) { return RxJavaPlugins.onAssembly(new ObservableTakeLastOne(this)); } return RxJavaPlugins.onAssembly(new ObservableTakeLast(this, count)); } /** * Returns an Observable that emits at most a specified number of items from the source ObservableSource that were * emitted in a specified window of time before the ObservableSource completed. *

* *

*
Scheduler:
*
{@code takeLast} does not operate on any particular scheduler but uses the current time * from the {@code computation} {@link Scheduler}.
*
* * @param count * the maximum number of items to emit * @param time * the length of the time window * @param unit * the time unit of {@code time} * @return an Observable that emits at most {@code count} items from the source ObservableSource that were emitted * in a specified window of time before the ObservableSource completed * @see ReactiveX operators documentation: TakeLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.TRAMPOLINE) public final Observable takeLast(long count, long time, TimeUnit unit) { return takeLast(count, time, unit, Schedulers.trampoline(), false, bufferSize()); } /** * Returns an Observable that emits at most a specified number of items from the source ObservableSource that were * emitted in a specified window of time before the ObservableSource completed, where the timing information is * provided by a given Scheduler. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use for tracking the current time
*
* * @param count * the maximum number of items to emit * @param time * the length of the time window * @param unit * the time unit of {@code time} * @param scheduler * the {@link Scheduler} that provides the timestamps for the observed items * @return an Observable that emits at most {@code count} items from the source ObservableSource that were emitted * in a specified window of time before the ObservableSource completed, where the timing information is * provided by the given {@code scheduler} * @throws IndexOutOfBoundsException * if {@code count} is less than zero * @see ReactiveX operators documentation: TakeLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable takeLast(long count, long time, TimeUnit unit, Scheduler scheduler) { return takeLast(count, time, unit, scheduler, false, bufferSize()); } /** * Returns an Observable that emits at most a specified number of items from the source ObservableSource that were * emitted in a specified window of time before the ObservableSource completed, where the timing information is * provided by a given Scheduler. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use for tracking the current time
*
* * @param count * the maximum number of items to emit * @param time * the length of the time window * @param unit * the time unit of {@code time} * @param scheduler * the {@link Scheduler} that provides the timestamps for the observed items * @param delayError * if true, an exception signalled by the current Observable is delayed until the regular elements are consumed * by the downstream; if false, an exception is immediately signalled and all regular elements dropped * @param bufferSize * the hint about how many elements to expect to be last * @return an Observable that emits at most {@code count} items from the source ObservableSource that were emitted * in a specified window of time before the ObservableSource completed, where the timing information is * provided by the given {@code scheduler} * @throws IndexOutOfBoundsException * if {@code count} is less than zero * @see ReactiveX operators documentation: TakeLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable takeLast(long count, long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); if (count < 0) { throw new IndexOutOfBoundsException("count >= 0 required but it was " + count); } return RxJavaPlugins.onAssembly(new ObservableTakeLastTimed(this, count, time, unit, scheduler, bufferSize, delayError)); } /** * Returns an Observable that emits the items from the source ObservableSource that were emitted in a specified * window of time before the ObservableSource completed. *

* *

*
Scheduler:
*
This version of {@code takeLast} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param time * the length of the time window * @param unit * the time unit of {@code time} * @return an Observable that emits the items from the source ObservableSource that were emitted in the window of * time before the ObservableSource completed specified by {@code time} * @see ReactiveX operators documentation: TakeLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.TRAMPOLINE) public final Observable takeLast(long time, TimeUnit unit) { return takeLast(time, unit, Schedulers.trampoline(), false, bufferSize()); } /** * Returns an Observable that emits the items from the source ObservableSource that were emitted in a specified * window of time before the ObservableSource completed. *

* *

*
Scheduler:
*
This version of {@code takeLast} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param time * the length of the time window * @param unit * the time unit of {@code time} * @param delayError * if true, an exception signalled by the current Observable is delayed until the regular elements are consumed * by the downstream; if false, an exception is immediately signalled and all regular elements dropped * @return an Observable that emits the items from the source ObservableSource that were emitted in the window of * time before the ObservableSource completed specified by {@code time} * @see ReactiveX operators documentation: TakeLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.TRAMPOLINE) public final Observable takeLast(long time, TimeUnit unit, boolean delayError) { return takeLast(time, unit, Schedulers.trampoline(), delayError, bufferSize()); } /** * Returns an Observable that emits the items from the source ObservableSource that were emitted in a specified * window of time before the ObservableSource completed, where the timing information is provided by a specified * Scheduler. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param time * the length of the time window * @param unit * the time unit of {@code time} * @param scheduler * the Scheduler that provides the timestamps for the Observed items * @return an Observable that emits the items from the source ObservableSource that were emitted in the window of * time before the ObservableSource completed specified by {@code time}, where the timing information is * provided by {@code scheduler} * @see ReactiveX operators documentation: TakeLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable takeLast(long time, TimeUnit unit, Scheduler scheduler) { return takeLast(time, unit, scheduler, false, bufferSize()); } /** * Returns an Observable that emits the items from the source ObservableSource that were emitted in a specified * window of time before the ObservableSource completed, where the timing information is provided by a specified * Scheduler. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param time * the length of the time window * @param unit * the time unit of {@code time} * @param scheduler * the Scheduler that provides the timestamps for the Observed items * @param delayError * if true, an exception signalled by the current Observable is delayed until the regular elements are consumed * by the downstream; if false, an exception is immediately signalled and all regular elements dropped * @return an Observable that emits the items from the source ObservableSource that were emitted in the window of * time before the ObservableSource completed specified by {@code time}, where the timing information is * provided by {@code scheduler} * @see ReactiveX operators documentation: TakeLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable takeLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError) { return takeLast(time, unit, scheduler, delayError, bufferSize()); } /** * Returns an Observable that emits the items from the source ObservableSource that were emitted in a specified * window of time before the ObservableSource completed, where the timing information is provided by a specified * Scheduler. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param time * the length of the time window * @param unit * the time unit of {@code time} * @param scheduler * the Scheduler that provides the timestamps for the Observed items * @param delayError * if true, an exception signalled by the current Observable is delayed until the regular elements are consumed * by the downstream; if false, an exception is immediately signalled and all regular elements dropped * @param bufferSize * the hint about how many elements to expect to be last * @return an Observable that emits the items from the source ObservableSource that were emitted in the window of * time before the ObservableSource completed specified by {@code time}, where the timing information is * provided by {@code scheduler} * @see ReactiveX operators documentation: TakeLast */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable takeLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { return takeLast(Long.MAX_VALUE, time, unit, scheduler, delayError, bufferSize); } /** * Returns an Observable that emits the items emitted by the source Observable until a second ObservableSource * emits an item. *

* *

*
Scheduler:
*
{@code takeUntil} does not operate by default on a particular {@link Scheduler}.
*
* * @param other * the ObservableSource whose first emitted item will cause {@code takeUntil} to stop emitting items * from the source Observable * @param * the type of items emitted by {@code other} * @return an Observable that emits the items emitted by the source Observable until such time as {@code other} emits its first item * @see ReactiveX operators documentation: TakeUntil */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable takeUntil(ObservableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new ObservableTakeUntil(this, other)); } /** * Returns an Observable that emits items emitted by the source Observable, checks the specified predicate * for each item, and then completes when the condition is satisfied. *

* *

* The difference between this operator and {@link #takeWhile(Predicate)} is that here, the condition is * evaluated after the item is emitted. * *

*
Scheduler:
*
{@code takeUntil} does not operate by default on a particular {@link Scheduler}.
*
* * @param stopPredicate * a function that evaluates an item emitted by the source Observable and returns a Boolean * @return an Observable that first emits items emitted by the source Observable, checks the specified * condition after each item, and then completes when the condition is satisfied. * @see ReactiveX operators documentation: TakeUntil * @see Observable#takeWhile(Predicate) * @since 1.1.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable takeUntil(Predicate stopPredicate) { ObjectHelper.requireNonNull(stopPredicate, "stopPredicate is null"); return RxJavaPlugins.onAssembly(new ObservableTakeUntilPredicate(this, stopPredicate)); } /** * Returns an Observable that emits items emitted by the source ObservableSource so long as each item satisfied a * specified condition, and then completes as soon as this condition is not satisfied. *

* *

*
Scheduler:
*
{@code takeWhile} does not operate by default on a particular {@link Scheduler}.
*
* * @param predicate * a function that evaluates an item emitted by the source ObservableSource and returns a Boolean * @return an Observable that emits the items from the source ObservableSource so long as each item satisfies the * condition defined by {@code predicate}, then completes * @see ReactiveX operators documentation: TakeWhile * @see Observable#takeUntil(Predicate) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable takeWhile(Predicate predicate) { ObjectHelper.requireNonNull(predicate, "predicate is null"); return RxJavaPlugins.onAssembly(new ObservableTakeWhile(this, predicate)); } /** * Returns an Observable that emits only the first item emitted by the source ObservableSource during sequential * time windows of a specified duration. *

* This differs from {@link #throttleLast} in that this only tracks passage of time whereas * {@link #throttleLast} ticks at scheduled intervals. *

* *

*
Scheduler:
*
{@code throttleFirst} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param windowDuration * time to wait before emitting another item after emitting the last item * @param unit * the unit of time of {@code windowDuration} * @return an Observable that performs the throttle operation * @see ReactiveX operators documentation: Sample */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable throttleFirst(long windowDuration, TimeUnit unit) { return throttleFirst(windowDuration, unit, Schedulers.computation()); } /** * Returns an Observable that emits only the first item emitted by the source ObservableSource during sequential * time windows of a specified duration, where the windows are managed by a specified Scheduler. *

* This differs from {@link #throttleLast} in that this only tracks passage of time whereas * {@link #throttleLast} ticks at scheduled intervals. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param skipDuration * time to wait before emitting another item after emitting the last item * @param unit * the unit of time of {@code skipDuration} * @param scheduler * the {@link Scheduler} to use internally to manage the timers that handle timeout for each * event * @return an Observable that performs the throttle operation * @see ReactiveX operators documentation: Sample */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable throttleFirst(long skipDuration, TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new ObservableThrottleFirstTimed(this, skipDuration, unit, scheduler)); } /** * Returns an Observable that emits only the last item emitted by the source ObservableSource during sequential * time windows of a specified duration. *

* This differs from {@link #throttleFirst} in that this ticks along at a scheduled interval whereas * {@link #throttleFirst} does not tick, it just tracks passage of time. *

* *

*
Scheduler:
*
{@code throttleLast} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param intervalDuration * duration of windows within which the last item emitted by the source ObservableSource will be * emitted * @param unit * the unit of time of {@code intervalDuration} * @return an Observable that performs the throttle operation * @see ReactiveX operators documentation: Sample * @see #sample(long, TimeUnit) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable throttleLast(long intervalDuration, TimeUnit unit) { return sample(intervalDuration, unit); } /** * Returns an Observable that emits only the last item emitted by the source ObservableSource during sequential * time windows of a specified duration, where the duration is governed by a specified Scheduler. *

* This differs from {@link #throttleFirst} in that this ticks along at a scheduled interval whereas * {@link #throttleFirst} does not tick, it just tracks passage of time. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param intervalDuration * duration of windows within which the last item emitted by the source ObservableSource will be * emitted * @param unit * the unit of time of {@code intervalDuration} * @param scheduler * the {@link Scheduler} to use internally to manage the timers that handle timeout for each * event * @return an Observable that performs the throttle operation * @see ReactiveX operators documentation: Sample * @see #sample(long, TimeUnit, Scheduler) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable throttleLast(long intervalDuration, TimeUnit unit, Scheduler scheduler) { return sample(intervalDuration, unit, scheduler); } /** * Throttles items from the upstream {@code Observable} by 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 {@link #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:
*
{@code throttleLatest} operates by default on the {@code computation} {@link Scheduler}.
*
*

History: 2.1.14 - experimental * @param timeout the time to wait after an item emission towards the downstream * before trying to emit the latest item from upstream again * @param unit the time unit * @return the new Observable instance * @see #throttleLatest(long, TimeUnit, boolean) * @see #throttleLatest(long, TimeUnit, Scheduler) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable throttleLatest(long timeout, TimeUnit unit) { return throttleLatest(timeout, unit, Schedulers.computation(), false); } /** * Throttles items from the upstream {@code Observable} by 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:
*
{@code throttleLatest} operates by default on the {@code computation} {@link Scheduler}.
*
*

History: 2.1.14 - experimental * @param timeout the time to wait after an item emission towards the downstream * before trying to emit the latest item from upstream again * @param unit the time unit * @param emitLast If {@code true}, 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. If {@code false}, the very last * upstream item is ignored and the flow terminates. * @return the new Observable instance * @see #throttleLatest(long, TimeUnit, Scheduler, boolean) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable throttleLatest(long timeout, TimeUnit unit, boolean emitLast) { return throttleLatest(timeout, unit, Schedulers.computation(), emitLast); } /** * Throttles items from the upstream {@code Observable} by 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 {@link #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 {@link Scheduler} this operator will use.
*
*

History: 2.1.14 - experimental * @param timeout the time to wait after an item emission towards the downstream * before trying to emit the latest item from upstream again * @param unit the time unit * @param scheduler the {@link Scheduler} where the timed wait and latest item * emission will be performed * @return the new Observable instance * @see #throttleLatest(long, TimeUnit, Scheduler, boolean) * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable throttleLatest(long timeout, TimeUnit unit, Scheduler scheduler) { return throttleLatest(timeout, unit, scheduler, false); } /** * Throttles items from the upstream {@code Observable} by 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 {@link Scheduler} this operator will use.
*
*

History: 2.1.14 - experimental * @param timeout the time to wait after an item emission towards the downstream * before trying to emit the latest item from upstream again * @param unit the time unit * @param scheduler the {@link Scheduler} where the timed wait and latest item * emission will be performed * @param emitLast If {@code true}, 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. If {@code false}, the very last * upstream item is ignored and the flow terminates. * @return the new Observable instance * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable throttleLatest(long timeout, TimeUnit unit, Scheduler scheduler, boolean emitLast) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new ObservableThrottleLatest(this, timeout, unit, scheduler, emitLast)); } /** * Returns an Observable that mirrors the source ObservableSource, except that it drops items emitted by the * source ObservableSource that are followed by newer items before a timeout value expires. The timer resets on * each emission (alias to {@link #debounce(long, TimeUnit, Scheduler)}). *

* Note: If items keep being emitted by the source ObservableSource faster than the timeout then no items * will be emitted by the resulting ObservableSource. *

* *

*
Scheduler:
*
{@code throttleWithTimeout} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param timeout * the length of the window of time that must pass after the emission of an item from the source * ObservableSource in which that ObservableSource emits no items in order for the item to be emitted by the * resulting ObservableSource * @param unit * the unit of time for the specified {@code timeout} * @return an Observable that filters out items from the source ObservableSource that are too quickly followed by * newer items * @see ReactiveX operators documentation: Debounce * @see #debounce(long, TimeUnit) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable throttleWithTimeout(long timeout, TimeUnit unit) { return debounce(timeout, unit); } /** * Returns an Observable that mirrors the source ObservableSource, except that it drops items emitted by the * source ObservableSource that are followed by newer items before a timeout value expires on a specified * Scheduler. The timer resets on each emission (Alias to {@link #debounce(long, TimeUnit, Scheduler)}). *

* Note: If items keep being emitted by the source ObservableSource faster than the timeout then no items * will be emitted by the resulting ObservableSource. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param timeout * the length of the window of time that must pass after the emission of an item from the source * ObservableSource in which that ObservableSource emits no items in order for the item to be emitted by the * resulting ObservableSource * @param unit * the unit of time for the specified {@code timeout} * @param scheduler * the {@link Scheduler} to use internally to manage the timers that handle the timeout for each * item * @return an Observable that filters out items from the source ObservableSource that are too quickly followed by * newer items * @see ReactiveX operators documentation: Debounce * @see #debounce(long, TimeUnit, Scheduler) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable throttleWithTimeout(long timeout, TimeUnit unit, Scheduler scheduler) { return debounce(timeout, unit, scheduler); } /** * Returns an Observable that emits records of the time interval between consecutive items emitted by the * source ObservableSource. *

* *

*
Scheduler:
*
{@code timeInterval} does not operate on any particular scheduler but uses the current time * from the {@code computation} {@link Scheduler}.
*
* * @return an Observable that emits time interval information items * @see ReactiveX operators documentation: TimeInterval */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> timeInterval() { return timeInterval(TimeUnit.MILLISECONDS, Schedulers.computation()); } /** * Returns an Observable that emits records of the time interval between consecutive items emitted by the * source ObservableSource, where this interval is computed on a specified Scheduler. *

* *

*
Scheduler:
*
The operator does not operate on any particular scheduler but uses the current time * from the specified {@link Scheduler}.
*
* * @param scheduler * the {@link Scheduler} used to compute time intervals * @return an Observable that emits time interval information items * @see ReactiveX operators documentation: TimeInterval */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) // Supplied scheduler is only used for creating timestamps. public final Observable> timeInterval(Scheduler scheduler) { return timeInterval(TimeUnit.MILLISECONDS, scheduler); } /** * Returns an Observable that emits records of the time interval between consecutive items emitted by the * source ObservableSource. *

* *

*
Scheduler:
*
{@code timeInterval} does not operate on any particular scheduler but uses the current time * from the {@code computation} {@link Scheduler}.
*
* * @param unit the time unit for the current time * @return an Observable that emits time interval information items * @see ReactiveX operators documentation: TimeInterval */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> timeInterval(TimeUnit unit) { return timeInterval(unit, Schedulers.computation()); } /** * Returns an Observable that emits records of the time interval between consecutive items emitted by the * source ObservableSource, where this interval is computed on a specified Scheduler. *

* *

*
Scheduler:
*
The operator does not operate on any particular scheduler but uses the current time * from the specified {@link Scheduler}.
*
* * @param unit the time unit for the current time * @param scheduler * the {@link Scheduler} used to compute time intervals * @return an Observable that emits time interval information items * @see ReactiveX operators documentation: TimeInterval */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) // Supplied scheduler is only used for creating timestamps. public final Observable> timeInterval(TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new ObservableTimeInterval(this, unit, scheduler)); } /** * Returns an Observable that mirrors the source ObservableSource, but notifies observers of a * {@code TimeoutException} if an item emitted by the source ObservableSource doesn't arrive within a window of * time after the emission of the previous item, where that period of time is measured by an ObservableSource that * is a function of the previous item. *

* *

* Note: The arrival of the first source item is never timed out. *

*
Scheduler:
*
This version of {@code timeout} operates by default on the {@code immediate} {@link Scheduler}.
*
* * @param * the timeout value type (ignored) * @param itemTimeoutIndicator * a function that returns an ObservableSource for each item emitted by the source * ObservableSource and that determines the timeout window for the subsequent item * @return an Observable that mirrors the source ObservableSource, but notifies observers of a * {@code TimeoutException} if an item emitted by the source ObservableSource takes longer to arrive than * the time window defined by the selector for the previously emitted item * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable timeout(Function> itemTimeoutIndicator) { return timeout0(null, itemTimeoutIndicator, null); } /** * Returns an Observable that mirrors the source ObservableSource, but that switches to a fallback ObservableSource if * an item emitted by the source ObservableSource doesn't arrive within a window of time after the emission of the * previous item, where that period of time is measured by an ObservableSource that is a function of the previous * item. *

* *

* Note: The arrival of the first source item is never timed out. *

*
Scheduler:
*
This version of {@code timeout} operates by default on the {@code immediate} {@link Scheduler}.
*
* * @param * the timeout value type (ignored) * @param itemTimeoutIndicator * a function that returns an ObservableSource, for each item emitted by the source ObservableSource, that * determines the timeout window for the subsequent item * @param other * the fallback ObservableSource to switch to if the source ObservableSource times out * @return an Observable that mirrors the source ObservableSource, but switches to mirroring a fallback ObservableSource * if an item emitted by the source ObservableSource takes longer to arrive than the time window defined * by the selector for the previously emitted item * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable timeout(Function> itemTimeoutIndicator, ObservableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return timeout0(null, itemTimeoutIndicator, other); } /** * Returns an Observable that mirrors the source ObservableSource but 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 resulting ObservableSource terminates and notifies observers of a {@code TimeoutException}. *

* *

*
Scheduler:
*
This version of {@code timeout} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param timeout * maximum duration between emitted items before a timeout occurs * @param timeUnit * the unit of time that applies to the {@code timeout} argument. * @return the source ObservableSource modified to notify observers of a {@code TimeoutException} in case of a * timeout * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable timeout(long timeout, TimeUnit timeUnit) { return timeout0(timeout, timeUnit, null, Schedulers.computation()); } /** * Returns an Observable that mirrors the source ObservableSource but 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 source ObservableSource is disposed and resulting ObservableSource begins instead * to mirror a fallback ObservableSource. *

* *

*
Scheduler:
*
This version of {@code timeout} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param timeout * maximum duration between items before a timeout occurs * @param timeUnit * the unit of time that applies to the {@code timeout} argument * @param other * the fallback ObservableSource to use in case of a timeout * @return the source ObservableSource modified to switch to the fallback ObservableSource in case of a timeout * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable timeout(long timeout, TimeUnit timeUnit, ObservableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return timeout0(timeout, timeUnit, other, Schedulers.computation()); } /** * Returns an Observable that mirrors the source ObservableSource but applies a timeout policy for each emitted * item using a specified Scheduler. If the next item isn't emitted within the specified timeout duration * starting from its predecessor, the source ObservableSource is disposed and resulting ObservableSource * begins instead to mirror a fallback ObservableSource. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param timeout * maximum duration between items before a timeout occurs * @param timeUnit * the unit of time that applies to the {@code timeout} argument * @param scheduler * the {@link Scheduler} to run the timeout timers on * @param other * the ObservableSource to use as the fallback in case of a timeout * @return the source ObservableSource modified so that it will switch to the fallback ObservableSource in case of a * timeout * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable timeout(long timeout, TimeUnit timeUnit, Scheduler scheduler, ObservableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return timeout0(timeout, timeUnit, other, scheduler); } /** * Returns an Observable that mirrors the source ObservableSource but applies a timeout policy for each emitted * item, where this policy is governed on a specified Scheduler. If the next item isn't emitted within the * specified timeout duration starting from its predecessor, the resulting ObservableSource terminates and * notifies observers of a {@code TimeoutException}. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param timeout * maximum duration between items before a timeout occurs * @param timeUnit * the unit of time that applies to the {@code timeout} argument * @param scheduler * the Scheduler to run the timeout timers on * @return the source ObservableSource modified to notify observers of a {@code TimeoutException} in case of a * timeout * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable timeout(long timeout, TimeUnit timeUnit, Scheduler scheduler) { return timeout0(timeout, timeUnit, null, scheduler); } /** * Returns an Observable that mirrors the source ObservableSource, but notifies observers of a * {@code TimeoutException} if either the first item emitted by the source ObservableSource or any subsequent item * doesn't arrive within time windows defined by other ObservableSources. *

* *

*
Scheduler:
*
This version of {@code timeout} operates by default on the {@code immediate} {@link Scheduler}.
*
* * @param * the first timeout value type (ignored) * @param * the subsequent timeout value type (ignored) * @param firstTimeoutIndicator * a function that returns an ObservableSource that determines the timeout window for the first source * item * @param itemTimeoutIndicator * a function that returns an ObservableSource for each item emitted by the source ObservableSource and that * determines the timeout window in which the subsequent source item must arrive in order to * continue the sequence * @return an Observable that mirrors the source ObservableSource, but notifies observers of a * {@code TimeoutException} if either the first item or any subsequent item doesn't arrive within * the time windows specified by the timeout selectors * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable timeout(ObservableSource firstTimeoutIndicator, Function> itemTimeoutIndicator) { ObjectHelper.requireNonNull(firstTimeoutIndicator, "firstTimeoutIndicator is null"); return timeout0(firstTimeoutIndicator, itemTimeoutIndicator, null); } /** * Returns an Observable that mirrors the source ObservableSource, but switches to a fallback ObservableSource if either * the first item emitted by the source ObservableSource or any subsequent item doesn't arrive within time windows * defined by other ObservableSources. *

* *

*
Scheduler:
*
This version of {@code timeout} operates by default on the {@code immediate} {@link Scheduler}.
*
* * @param * the first timeout value type (ignored) * @param * the subsequent timeout value type (ignored) * @param firstTimeoutIndicator * a function that returns an ObservableSource which determines the timeout window for the first source * item * @param itemTimeoutIndicator * a function that returns an ObservableSource for each item emitted by the source ObservableSource and that * determines the timeout window in which the subsequent source item must arrive in order to * continue the sequence * @param other * the fallback ObservableSource to switch to if the source ObservableSource times out * @return an Observable that mirrors the source ObservableSource, but switches to the {@code other} ObservableSource if * either the first item emitted by the source ObservableSource or any subsequent item doesn't arrive * within time windows defined by the timeout selectors * @throws NullPointerException * if {@code itemTimeoutIndicator} is null, or * if {@code other} is null * @see ReactiveX operators documentation: Timeout */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable timeout( ObservableSource firstTimeoutIndicator, Function> itemTimeoutIndicator, ObservableSource other) { ObjectHelper.requireNonNull(firstTimeoutIndicator, "firstTimeoutIndicator is null"); ObjectHelper.requireNonNull(other, "other is null"); return timeout0(firstTimeoutIndicator, itemTimeoutIndicator, other); } private Observable timeout0(long timeout, TimeUnit timeUnit, ObservableSource other, Scheduler scheduler) { ObjectHelper.requireNonNull(timeUnit, "timeUnit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new ObservableTimeoutTimed(this, timeout, timeUnit, scheduler, other)); } private Observable timeout0( ObservableSource firstTimeoutIndicator, Function> itemTimeoutIndicator, ObservableSource other) { ObjectHelper.requireNonNull(itemTimeoutIndicator, "itemTimeoutIndicator is null"); return RxJavaPlugins.onAssembly(new ObservableTimeout(this, firstTimeoutIndicator, itemTimeoutIndicator, other)); } /** * Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a * {@link Timed} object. *

* *

*
Scheduler:
*
{@code timestamp} does not operate on any particular scheduler but uses the current time * from the {@code computation} {@link Scheduler}.
*
* * @return an Observable that emits timestamped items from the source ObservableSource * @see ReactiveX operators documentation: Timestamp */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> timestamp() { return timestamp(TimeUnit.MILLISECONDS, Schedulers.computation()); } /** * Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a * {@link Timed} object whose timestamps are provided by a specified Scheduler. *

* *

*
Scheduler:
*
This operator does not operate on any particular scheduler but uses the current time * from the specified {@link Scheduler}.
*
* * @param scheduler * the {@link Scheduler} to use as a time source * @return an Observable that emits timestamped items from the source ObservableSource with timestamps provided by * the {@code scheduler} * @see ReactiveX operators documentation: Timestamp */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) // Supplied scheduler is only used for creating timestamps. public final Observable> timestamp(Scheduler scheduler) { return timestamp(TimeUnit.MILLISECONDS, scheduler); } /** * Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a * {@link Timed} object. *

* *

*
Scheduler:
*
{@code timestamp} does not operate on any particular scheduler but uses the current time * from the {@code computation} {@link Scheduler}.
*
* * @param unit the time unit for the current time * @return an Observable that emits timestamped items from the source ObservableSource * @see ReactiveX operators documentation: Timestamp */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> timestamp(TimeUnit unit) { return timestamp(unit, Schedulers.computation()); } /** * Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a * {@link Timed} object whose timestamps are provided by a specified Scheduler. *

* *

*
Scheduler:
*
This operator does not operate on any particular scheduler but uses the current time * from the specified {@link Scheduler}.
*
* * @param unit the time unit for the current time * @param scheduler * the {@link Scheduler} to use as a time source * @return an Observable that emits timestamped items from the source ObservableSource with timestamps provided by * the {@code scheduler} * @see ReactiveX operators documentation: Timestamp */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) // Supplied scheduler is only used for creating timestamps. public final Observable> timestamp(final TimeUnit unit, final Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return map(Functions.timestampWith(unit, scheduler)); } /** * Calls the specified converter function during assembly time and returns its resulting value. *

* This allows fluent conversion to any other type. *

*
Scheduler:
*
{@code to} does not operate by default on a particular {@link Scheduler}.
*
* @param the resulting object type * @param converter the function that receives the current Observable instance and returns a value * @return the value returned by the function */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final R to(Function, R> converter) { try { return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); throw ExceptionHelper.wrapOrThrow(ex); } } /** * Returns a Single that emits a single item, a list composed of all the items emitted by the * finite source ObservableSource. *

* *

* Normally, an ObservableSource that returns multiple items will do so by invoking its {@link Observer}'s * {@link Observer#onNext onNext} method for each such item. You can change this behavior, instructing the * ObservableSource to compose a list of all of these items and then to invoke the Observer's {@code onNext} * function once, passing it the entire list, by calling the ObservableSource's {@code toList} method prior to * calling its {@link #subscribe} method. *

* Note that this operator requires the upstream to signal {@code onComplete} for 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code toList} does not operate by default on a particular {@link Scheduler}.
*
* * @return a Single that emits a single item: a List containing all of the items emitted by the source * ObservableSource * @see ReactiveX operators documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single> toList() { return toList(16); } /** * Returns a Single that emits a single item, a list composed of all the items emitted by the * finite source ObservableSource. *

* *

* Normally, an ObservableSource that returns multiple items will do so by invoking its {@link Observer}'s * {@link Observer#onNext onNext} method for each such item. You can change this behavior, instructing the * ObservableSource to compose a list of all of these items and then to invoke the Observer's {@code onNext} * function once, passing it the entire list, by calling the ObservableSource's {@code toList} method prior to * calling its {@link #subscribe} method. *

* Note that this operator requires the upstream to signal {@code onComplete} for 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code toList} does not operate by default on a particular {@link Scheduler}.
*
* * @param capacityHint * the number of elements expected from the current Observable * @return a Single that emits a single item: a List containing all of the items emitted by the source * ObservableSource * @see ReactiveX operators documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single> toList(final int capacityHint) { ObjectHelper.verifyPositive(capacityHint, "capacityHint"); return RxJavaPlugins.onAssembly(new ObservableToListSingle>(this, capacityHint)); } /** * Returns a Single that emits a single item, a list composed of all the items emitted by the * finite source ObservableSource. *

* *

* Normally, an ObservableSource that returns multiple items will do so by invoking its {@link Observer}'s * {@link Observer#onNext onNext} method for each such item. You can change this behavior, instructing the * ObservableSource to compose a list of all of these items and then to invoke the Observer's {@code onNext} * function once, passing it the entire list, by calling the ObservableSource's {@code toList} method prior to * calling its {@link #subscribe} method. *

* Note that this operator requires the upstream to signal {@code onComplete} for 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code toList} does not operate by default on a particular {@link Scheduler}.
*
* * @param the subclass of a collection of Ts * @param collectionSupplier * the Callable returning the collection (for each individual Observer) to be filled in * @return a Single that emits a single item: a List containing all of the items emitted by the source * ObservableSource * @see ReactiveX operators documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final > Single toList(Callable collectionSupplier) { ObjectHelper.requireNonNull(collectionSupplier, "collectionSupplier is null"); return RxJavaPlugins.onAssembly(new ObservableToListSingle(this, collectionSupplier)); } /** * Returns a Single that emits a single HashMap containing all items emitted by the * finite source ObservableSource, mapped by the keys returned by a specified * {@code keySelector} function. *

* *

* If more than one source item maps to the same key, the HashMap will contain the latest of those items. *

* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated map 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code toMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the key type of the Map * @param keySelector * the function that extracts the key from a source item to be used in the HashMap * @return a Single that emits a single item: a HashMap containing the mapped items from the source * ObservableSource * @see ReactiveX operators documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single> toMap(final Function keySelector) { ObjectHelper.requireNonNull(keySelector, "keySelector is null"); return collect(HashMapSupplier.asCallable(), Functions.toMapKeySelector(keySelector)); } /** * Returns a Single that emits a single HashMap containing values corresponding to items emitted by the * finite source ObservableSource, mapped by the keys returned by a specified {@code keySelector} function. *

* *

* If more than one source item maps to the same key, the HashMap will contain a single entry that * corresponds to the latest of those items. *

* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated map 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code toMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the key type of the Map * @param the value type of the Map * @param keySelector * the function that extracts the key from a source item to be used in the HashMap * @param valueSelector * the function that extracts the value from a source item to be used in the HashMap * @return a Single that emits a single item: a HashMap containing the mapped items from the source * ObservableSource * @see ReactiveX operators documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single> toMap( final Function keySelector, final Function valueSelector) { ObjectHelper.requireNonNull(keySelector, "keySelector is null"); ObjectHelper.requireNonNull(valueSelector, "valueSelector is null"); return collect(HashMapSupplier.asCallable(), Functions.toMapKeyValueSelector(keySelector, valueSelector)); } /** * Returns a Single that emits a single Map, returned by a specified {@code mapFactory} function, that * contains keys and values extracted from the items emitted by the finite source ObservableSource. *

* *

* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated map 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code toMap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the key type of the Map * @param the value type of the Map * @param keySelector * the function that extracts the key from a source item to be used in the Map * @param valueSelector * the function that extracts the value from the source items to be used as value in the Map * @param mapSupplier * the function that returns a Map instance to be used * @return a Single that emits a single item: a Map that contains the mapped items emitted by the * source ObservableSource * @see ReactiveX operators documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single> toMap( final Function keySelector, final Function valueSelector, Callable> mapSupplier) { ObjectHelper.requireNonNull(keySelector, "keySelector is null"); ObjectHelper.requireNonNull(valueSelector, "valueSelector is null"); ObjectHelper.requireNonNull(mapSupplier, "mapSupplier is null"); return collect(mapSupplier, Functions.toMapKeyValueSelector(keySelector, valueSelector)); } /** * Returns a Single that emits a single HashMap that contains an ArrayList of items emitted by the * finite source ObservableSource keyed by a specified {@code keySelector} function. *

* *

* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated map 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code toMultimap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the key type of the Map * @param keySelector * the function that extracts the key from the source items to be used as key in the HashMap * @return a Single that emits a single item: a HashMap that contains an ArrayList of items mapped from * the source ObservableSource * @see ReactiveX operators documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single>> toMultimap(Function keySelector) { @SuppressWarnings({ "rawtypes", "unchecked" }) Function valueSelector = (Function)Functions.identity(); Callable>> mapSupplier = HashMapSupplier.asCallable(); Function> collectionFactory = ArrayListSupplier.asFunction(); return toMultimap(keySelector, valueSelector, mapSupplier, collectionFactory); } /** * Returns a Single that emits a single HashMap that contains an ArrayList of values extracted by a * specified {@code valueSelector} function from items emitted by the finite source ObservableSource, * keyed by a specified {@code keySelector} function. *

* *

* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated map 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code toMultimap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the key type of the Map * @param the value type of the Map * @param keySelector * the function that extracts a key from the source items to be used as key in the HashMap * @param valueSelector * the function that extracts a value from the source items to be used as value in the HashMap * @return a Single that emits a single item: a HashMap that contains an ArrayList of items mapped from * the source ObservableSource * @see ReactiveX operators documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single>> toMultimap(Function keySelector, Function valueSelector) { Callable>> mapSupplier = HashMapSupplier.asCallable(); Function> collectionFactory = ArrayListSupplier.asFunction(); return toMultimap(keySelector, valueSelector, mapSupplier, collectionFactory); } /** * Returns a Single that emits a single Map, returned by a specified {@code mapFactory} function, that * contains a custom collection of values, extracted by a specified {@code valueSelector} function from * items emitted by the source ObservableSource, and keyed by the {@code keySelector} function. *

* *

*
Scheduler:
*
{@code toMultimap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the key type of the Map * @param the value type of the Map * @param keySelector * the function that extracts a key from the source items to be used as the key in the Map * @param valueSelector * the function that extracts a value from the source items to be used as the value in the Map * @param mapSupplier * the function that returns a Map instance to be used * @param collectionFactory * the function that returns a Collection instance for a particular key to be used in the Map * @return a Single that emits a single item: a Map that contains the collection of mapped items from * the source ObservableSource * @see ReactiveX operators documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single>> toMultimap( final Function keySelector, final Function valueSelector, final Callable>> mapSupplier, final Function> collectionFactory) { ObjectHelper.requireNonNull(keySelector, "keySelector is null"); ObjectHelper.requireNonNull(valueSelector, "valueSelector is null"); ObjectHelper.requireNonNull(mapSupplier, "mapSupplier is null"); ObjectHelper.requireNonNull(collectionFactory, "collectionFactory is null"); return collect(mapSupplier, Functions.toMultimapKeyValueSelector(keySelector, valueSelector, collectionFactory)); } /** * Returns a Single that emits a single Map, returned by a specified {@code mapFactory} function, that * contains an ArrayList of values, extracted by a specified {@code valueSelector} function from items * emitted by the finite source ObservableSource and keyed by the {@code keySelector} function. *

* *

* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated map 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code toMultimap} does not operate by default on a particular {@link Scheduler}.
*
* * @param the key type of the Map * @param the value type of the Map * @param keySelector * the function that extracts a key from the source items to be used as the key in the Map * @param valueSelector * the function that extracts a value from the source items to be used as the value in the Map * @param mapSupplier * the function that returns a Map instance to be used * @return a Single that emits a single item: a Map that contains a list items mapped from the source * ObservableSource * @see ReactiveX operators documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single>> toMultimap( Function keySelector, Function valueSelector, Callable>> mapSupplier ) { return toMultimap(keySelector, valueSelector, mapSupplier, ArrayListSupplier.asFunction()); } /** * Converts the current Observable into a Flowable by applying the specified backpressure strategy. *

* Marble diagrams for the various backpressure strategies are as follows: *

    *
  • {@link BackpressureStrategy#BUFFER} *

    * *

  • *
  • {@link BackpressureStrategy#DROP} *

    * *

  • *
  • {@link BackpressureStrategy#LATEST} *

    * *

  • *
  • {@link BackpressureStrategy#ERROR} *

    * *

  • *
  • {@link BackpressureStrategy#MISSING} *

    * *

  • *
*
*
Backpressure:
*
The operator applies the chosen backpressure strategy of {@link BackpressureStrategy} enum.
*
Scheduler:
*
{@code toFlowable} does not operate by default on a particular {@link Scheduler}.
*
* * @param strategy the backpressure strategy to apply * @return the new Flowable instance */ @BackpressureSupport(BackpressureKind.SPECIAL) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Flowable toFlowable(BackpressureStrategy strategy) { Flowable f = new FlowableFromObservable(this); switch (strategy) { case DROP: return f.onBackpressureDrop(); case LATEST: return f.onBackpressureLatest(); case MISSING: return f; case ERROR: return RxJavaPlugins.onAssembly(new FlowableOnBackpressureError(f)); default: return f.onBackpressureBuffer(); } } /** * Returns a Single that emits a list that contains the items emitted by the finite source ObservableSource, in a * sorted order. Each item emitted by the ObservableSource must implement {@link Comparable} with respect to all * other items in the sequence. * *

If any item emitted by this Observable does not implement {@link Comparable} with respect to * all other items emitted by this Observable, no items will be emitted and the * sequence is terminated with a {@link ClassCastException}. *

* *

* Note that this operator requires the upstream to signal {@code onComplete} for 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code toSortedList} does not operate by default on a particular {@link Scheduler}.
*
* @return a Single that emits a list that contains the items emitted by the source ObservableSource in * sorted order * @see ReactiveX operators documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single> toSortedList() { return toSortedList(Functions.naturalOrder()); } /** * Returns a Single that emits a list that contains the items emitted by the finite source ObservableSource, in a * sorted order based on a specified comparison function. *

* *

* Note that this operator requires the upstream to signal {@code onComplete} for 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code toSortedList} does not operate by default on a particular {@link Scheduler}.
*
* * @param comparator * a function that compares two items emitted by the source ObservableSource and returns an Integer * that indicates their sort order * @return a Single that emits a list that contains the items emitted by the source ObservableSource in * sorted order * @see ReactiveX operators documentation: To */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single> toSortedList(final Comparator comparator) { ObjectHelper.requireNonNull(comparator, "comparator is null"); return toList().map(Functions.listSorter(comparator)); } /** * Returns a Single that emits a list that contains the items emitted by the finite source ObservableSource, in a * sorted order based on a specified comparison function. *

* *

* Note that this operator requires the upstream to signal {@code onComplete} for 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code toSortedList} does not operate by default on a particular {@link Scheduler}.
*
* * @param comparator * a function that compares two items emitted by the source ObservableSource and returns an Integer * that indicates their sort order * @param capacityHint * the initial capacity of the ArrayList used to accumulate items before sorting * @return a Single that emits a list that contains the items emitted by the source ObservableSource in * sorted order * @see ReactiveX operators documentation: To * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single> toSortedList(final Comparator comparator, int capacityHint) { ObjectHelper.requireNonNull(comparator, "comparator is null"); return toList(capacityHint).map(Functions.listSorter(comparator)); } /** * Returns a Single that emits a list that contains the items emitted by the finite source ObservableSource, in a * sorted order. Each item emitted by the ObservableSource must implement {@link Comparable} with respect to all * other items in the sequence. * *

If any item emitted by this Observable does not implement {@link Comparable} with respect to * all other items emitted by this Observable, no items will be emitted and the * sequence is terminated with a {@link ClassCastException}. *

* *

* Note that this operator requires the upstream to signal {@code onComplete} for 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 fatal {@code OutOfMemoryError}. *

*
Scheduler:
*
{@code toSortedList} does not operate by default on a particular {@link Scheduler}.
*
* * @param capacityHint * the initial capacity of the ArrayList used to accumulate items before sorting * @return a Single that emits a list that contains the items emitted by the source ObservableSource in * sorted order * @see ReactiveX operators documentation: To * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single> toSortedList(int capacityHint) { return toSortedList(Functions.naturalOrder(), capacityHint); } /** * Modifies the source ObservableSource so that subscribers will dispose it on a specified * {@link Scheduler}. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param scheduler * the {@link Scheduler} to perform the call to dispose() of the upstream Disposable * @return the source ObservableSource modified so that its dispose() calls happen on the specified * {@link Scheduler} * @see ReactiveX operators documentation: SubscribeOn */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable unsubscribeOn(Scheduler scheduler) { ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new ObservableUnsubscribeOn(this, scheduler)); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping windows, each containing {@code count} items. When the source * ObservableSource completes or encounters an error, the resulting ObservableSource emits the current window and * propagates the notification from the source ObservableSource. *

* *

*
Scheduler:
*
This version of {@code window} does not operate by default on a particular {@link Scheduler}.
*
* * @param count * the maximum size of each window before it should be emitted * @return an Observable that emits connected, non-overlapping windows, each containing at most * {@code count} items from the source ObservableSource * @throws IllegalArgumentException if either count is non-positive * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> window(long count) { return window(count, count, bufferSize()); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits windows every {@code skip} items, each containing no more than {@code count} items. When * the source ObservableSource completes or encounters an error, the resulting ObservableSource emits the current window * and propagates the notification from the source ObservableSource. *

* *

*
Scheduler:
*
This version of {@code window} does not operate by default on a particular {@link Scheduler}.
*
* * @param count * the maximum size of each window before it should be emitted * @param skip * how many items need to be skipped before starting a new window. Note that if {@code skip} and * {@code count} are equal this is the same operation as {@link #window(long)}. * @return an Observable that emits windows every {@code skip} items containing at most {@code count} items * from the source ObservableSource * @throws IllegalArgumentException if either count or skip is non-positive * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> window(long count, long skip) { return window(count, skip, bufferSize()); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits windows every {@code skip} items, each containing no more than {@code count} items. When * the source ObservableSource completes or encounters an error, the resulting ObservableSource emits the current window * and propagates the notification from the source ObservableSource. *

* *

*
Scheduler:
*
This version of {@code window} does not operate by default on a particular {@link Scheduler}.
*
* * @param count * the maximum size of each window before it should be emitted * @param skip * how many items need to be skipped before starting a new window. Note that if {@code skip} and * {@code count} are equal this is the same operation as {@link #window(long)}. * @param bufferSize * the capacity hint for the buffer in the inner windows * @return an Observable that emits windows every {@code skip} items containing at most {@code count} items * from the source ObservableSource * @throws IllegalArgumentException if either count or skip is non-positive * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> window(long count, long skip, int bufferSize) { ObjectHelper.verifyPositive(count, "count"); ObjectHelper.verifyPositive(skip, "skip"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return RxJavaPlugins.onAssembly(new ObservableWindow(this, count, skip, bufferSize)); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource starts a new window periodically, as determined by the {@code timeskip} argument. It emits * each window after a fixed timespan, specified by the {@code timespan} argument. When the source * ObservableSource completes or ObservableSource completes or encounters an error, the resulting ObservableSource emits the * current window and propagates the notification from the source ObservableSource. *

* *

*
Scheduler:
*
This version of {@code window} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param timespan * the period of time each window collects items before it should be emitted * @param timeskip * the period of time after which a new window will be created * @param unit * the unit of time that applies to the {@code timespan} and {@code timeskip} arguments * @return an Observable that emits new windows periodically as a fixed timespan elapses * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable> window(long timespan, long timeskip, TimeUnit unit) { return window(timespan, timeskip, unit, Schedulers.computation(), bufferSize()); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource starts a new window periodically, as determined by the {@code timeskip} argument. It emits * each window after a fixed timespan, specified by the {@code timespan} argument. When the source * ObservableSource completes or ObservableSource completes or encounters an error, the resulting ObservableSource emits the * current window and propagates the notification from the source ObservableSource. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param timespan * the period of time each window collects items before it should be emitted * @param timeskip * the period of time after which a new window will be created * @param unit * the unit of time that applies to the {@code timespan} and {@code timeskip} arguments * @param scheduler * the {@link Scheduler} to use when determining the end and start of a window * @return an Observable that emits new windows periodically as a fixed timespan elapses * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable> window(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler) { return window(timespan, timeskip, unit, scheduler, bufferSize()); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource starts a new window periodically, as determined by the {@code timeskip} argument. It emits * each window after a fixed timespan, specified by the {@code timespan} argument. When the source * ObservableSource completes or ObservableSource completes or encounters an error, the resulting ObservableSource emits the * current window and propagates the notification from the source ObservableSource. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param timespan * the period of time each window collects items before it should be emitted * @param timeskip * the period of time after which a new window will be created * @param unit * the unit of time that applies to the {@code timespan} and {@code timeskip} arguments * @param scheduler * the {@link Scheduler} to use when determining the end and start of a window * @param bufferSize * the capacity hint for the buffer in the inner windows * @return an Observable that emits new windows periodically as a fixed timespan elapses * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable> window(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler, int bufferSize) { ObjectHelper.verifyPositive(timespan, "timespan"); ObjectHelper.verifyPositive(timeskip, "timeskip"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); ObjectHelper.requireNonNull(unit, "unit is null"); return RxJavaPlugins.onAssembly(new ObservableWindowTimed(this, timespan, timeskip, unit, scheduler, Long.MAX_VALUE, bufferSize, false)); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping windows, each of a fixed duration specified by the * {@code timespan} argument. When the source ObservableSource completes or encounters an error, the resulting * ObservableSource emits the current window and propagates the notification from the source ObservableSource. *

* *

*
Scheduler:
*
This version of {@code window} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param timespan * the period of time each window collects items before it should be emitted and replaced with a * new window * @param unit * the unit of time that applies to the {@code timespan} argument * @return an Observable that emits connected, non-overlapping windows representing items emitted by the * source ObservableSource during fixed, consecutive durations * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable> window(long timespan, TimeUnit unit) { return window(timespan, unit, Schedulers.computation(), Long.MAX_VALUE, false); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping windows, each of a fixed duration as specified by the * {@code timespan} argument or a maximum size as specified by the {@code count} argument (whichever is * reached first). When the source ObservableSource completes or encounters an error, the resulting ObservableSource * emits the current window and propagates the notification from the source ObservableSource. *

* *

*
Scheduler:
*
This version of {@code window} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param timespan * the period of time each window collects items before it should be emitted and replaced with a * new window * @param unit * the unit of time that applies to the {@code timespan} argument * @param count * the maximum size of each window before it should be emitted * @return an Observable that emits connected, non-overlapping windows of items from the source ObservableSource * that were emitted during a fixed duration of time or when the window has reached maximum capacity * (whichever occurs first) * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable> window(long timespan, TimeUnit unit, long count) { return window(timespan, unit, Schedulers.computation(), count, false); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping windows, each of a fixed duration as specified by the * {@code timespan} argument or a maximum size as specified by the {@code count} argument (whichever is * reached first). When the source ObservableSource completes or encounters an error, the resulting ObservableSource * emits the current window and propagates the notification from the source ObservableSource. *

* *

*
Scheduler:
*
This version of {@code window} operates by default on the {@code computation} {@link Scheduler}.
*
* * @param timespan * the period of time each window collects items before it should be emitted and replaced with a * new window * @param unit * the unit of time that applies to the {@code timespan} argument * @param count * the maximum size of each window before it should be emitted * @param restart * if true, when a window reaches the capacity limit, the timer is restarted as well * @return an Observable that emits connected, non-overlapping windows of items from the source ObservableSource * that were emitted during a fixed duration of time or when the window has reached maximum capacity * (whichever occurs first) * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final Observable> window(long timespan, TimeUnit unit, long count, boolean restart) { return window(timespan, unit, Schedulers.computation(), count, restart); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping windows, each of a fixed duration as specified by the * {@code timespan} argument. When the source ObservableSource completes or encounters an error, the resulting * ObservableSource emits the current window and propagates the notification from the source ObservableSource. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param timespan * the period of time each window collects items before it should be emitted and replaced with a * new window * @param unit * the unit of time which applies to the {@code timespan} argument * @param scheduler * the {@link Scheduler} to use when determining the end and start of a window * @return an Observable that emits connected, non-overlapping windows containing items emitted by the * source ObservableSource within a fixed duration * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable> window(long timespan, TimeUnit unit, Scheduler scheduler) { return window(timespan, unit, scheduler, Long.MAX_VALUE, false); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping windows, each of a fixed duration specified by the * {@code timespan} argument or a maximum size specified by the {@code count} argument (whichever is reached * first). When the source ObservableSource completes or encounters an error, the resulting ObservableSource emits the * current window and propagates the notification from the source ObservableSource. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param timespan * the period of time each window collects items before it should be emitted and replaced with a * new window * @param unit * the unit of time which applies to the {@code timespan} argument * @param count * the maximum size of each window before it should be emitted * @param scheduler * the {@link Scheduler} to use when determining the end and start of a window * @return an Observable that emits connected, non-overlapping windows of items from the source ObservableSource * that were emitted during a fixed duration of time or when the window has reached maximum capacity * (whichever occurs first) * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable> window(long timespan, TimeUnit unit, Scheduler scheduler, long count) { return window(timespan, unit, scheduler, count, false); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping windows, each of a fixed duration specified by the * {@code timespan} argument or a maximum size specified by the {@code count} argument (whichever is reached * first). When the source ObservableSource completes or encounters an error, the resulting ObservableSource emits the * current window and propagates the notification from the source ObservableSource. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param timespan * the period of time each window collects items before it should be emitted and replaced with a * new window * @param unit * the unit of time which applies to the {@code timespan} argument * @param count * the maximum size of each window before it should be emitted * @param scheduler * the {@link Scheduler} to use when determining the end and start of a window * @param restart * if true, when a window reaches the capacity limit, the timer is restarted as well * @return an Observable that emits connected, non-overlapping windows of items from the source ObservableSource * that were emitted during a fixed duration of time or when the window has reached maximum capacity * (whichever occurs first) * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable> window(long timespan, TimeUnit unit, Scheduler scheduler, long count, boolean restart) { return window(timespan, unit, scheduler, count, restart, bufferSize()); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping windows, each of a fixed duration specified by the * {@code timespan} argument or a maximum size specified by the {@code count} argument (whichever is reached * first). When the source ObservableSource completes or encounters an error, the resulting ObservableSource emits the * current window and propagates the notification from the source ObservableSource. *

* *

*
Scheduler:
*
You specify which {@link Scheduler} this operator will use.
*
* * @param timespan * the period of time each window collects items before it should be emitted and replaced with a * new window * @param unit * the unit of time which applies to the {@code timespan} argument * @param count * the maximum size of each window before it should be emitted * @param scheduler * the {@link Scheduler} to use when determining the end and start of a window * @param restart * if true, when a window reaches the capacity limit, the timer is restarted as well * @param bufferSize * the capacity hint for the buffer in the inner windows * @return an Observable that emits connected, non-overlapping windows of items from the source ObservableSource * that were emitted during a fixed duration of time or when the window has reached maximum capacity * (whichever occurs first) * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable> window( long timespan, TimeUnit unit, Scheduler scheduler, long count, boolean restart, int bufferSize) { ObjectHelper.verifyPositive(bufferSize, "bufferSize"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.verifyPositive(count, "count"); return RxJavaPlugins.onAssembly(new ObservableWindowTimed(this, timespan, timespan, unit, scheduler, count, bufferSize, restart)); } /** * Returns an Observable that emits non-overlapping windows of items it collects from the source ObservableSource * where the boundary of each window is determined by the items emitted from a specified boundary-governing * ObservableSource. *

* *

*
Scheduler:
*
This version of {@code window} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the window element type (ignored) * @param boundary * an ObservableSource whose emitted items close and open windows * @return an Observable that emits non-overlapping windows of items it collects from the source ObservableSource * where the boundary of each window is determined by the items emitted from the {@code boundary} * ObservableSource * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> window(ObservableSource boundary) { return window(boundary, bufferSize()); } /** * Returns an Observable that emits non-overlapping windows of items it collects from the source ObservableSource * where the boundary of each window is determined by the items emitted from a specified boundary-governing * ObservableSource. *

* *

*
Scheduler:
*
This version of {@code window} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the window element type (ignored) * @param boundary * an ObservableSource whose emitted items close and open windows * @param bufferSize * the capacity hint for the buffer in the inner windows * @return an Observable that emits non-overlapping windows of items it collects from the source ObservableSource * where the boundary of each window is determined by the items emitted from the {@code boundary} * ObservableSource * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> window(ObservableSource boundary, int bufferSize) { ObjectHelper.requireNonNull(boundary, "boundary is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return RxJavaPlugins.onAssembly(new ObservableWindowBoundary(this, boundary, bufferSize)); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits windows that contain those items emitted by the source ObservableSource between the time when * the {@code openingIndicator} ObservableSource emits an item and when the ObservableSource returned by * {@code closingIndicator} emits an item. *

* *

*
Scheduler:
*
This version of {@code window} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the window-opening ObservableSource * @param the element type of the window-closing ObservableSources * @param openingIndicator * an ObservableSource that, when it emits an item, causes another window to be created * @param closingIndicator * a {@link Function} that produces an ObservableSource for every window created. When this ObservableSource * emits an item, the associated window is closed and emitted * @return an Observable that emits windows of items emitted by the source ObservableSource that are governed by * the specified window-governing ObservableSources * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> window( ObservableSource openingIndicator, Function> closingIndicator) { return window(openingIndicator, closingIndicator, bufferSize()); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits windows that contain those items emitted by the source ObservableSource between the time when * the {@code openingIndicator} ObservableSource emits an item and when the ObservableSource returned by * {@code closingIndicator} emits an item. *

* *

*
Scheduler:
*
This version of {@code window} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the window-opening ObservableSource * @param the element type of the window-closing ObservableSources * @param openingIndicator * an ObservableSource that, when it emits an item, causes another window to be created * @param closingIndicator * a {@link Function} that produces an ObservableSource for every window created. When this ObservableSource * emits an item, the associated window is closed and emitted * @param bufferSize * the capacity hint for the buffer in the inner windows * @return an Observable that emits windows of items emitted by the source ObservableSource that are governed by * the specified window-governing ObservableSources * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> window( ObservableSource openingIndicator, Function> closingIndicator, int bufferSize) { ObjectHelper.requireNonNull(openingIndicator, "openingIndicator is null"); ObjectHelper.requireNonNull(closingIndicator, "closingIndicator is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return RxJavaPlugins.onAssembly(new ObservableWindowBoundarySelector(this, openingIndicator, closingIndicator, bufferSize)); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping windows. It emits the current window and opens a new one * whenever the ObservableSource produced by the specified {@code closingIndicator} emits an item. *

* *

*
Scheduler:
*
This version of {@code window} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the boundary ObservableSource * @param boundary * a {@link Callable} that returns an {@code ObservableSource} that governs the boundary between windows. * When the source {@code ObservableSource} emits an item, {@code window} emits the current window and begins * a new one. * @return an Observable that emits connected, non-overlapping windows of items from the source ObservableSource * whenever {@code closingIndicator} emits an item * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> window(Callable> boundary) { return window(boundary, bufferSize()); } /** * Returns an Observable that emits windows of items it collects from the source ObservableSource. The resulting * ObservableSource emits connected, non-overlapping windows. It emits the current window and opens a new one * whenever the ObservableSource produced by the specified {@code closingIndicator} emits an item. *

* *

*
Scheduler:
*
This version of {@code window} does not operate by default on a particular {@link Scheduler}.
*
* * @param the element type of the boundary ObservableSource * @param boundary * a {@link Callable} that returns an {@code ObservableSource} that governs the boundary between windows. * When the source {@code ObservableSource} emits an item, {@code window} emits the current window and begins * a new one. * @param bufferSize * the capacity hint for the buffer in the inner windows * @return an Observable that emits connected, non-overlapping windows of items from the source ObservableSource * whenever {@code closingIndicator} emits an item * @see ReactiveX operators documentation: Window */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable> window(Callable> boundary, int bufferSize) { ObjectHelper.requireNonNull(boundary, "boundary is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return RxJavaPlugins.onAssembly(new ObservableWindowBoundarySupplier(this, boundary, bufferSize)); } /** * Merges the specified ObservableSource into this ObservableSource sequence by using the {@code resultSelector} * function only when the source ObservableSource (this instance) emits an item. *

* * *

*
Scheduler:
*
This operator, by default, doesn't run any particular {@link Scheduler}.
*
* * @param the element type of the other ObservableSource * @param the result type of the combination * @param other * the other ObservableSource * @param combiner * the function to call when this ObservableSource emits an item and the other ObservableSource has already * emitted an item, to generate the item to be emitted by the resulting ObservableSource * @return an Observable that merges the specified ObservableSource into this ObservableSource by using the * {@code resultSelector} function only when the source ObservableSource sequence (this instance) emits an * item * @since 2.0 * @see ReactiveX operators documentation: CombineLatest */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable withLatestFrom(ObservableSource other, BiFunction combiner) { ObjectHelper.requireNonNull(other, "other is null"); ObjectHelper.requireNonNull(combiner, "combiner is null"); return RxJavaPlugins.onAssembly(new ObservableWithLatestFrom(this, combiner, other)); } /** * Combines the value emission from this ObservableSource with the latest emissions from the * other ObservableSources 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 this ObservableSource emits (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. *

* *

*
Scheduler:
*
This operator does not operate by default on a particular {@link Scheduler}.
*
* * @param the first other source's value type * @param the second other source's value type * @param the result value type * @param o1 the first other ObservableSource * @param o2 the second other ObservableSource * @param combiner the function called with an array of values from each participating ObservableSource * @return the new ObservableSource instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable withLatestFrom( ObservableSource o1, ObservableSource o2, Function3 combiner) { ObjectHelper.requireNonNull(o1, "o1 is null"); ObjectHelper.requireNonNull(o2, "o2 is null"); ObjectHelper.requireNonNull(combiner, "combiner is null"); Function f = Functions.toFunction(combiner); return withLatestFrom(new ObservableSource[] { o1, o2 }, f); } /** * Combines the value emission from this ObservableSource with the latest emissions from the * other ObservableSources 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 this ObservableSource emits (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. *

* *

*
Scheduler:
*
This operator does not operate by default on a particular {@link Scheduler}.
*
* * @param the first other source's value type * @param the second other source's value type * @param the third other source's value type * @param the result value type * @param o1 the first other ObservableSource * @param o2 the second other ObservableSource * @param o3 the third other ObservableSource * @param combiner the function called with an array of values from each participating ObservableSource * @return the new ObservableSource instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable withLatestFrom( ObservableSource o1, ObservableSource o2, ObservableSource o3, Function4 combiner) { ObjectHelper.requireNonNull(o1, "o1 is null"); ObjectHelper.requireNonNull(o2, "o2 is null"); ObjectHelper.requireNonNull(o3, "o3 is null"); ObjectHelper.requireNonNull(combiner, "combiner is null"); Function f = Functions.toFunction(combiner); return withLatestFrom(new ObservableSource[] { o1, o2, o3 }, f); } /** * Combines the value emission from this ObservableSource with the latest emissions from the * other ObservableSources 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 this ObservableSource emits (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. *

* *

*
Scheduler:
*
This operator does not operate by default on a particular {@link Scheduler}.
*
* * @param the first other source's value type * @param the second other source's value type * @param the third other source's value type * @param the fourth other source's value type * @param the result value type * @param o1 the first other ObservableSource * @param o2 the second other ObservableSource * @param o3 the third other ObservableSource * @param o4 the fourth other ObservableSource * @param combiner the function called with an array of values from each participating ObservableSource * @return the new ObservableSource instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable withLatestFrom( ObservableSource o1, ObservableSource o2, ObservableSource o3, ObservableSource o4, Function5 combiner) { ObjectHelper.requireNonNull(o1, "o1 is null"); ObjectHelper.requireNonNull(o2, "o2 is null"); ObjectHelper.requireNonNull(o3, "o3 is null"); ObjectHelper.requireNonNull(o4, "o4 is null"); ObjectHelper.requireNonNull(combiner, "combiner is null"); Function f = Functions.toFunction(combiner); return withLatestFrom(new ObservableSource[] { o1, o2, o3, o4 }, f); } /** * Combines the value emission from this ObservableSource with the latest emissions from the * other ObservableSources 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 this ObservableSource emits (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. *

* *

*
Scheduler:
*
This operator does not operate by default on a particular {@link Scheduler}.
*
* * @param the result value type * @param others the array of other sources * @param combiner the function called with an array of values from each participating ObservableSource * @return the new ObservableSource instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable withLatestFrom(ObservableSource[] others, Function combiner) { ObjectHelper.requireNonNull(others, "others is null"); ObjectHelper.requireNonNull(combiner, "combiner is null"); return RxJavaPlugins.onAssembly(new ObservableWithLatestFromMany(this, others, combiner)); } /** * Combines the value emission from this ObservableSource with the latest emissions from the * other ObservableSources 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 this ObservableSource emits (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. *

* *

*
Scheduler:
*
This operator does not operate by default on a particular {@link Scheduler}.
*
* * @param the result value type * @param others the iterable of other sources * @param combiner the function called with an array of values from each participating ObservableSource * @return the new ObservableSource instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable withLatestFrom(Iterable> others, Function combiner) { ObjectHelper.requireNonNull(others, "others is null"); ObjectHelper.requireNonNull(combiner, "combiner is null"); return RxJavaPlugins.onAssembly(new ObservableWithLatestFromMany(this, others, combiner)); } /** * Returns an Observable that emits items that are the result of applying a specified function to pairs of * values, one each from the source ObservableSource and a specified Iterable sequence. *

* *

* Note that the {@code other} Iterable is evaluated as items are observed from the source ObservableSource; it is * not pre-consumed. This allows you to zip infinite streams on either side. *

*
Scheduler:
*
{@code zipWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items in the {@code other} Iterable * @param * the type of items emitted by the resulting ObservableSource * @param other * the Iterable sequence * @param zipper * a function that combines the pairs of items from the ObservableSource and the Iterable to generate * the items to be emitted by the resulting ObservableSource * @return an Observable that pairs up values from the source ObservableSource and the {@code other} Iterable * sequence and emits the results of {@code zipFunction} applied to these pairs * @see ReactiveX operators documentation: Zip */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable zipWith(Iterable other, BiFunction zipper) { ObjectHelper.requireNonNull(other, "other is null"); ObjectHelper.requireNonNull(zipper, "zipper is null"); return RxJavaPlugins.onAssembly(new ObservableZipIterable(this, other, zipper)); } /** * Returns an Observable that emits items that are the result of applying a specified function to pairs of * values, one each from the source ObservableSource and another specified ObservableSource. *

* *

* 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} to do cleanup in case of completion * or a dispose() call. *
*
Scheduler:
*
{@code zipWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items emitted by the {@code other} ObservableSource * @param * the type of items emitted by the resulting ObservableSource * @param other * the other ObservableSource * @param zipper * a function that combines the pairs of items from the two ObservableSources to generate the items to * be emitted by the resulting ObservableSource * @return an Observable that pairs up values from the source ObservableSource and the {@code other} ObservableSource * and emits the results of {@code zipFunction} applied to these pairs * @see ReactiveX operators documentation: Zip */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable zipWith(ObservableSource other, BiFunction zipper) { ObjectHelper.requireNonNull(other, "other is null"); return zip(this, other, zipper); } /** * Returns an Observable that emits items that are the result of applying a specified function to pairs of * values, one each from the source ObservableSource and another specified ObservableSource. *

* *

* 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} to do cleanup in case of completion * or a dispose() call. *
*
Scheduler:
*
{@code zipWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items emitted by the {@code other} ObservableSource * @param * the type of items emitted by the resulting ObservableSource * @param other * the other ObservableSource * @param zipper * a function that combines the pairs of items from the two ObservableSources to generate the items to * be emitted by the resulting ObservableSource * @param delayError * if true, errors from the current Observable or the other ObservableSource is delayed until both terminate * @return an Observable that pairs up values from the source ObservableSource and the {@code other} ObservableSource * and emits the results of {@code zipFunction} applied to these pairs * @see ReactiveX operators documentation: Zip * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable zipWith(ObservableSource other, BiFunction zipper, boolean delayError) { return zip(this, other, zipper, delayError); } /** * Returns an Observable that emits items that are the result of applying a specified function to pairs of * values, one each from the source ObservableSource and another specified ObservableSource. *

* *

* 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 * {@code 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)
* {@code action1} will be called but {@code action2} won't. *
To work around this termination property, * use {@link #doOnDispose(Action)} as well or use {@code using()} to do cleanup in case of completion * or a dispose() call. *
*
Scheduler:
*
{@code zipWith} does not operate by default on a particular {@link Scheduler}.
*
* * @param * the type of items emitted by the {@code other} ObservableSource * @param * the type of items emitted by the resulting ObservableSource * @param other * the other ObservableSource * @param zipper * a function that combines the pairs of items from the two ObservableSources to generate the items to * be emitted by the resulting ObservableSource * @param bufferSize * the capacity hint for the buffer in the inner windows * @param delayError * if true, errors from the current Observable or the other ObservableSource is delayed until both terminate * @return an Observable that pairs up values from the source ObservableSource and the {@code other} ObservableSource * and emits the results of {@code zipFunction} applied to these pairs * @see ReactiveX operators documentation: Zip * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable zipWith(ObservableSource other, BiFunction zipper, boolean delayError, int bufferSize) { return zip(this, other, zipper, delayError, bufferSize); } // ------------------------------------------------------------------------- // Fluent test support, super handy and reduces test preparation boilerplate // ------------------------------------------------------------------------- /** * Creates a TestObserver and subscribes * it to this Observable. *
*
Scheduler:
*
{@code test} does not operate by default on a particular {@link Scheduler}.
*
* @return the new TestObserver instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final TestObserver test() { // NoPMD TestObserver to = new TestObserver(); subscribe(to); return to; } /** * Creates a TestObserver, optionally disposes it and then subscribes * it to this Observable. * *
*
Scheduler:
*
{@code test} does not operate by default on a particular {@link Scheduler}.
*
* @param dispose dispose the TestObserver before it is subscribed to this Observable? * @return the new TestObserver instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final TestObserver test(boolean dispose) { // NoPMD TestObserver to = new TestObserver(); if (dispose) { to.dispose(); } subscribe(to); return to; } }