/**
 * 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.*;

import io.reactivex.annotations.*;
import io.reactivex.disposables.Disposable;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.flowables.*;
import io.reactivex.functions.*;
import io.reactivex.internal.functions.*;
import io.reactivex.internal.fuseable.*;
import io.reactivex.internal.operators.flowable.*;
import io.reactivex.internal.operators.mixed.*;
import io.reactivex.internal.operators.observable.*;
import io.reactivex.internal.schedulers.ImmediateThinScheduler;
import io.reactivex.internal.subscribers.*;
import io.reactivex.internal.util.*;
import io.reactivex.parallel.ParallelFlowable;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.*;
import io.reactivex.subscribers.*;

/**
 * The Flowable class that implements the Reactive-Streams Pattern and offers factory methods,
 * intermediate operators and the ability to consume reactive dataflows.
 *

 * Reactive-Streams operates with {@code Publisher}s which {@code Flowable} extends. Many operators
 * therefore accept general {@code Publisher}s directly and allow direct interoperation with other
 * Reactive-Streams implementations.
 *

 * The Flowable hosts the default buffer size of 128 elements for operators, accessible via {@link #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:
 *

 *
 *

 * For more information see the ReactiveX
 * documentation.
 *
 * @param <T>
 *            the type of the items emitted by the Flowable
 */
public abstract class Flowable<T> implements Publisher<T> {
    /** The default buffer size. */
    static final int BUFFER_SIZE;
    static {
        BUFFER_SIZE = Math.max(1, Integer.getInteger("rx2.buffer-size", 128));
    }

    /**
     * Mirrors the one Publisher in an Iterable of several Publishers that first either emits an item or sends
     * a termination notification.
     *

     *
     *

     *
Backpressure:

     *
The operator itself doesn't interfere with backpressure which is determined by the winning
     *  {@code Publisher}'s backpressure behavior.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element type
     * @param sources
     *            an Iterable of Publishers sources competing to react first. A subscription to each Publisher will
     *            occur in the same order as in this Iterable.
     * @return a Flowable that emits the same sequence as whichever of the source Publishers first
     *         emitted an item or sent a termination notification
     * @see ReactiveX operators documentation: Amb
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> amb(Iterable<? extends Publisher<? extends T>> sources) {
        ObjectHelper.requireNonNull(sources, "sources is null");
        return RxJavaPlugins.onAssembly(new FlowableAmb<T>(null, sources));
    }

    /**
     * Mirrors the one Publisher in an array of several Publishers that first either emits an item or sends
     * a termination notification.
     *

     *
     *

     *
Backpressure:

     *
The operator itself doesn't interfere with backpressure which is determined by the winning
     *  {@code Publisher}'s backpressure behavior.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element type
     * @param sources
     *            an array of Publisher sources competing to react first. A subscription to each Publisher will
     *            occur in the same order as in this Iterable.
     * @return a Flowable that emits the same sequence as whichever of the source Publishers first
     *         emitted an item or sent a termination notification
     * @see ReactiveX operators documentation: Amb
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> ambArray(Publisher<? extends T>... sources) {
        ObjectHelper.requireNonNull(sources, "sources is null");
        int len = sources.length;
        if (len == 0) {
            return empty();
        } else
        if (len == 1) {
            return fromPublisher(sources[0]);
        }
        return RxJavaPlugins.onAssembly(new FlowableAmb<T>(sources, null));
    }

    /**
     * Returns the default internal buffer size used by most async operators.
     *
The value can be overridden via system parameter {@code rx2.buffer-size}
     * before the Flowable class is loaded.
     * @return the default internal buffer size.
     */
    public static int bufferSize() {
        return BUFFER_SIZE;
    }

    /**
     * Combines a collection of source Publishers by emitting an item that aggregates the latest values of each of
     * the source Publishers each time an item is received from any of the source Publishers, 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<Integer[], R>} 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

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

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T>
     *            the common base type of source values
     * @param <R>
     *            the result type
     * @param sources
     *            the collection of source Publishers
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SchedulerSupport(SchedulerSupport.NONE)
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    public static <T, R> Flowable<R> combineLatest(Publisher<? extends T>[] sources, Function<? super Object[], ? extends R> combiner) {
        return combineLatest(sources, combiner, bufferSize());
    }

    /**
     * Combines a collection of source Publishers by emitting an item that aggregates the latest values of each of
     * the source Publishers each time an item is received from any of the source Publishers, 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<Integer[], R>} 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

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

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T>
     *            the common base type of source values
     * @param <R>
     *            the result type
     * @param sources
     *            the collection of source Publishers
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SchedulerSupport(SchedulerSupport.NONE)
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    public static <T, R> Flowable<R> combineLatest(Function<? super Object[], ? extends R> combiner, Publisher<? extends T>... sources) {
        return combineLatest(sources, combiner, bufferSize());
    }

    /**
     * Combines a collection of source Publishers by emitting an item that aggregates the latest values of each of
     * the source Publishers each time an item is received from any of the source Publishers, 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<Integer[], R>} 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

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

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T>
     *            the common base type of source values
     * @param <R>
     *            the result type
     * @param sources
     *            the collection of source Publishers
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @param bufferSize
     *            the internal buffer size and prefetch amount applied to every source Flowable
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SchedulerSupport(SchedulerSupport.NONE)
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    public static <T, R> Flowable<R> combineLatest(Publisher<? extends T>[] sources, Function<? super Object[], ? extends R> combiner, int bufferSize) {
        ObjectHelper.requireNonNull(sources, "sources is null");
        if (sources.length == 0) {
            return empty();
        }
        ObjectHelper.requireNonNull(combiner, "combiner is null");
        ObjectHelper.verifyPositive(bufferSize, "bufferSize");
        return RxJavaPlugins.onAssembly(new FlowableCombineLatest<T, R>(sources, combiner, bufferSize, false));
    }

    /**
     * Combines a collection of source Publishers by emitting an item that aggregates the latest values of each of
     * the source Publishers each time an item is received from any of the source Publishers, 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<Integer[], R>} 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

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

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T>
     *            the common base type of source values
     * @param <R>
     *            the result type
     * @param sources
     *            the collection of source Publishers
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SchedulerSupport(SchedulerSupport.NONE)
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    public static <T, R> Flowable<R> combineLatest(Iterable<? extends Publisher<? extends T>> sources,
            Function<? super Object[], ? extends R> combiner) {
        return combineLatest(sources, combiner, bufferSize());
    }

    /**
     * Combines a collection of source Publishers by emitting an item that aggregates the latest values of each of
     * the source Publishers each time an item is received from any of the source Publishers, 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<Integer[], R>} 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

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

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T>
     *            the common base type of source values
     * @param <R>
     *            the result type
     * @param sources
     *            the collection of source Publishers
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @param bufferSize
     *            the internal buffer size and prefetch amount applied to every source Flowable
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SchedulerSupport(SchedulerSupport.NONE)
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    public static <T, R> Flowable<R> combineLatest(Iterable<? extends Publisher<? extends T>> sources,
            Function<? super Object[], ? extends R> combiner, int bufferSize) {
        ObjectHelper.requireNonNull(sources, "sources is null");
        ObjectHelper.requireNonNull(combiner, "combiner is null");
        ObjectHelper.verifyPositive(bufferSize, "bufferSize");
        return RxJavaPlugins.onAssembly(new FlowableCombineLatest<T, R>(sources, combiner, bufferSize, false));
    }

    /**
     * Combines a collection of source Publishers by emitting an item that aggregates the latest values of each of
     * the source Publishers each time an item is received from any of the source Publishers, 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<Integer[], R>} 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

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

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T>
     *            the common base type of source values
     * @param <R>
     *            the result type
     * @param sources
     *            the collection of source Publishers
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SchedulerSupport(SchedulerSupport.NONE)
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    public static <T, R> Flowable<R> combineLatestDelayError(Publisher<? extends T>[] sources,
            Function<? super Object[], ? extends R> combiner) {
        return combineLatestDelayError(sources, combiner, bufferSize());
    }

    /**
     * Combines a collection of source Publishers by emitting an item that aggregates the latest values of each of
     * the source Publishers each time an item is received from any of the source Publishers, where this
     * aggregation is defined by a specified function and delays any error from the sources until
     * all source Publishers 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<Integer[], R>} 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

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

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T>
     *            the common base type of source values
     * @param <R>
     *            the result type
     * @param sources
     *            the collection of source Publishers
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SchedulerSupport(SchedulerSupport.NONE)
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    public static <T, R> Flowable<R> combineLatestDelayError(Function<? super Object[], ? extends R> combiner,
            Publisher<? extends T>... sources) {
        return combineLatestDelayError(sources, combiner, bufferSize());
    }

    /**
     * Combines a collection of source Publishers by emitting an item that aggregates the latest values of each of
     * the source Publishers each time an item is received from any of the source Publisher, where this
     * aggregation is defined by a specified function and delays any error from the sources until
     * all source Publishers 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<Integer[], R>} 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

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

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T>
     *            the common base type of source values
     * @param <R>
     *            the result type
     * @param sources
     *            the collection of source Publishers
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @param bufferSize
     *            the internal buffer size and prefetch amount applied to every source Publisher
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SchedulerSupport(SchedulerSupport.NONE)
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    public static <T, R> Flowable<R> combineLatestDelayError(Function<? super Object[], ? extends R> combiner,
            int bufferSize, Publisher<? extends T>... sources) {
        return combineLatestDelayError(sources, combiner, bufferSize);
    }

    /**
     * Combines a collection of source Publishers by emitting an item that aggregates the latest values of each of
     * the source Publishers each time an item is received from any of the source Publishers, where this
     * aggregation is defined by a specified function and delays any error from the sources until
     * all source Publishers 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<Integer[], R>} 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

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

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T>
     *            the common base type of source values
     * @param <R>
     *            the result type
     * @param sources
     *            the collection of source Publishers
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @param bufferSize
     *            the internal buffer size and prefetch amount applied to every source Flowable
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SchedulerSupport(SchedulerSupport.NONE)
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    public static <T, R> Flowable<R> combineLatestDelayError(Publisher<? extends T>[] sources,
            Function<? super Object[], ? extends R> combiner, int bufferSize) {
        ObjectHelper.requireNonNull(sources, "sources is null");
        ObjectHelper.requireNonNull(combiner, "combiner is null");
        ObjectHelper.verifyPositive(bufferSize, "bufferSize");
        if (sources.length == 0) {
            return empty();
        }
        return RxJavaPlugins.onAssembly(new FlowableCombineLatest<T, R>(sources, combiner, bufferSize, true));
    }

    /**
     * Combines a collection of source Publishers by emitting an item that aggregates the latest values of each of
     * the source Publishers each time an item is received from any of the source Publishers, where this
     * aggregation is defined by a specified function and delays any error from the sources until
     * all source Publishers 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<Integer[], R>} 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

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

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T>
     *            the common base type of source values
     * @param <R>
     *            the result type
     * @param sources
     *            the collection of source Publishers
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SchedulerSupport(SchedulerSupport.NONE)
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    public static <T, R> Flowable<R> combineLatestDelayError(Iterable<? extends Publisher<? extends T>> sources,
            Function<? super Object[], ? extends R> combiner) {
        return combineLatestDelayError(sources, combiner, bufferSize());
    }

    /**
     * Combines a collection of source Publishers by emitting an item that aggregates the latest values of each of
     * the source Publishers each time an item is received from any of the source Publishers, where this
     * aggregation is defined by a specified function and delays any error from the sources until
     * all source Publishers 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<Integer[], R>} 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

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

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T>
     *            the common base type of source values
     * @param <R>
     *            the result type
     * @param sources
     *            the collection of source Publishers
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @param bufferSize
     *            the internal buffer size and prefetch amount applied to every source Flowable
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SchedulerSupport(SchedulerSupport.NONE)
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    public static <T, R> Flowable<R> combineLatestDelayError(Iterable<? extends Publisher<? extends T>> sources,
            Function<? super Object[], ? extends R> combiner, int bufferSize) {
        ObjectHelper.requireNonNull(sources, "sources is null");
        ObjectHelper.requireNonNull(combiner, "combiner is null");
        ObjectHelper.verifyPositive(bufferSize, "bufferSize");
        return RxJavaPlugins.onAssembly(new FlowableCombineLatest<T, R>(sources, combiner, bufferSize, true));
    }

    /**
     * Combines two source Publishers by emitting an item that aggregates the latest values of each of the
     * source Publishers each time an item is received from either of the source Publishers, 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

     *
     *

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T1> the element type of the first source
     * @param <T2> the element type of the second source
     * @param <R> the combined output type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            the second source Publisher
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, R> Flowable<R> combineLatest(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2,
            BiFunction<? super T1, ? super T2, ? extends R> combiner) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        Function<Object[], R> f = Functions.toFunction(combiner);
        return combineLatest(f, source1, source2);
    }

    /**
     * Combines three source Publishers by emitting an item that aggregates the latest values of each of the
     * source Publishers each time an item is received from any of the source Publishers, 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

     *
     *

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T1> the element type of the first source
     * @param <T2> the element type of the second source
     * @param <T3> the element type of the third source
     * @param <R> the combined output type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            the second source Publisher
     * @param source3
     *            the third source Publisher
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, R> Flowable<R> combineLatest(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2,
            Publisher<? extends T3> source3,
            Function3<? super T1, ? super T2, ? super T3, ? extends R> combiner) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        ObjectHelper.requireNonNull(source3, "source3 is null");
        return combineLatest(Functions.toFunction(combiner), source1, source2, source3);
    }

    /**
     * Combines four source Publishers by emitting an item that aggregates the latest values of each of the
     * source Publishers each time an item is received from any of the source Publishers, 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

     *
     *

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T1> the element type of the first source
     * @param <T2> the element type of the second source
     * @param <T3> the element type of the third source
     * @param <T4> the element type of the fourth source
     * @param <R> the combined output type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            the second source Publisher
     * @param source3
     *            the third source Publisher
     * @param source4
     *            the fourth source Publisher
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, T4, R> Flowable<R> combineLatest(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2,
            Publisher<? extends T3> source3, Publisher<? extends T4> source4,
            Function4<? super T1, ? super T2, ? super T3, ? super T4, ? extends R> combiner) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        ObjectHelper.requireNonNull(source3, "source3 is null");
        ObjectHelper.requireNonNull(source4, "source4 is null");
        return combineLatest(Functions.toFunction(combiner), source1, source2, source3, source4);
    }

    /**
     * Combines five source Publishers by emitting an item that aggregates the latest values of each of the
     * source Publishers each time an item is received from any of the source Publishers, 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

     *
     *

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T1> the element type of the first source
     * @param <T2> the element type of the second source
     * @param <T3> the element type of the third source
     * @param <T4> the element type of the fourth source
     * @param <T5> the element type of the fifth source
     * @param <R> the combined output type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            the second source Publisher
     * @param source3
     *            the third source Publisher
     * @param source4
     *            the fourth source Publisher
     * @param source5
     *            the fifth source Publisher
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, T4, T5, R> Flowable<R> combineLatest(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2,
            Publisher<? extends T3> source3, Publisher<? extends T4> source4,
            Publisher<? extends T5> source5,
            Function5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> combiner) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        ObjectHelper.requireNonNull(source3, "source3 is null");
        ObjectHelper.requireNonNull(source4, "source4 is null");
        ObjectHelper.requireNonNull(source5, "source5 is null");
        return combineLatest(Functions.toFunction(combiner), source1, source2, source3, source4, source5);
    }

    /**
     * Combines six source Publishers by emitting an item that aggregates the latest values of each of the
     * source Publishers each time an item is received from any of the source Publishers, 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

     *
     *

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T1> the element type of the first source
     * @param <T2> the element type of the second source
     * @param <T3> the element type of the third source
     * @param <T4> the element type of the fourth source
     * @param <T5> the element type of the fifth source
     * @param <T6> the element type of the sixth source
     * @param <R> the combined output type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            the second source Publisher
     * @param source3
     *            the third source Publisher
     * @param source4
     *            the fourth source Publisher
     * @param source5
     *            the fifth source Publisher
     * @param source6
     *            the sixth source Publisher
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, T4, T5, T6, R> Flowable<R> combineLatest(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2,
            Publisher<? extends T3> source3, Publisher<? extends T4> source4,
            Publisher<? extends T5> source5, Publisher<? extends T6> source6,
            Function6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> combiner) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        ObjectHelper.requireNonNull(source3, "source3 is null");
        ObjectHelper.requireNonNull(source4, "source4 is null");
        ObjectHelper.requireNonNull(source5, "source5 is null");
        ObjectHelper.requireNonNull(source6, "source6 is null");
        return combineLatest(Functions.toFunction(combiner), source1, source2, source3, source4, source5, source6);
    }

    /**
     * Combines seven source Publishers by emitting an item that aggregates the latest values of each of the
     * source Publishers each time an item is received from any of the source Publishers, 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

     *
     *

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T1> the element type of the first source
     * @param <T2> the element type of the second source
     * @param <T3> the element type of the third source
     * @param <T4> the element type of the fourth source
     * @param <T5> the element type of the fifth source
     * @param <T6> the element type of the sixth source
     * @param <T7> the element type of the seventh source
     * @param <R> the combined output type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            the second source Publisher
     * @param source3
     *            the third source Publisher
     * @param source4
     *            the fourth source Publisher
     * @param source5
     *            the fifth source Publisher
     * @param source6
     *            the sixth source Publisher
     * @param source7
     *            the seventh source Publisher
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, T4, T5, T6, T7, R> Flowable<R> combineLatest(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2,
            Publisher<? extends T3> source3, Publisher<? extends T4> source4,
            Publisher<? extends T5> source5, Publisher<? extends T6> source6,
            Publisher<? extends T7> source7,
            Function7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> combiner) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        ObjectHelper.requireNonNull(source3, "source3 is null");
        ObjectHelper.requireNonNull(source4, "source4 is null");
        ObjectHelper.requireNonNull(source5, "source5 is null");
        ObjectHelper.requireNonNull(source6, "source6 is null");
        ObjectHelper.requireNonNull(source7, "source7 is null");
        return combineLatest(Functions.toFunction(combiner), source1, source2, source3, source4, source5, source6, source7);
    }

    /**
     * Combines eight source Publishers by emitting an item that aggregates the latest values of each of the
     * source Publishers each time an item is received from any of the source Publishers, 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

     *
     *

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T1> the element type of the first source
     * @param <T2> the element type of the second source
     * @param <T3> the element type of the third source
     * @param <T4> the element type of the fourth source
     * @param <T5> the element type of the fifth source
     * @param <T6> the element type of the sixth source
     * @param <T7> the element type of the seventh source
     * @param <T8> the element type of the eighth source
     * @param <R> the combined output type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            the second source Publisher
     * @param source3
     *            the third source Publisher
     * @param source4
     *            the fourth source Publisher
     * @param source5
     *            the fifth source Publisher
     * @param source6
     *            the sixth source Publisher
     * @param source7
     *            the seventh source Publisher
     * @param source8
     *            the eighth source Publisher
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, T4, T5, T6, T7, T8, R> Flowable<R> combineLatest(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2,
            Publisher<? extends T3> source3, Publisher<? extends T4> source4,
            Publisher<? extends T5> source5, Publisher<? extends T6> source6,
            Publisher<? extends T7> source7, Publisher<? extends T8> source8,
            Function8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> combiner) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        ObjectHelper.requireNonNull(source3, "source3 is null");
        ObjectHelper.requireNonNull(source4, "source4 is null");
        ObjectHelper.requireNonNull(source5, "source5 is null");
        ObjectHelper.requireNonNull(source6, "source6 is null");
        ObjectHelper.requireNonNull(source7, "source7 is null");
        ObjectHelper.requireNonNull(source8, "source8 is null");
        return combineLatest(Functions.toFunction(combiner), source1, source2, source3, source4, source5, source6, source7, source8);
    }

    /**
     * Combines nine source Publishers by emitting an item that aggregates the latest values of each of the
     * source Publishers each time an item is received from any of the source Publishers, 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 until that point).
     * If that input source is also synchronous, other sources after it will not be subscribed to.
     *

     *
     *

     *
Backpressure:

     *
The returned {@code Publisher} honors backpressure from downstream. The source {@code Publisher}s
     *   are requested in a bounded manner, however, their backpressure is not enforced (the operator won't signal
     *   {@code MissingBackpressureException}) and may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T1> the element type of the first source
     * @param <T2> the element type of the second source
     * @param <T3> the element type of the third source
     * @param <T4> the element type of the fourth source
     * @param <T5> the element type of the fifth source
     * @param <T6> the element type of the sixth source
     * @param <T7> the element type of the seventh source
     * @param <T8> the element type of the eighth source
     * @param <T9> the element type of the ninth source
     * @param <R> the combined output type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            the second source Publisher
     * @param source3
     *            the third source Publisher
     * @param source4
     *            the fourth source Publisher
     * @param source5
     *            the fifth source Publisher
     * @param source6
     *            the sixth source Publisher
     * @param source7
     *            the seventh source Publisher
     * @param source8
     *            the eighth source Publisher
     * @param source9
     *            the ninth source Publisher
     * @param combiner
     *            the aggregation function used to combine the items emitted by the source Publishers
     * @return a Flowable that emits items that are the result of combining the items emitted by the source
     *         Publishers by means of the given aggregation function
     * @see ReactiveX operators documentation: CombineLatest
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Flowable<R> combineLatest(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2,
            Publisher<? extends T3> source3, Publisher<? extends T4> source4,
            Publisher<? extends T5> source5, Publisher<? extends T6> source6,
            Publisher<? extends T7> source7, Publisher<? extends T8> source8,
            Publisher<? extends T9> source9,
            Function9<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9, ? extends R> combiner) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        ObjectHelper.requireNonNull(source3, "source3 is null");
        ObjectHelper.requireNonNull(source4, "source4 is null");
        ObjectHelper.requireNonNull(source5, "source5 is null");
        ObjectHelper.requireNonNull(source6, "source6 is null");
        ObjectHelper.requireNonNull(source7, "source7 is null");
        ObjectHelper.requireNonNull(source8, "source8 is null");
        ObjectHelper.requireNonNull(source9, "source9 is null");
        return combineLatest(Functions.toFunction(combiner), source1, source2, source3, source4, source5, source6, source7, source8, source9);
    }

    /**
     * Concatenates elements of each Publisher provided via an Iterable sequence into a single sequence
     * of elements without interleaving them.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. The {@code Publisher}
     *  sources are expected to honor backpressure as well.
     *  If any of the source {@code Publisher}s violate this, it may throw an
     *  {@code IllegalStateException} when the source {@code Publisher} completes.

     *
Scheduler:

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

     *

     * @param <T> the common value type of the sources
     * @param sources the Iterable sequence of Publishers
     * @return the new Flowable instance
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concat(Iterable<? extends Publisher<? extends T>> sources) {
        ObjectHelper.requireNonNull(sources, "sources is null");
        // unlike general sources, fromIterable can only throw on a boundary because it is consumed only there
        return fromIterable(sources).concatMapDelayError((Function)Functions.identity(), 2, false);
    }

    /**
     * Returns a Flowable that emits the items emitted by each of the Publishers emitted by the source
     * Publisher, one after the other, without interleaving them.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. Both the outer and inner {@code Publisher}
     *  sources are expected to honor backpressure as well. If the outer violates this, a
     *  {@code MissingBackpressureException} is signaled. If any of the inner {@code Publisher}s violates
     *  this, it may throw an {@code IllegalStateException} when an inner {@code Publisher} completes.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            a Publisher that emits Publishers
     * @return a Flowable that emits items all of the items emitted by the Publishers emitted by
     *         {@code Publishers}, one after the other, without interleaving them
     * @see ReactiveX operators documentation: Concat
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concat(Publisher<? extends Publisher<? extends T>> sources) {
        return concat(sources, bufferSize());
    }

    /**
     * Returns a Flowable that emits the items emitted by each of the Publishers emitted by the source
     * Publisher, one after the other, without interleaving them.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. Both the outer and inner {@code Publisher}
     *  sources are expected to honor backpressure as well. If the outer violates this, a
     *  {@code MissingBackpressureException} is signaled. If any of the inner {@code Publisher}s violates
     *  this, it may throw an {@code IllegalStateException} when an inner {@code Publisher} completes.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            a Publisher that emits Publishers
     * @param prefetch
     *            the number of Publishers to prefetch from the sources sequence.
     * @return a Flowable that emits items all of the items emitted by the Publishers emitted by
     *         {@code Publishers}, one after the other, without interleaving them
     * @see ReactiveX operators documentation: Concat
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concat(Publisher<? extends Publisher<? extends T>> sources, int prefetch) {
        return fromPublisher(sources).concatMap((Function)Functions.identity(), prefetch);
    }

    /**
     * Returns a Flowable that emits the items emitted by two Publishers, one after the other, without
     * interleaving them.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. The {@code Publisher}
     *  sources are expected to honor backpressure as well.
     *  If any of the source {@code Publisher}s violate this, it may throw an
     *  {@code IllegalStateException} when the source {@code Publisher} completes.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param source1
     *            a Publisher to be concatenated
     * @param source2
     *            a Publisher to be concatenated
     * @return a Flowable that emits items emitted by the two source Publishers, one after the other,
     *         without interleaving them
     * @see ReactiveX operators documentation: Concat
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concat(Publisher<? extends T> source1, Publisher<? extends T> source2) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        return concatArray(source1, source2);
    }

    /**
     * Returns a Flowable that emits the items emitted by three Publishers, one after the other, without
     * interleaving them.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. The {@code Publisher}
     *  sources are expected to honor backpressure as well.
     *  If any of the source {@code Publisher}s violate this, it may throw an
     *  {@code IllegalStateException} when the source {@code Publisher} completes.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param source1
     *            a Publisher to be concatenated
     * @param source2
     *            a Publisher to be concatenated
     * @param source3
     *            a Publisher to be concatenated
     * @return a Flowable that emits items emitted by the three source Publishers, one after the other,
     *         without interleaving them
     * @see ReactiveX operators documentation: Concat
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concat(
            Publisher<? extends T> source1, Publisher<? extends T> source2,
            Publisher<? extends T> source3) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        ObjectHelper.requireNonNull(source3, "source3 is null");
        return concatArray(source1, source2, source3);
    }

    /**
     * Returns a Flowable that emits the items emitted by four Publishers, one after the other, without
     * interleaving them.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. The {@code Publisher}
     *  sources are expected to honor backpressure as well.
     *  If any of the source {@code Publisher}s violate this, it may throw an
     *  {@code IllegalStateException} when the source {@code Publisher} completes.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param source1
     *            a Publisher to be concatenated
     * @param source2
     *            a Publisher to be concatenated
     * @param source3
     *            a Publisher to be concatenated
     * @param source4
     *            a Publisher to be concatenated
     * @return a Flowable that emits items emitted by the four source Publishers, one after the other,
     *         without interleaving them
     * @see ReactiveX operators documentation: Concat
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concat(
            Publisher<? extends T> source1, Publisher<? extends T> source2,
            Publisher<? extends T> source3, Publisher<? extends T> source4) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        ObjectHelper.requireNonNull(source3, "source3 is null");
        ObjectHelper.requireNonNull(source4, "source4 is null");
        return concatArray(source1, source2, source3, source4);
    }

    /**
     * Concatenates a variable number of Publisher sources.
     *

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

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. The {@code Publisher}
     *  sources are expected to honor backpressure as well.
     *  If any of the source {@code Publisher}s violate this, it may throw an
     *  {@code IllegalStateException} when the source {@code Publisher} completes.

     *
Scheduler:

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

     *

     * @param sources the array of sources
     * @param <T> the common base value type
     * @return the new Publisher instance
     * @throws NullPointerException if sources is null
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concatArray(Publisher<? extends T>... sources) {
        if (sources.length == 0) {
            return empty();
        } else
        if (sources.length == 1) {
            return fromPublisher(sources[0]);
        }
        return RxJavaPlugins.onAssembly(new FlowableConcatArray<T>(sources, false));
    }

    /**
     * Concatenates a variable number of Publisher sources and delays errors from any of them
     * till all terminate.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. The {@code Publisher}
     *  sources are expected to honor backpressure as well.
     *  If any of the source {@code Publisher}s violate this, it may throw an
     *  {@code IllegalStateException} when the source {@code Publisher} completes.

     *
Scheduler:

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

     *

     * @param sources the array of sources
     * @param <T> the common base value type
     * @return the new Flowable instance
     * @throws NullPointerException if sources is null
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concatArrayDelayError(Publisher<? extends T>... sources) {
        if (sources.length == 0) {
            return empty();
        } else
        if (sources.length == 1) {
            return fromPublisher(sources[0]);
        }
        return RxJavaPlugins.onAssembly(new FlowableConcatArray<T>(sources, true));
    }

    /**
     * Concatenates an array of Publishers eagerly into a single stream of values.
     *

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The {@code Publisher}
     *  sources are expected to honor backpressure as well.
     *  If any of the source {@code Publisher}s violate this, the operator will signal a
     *  {@code MissingBackpressureException}.

     *
Scheduler:

     *
This method does not operate by default on a particular {@link Scheduler}.

     *

     * @param <T> the value type
     * @param sources an array of Publishers that need to be eagerly concatenated
     * @return the new Publisher instance with the specified concatenation behavior
     * @since 2.0
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concatArrayEager(Publisher<? extends T>... sources) {
        return concatArrayEager(bufferSize(), bufferSize(), sources);
    }

    /**
     * Concatenates an array of Publishers eagerly into a single stream of values.
     *

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The {@code Publisher}
     *  sources are expected to honor backpressure as well.
     *  If any of the source {@code Publisher}s violate this, the operator will signal a
     *  {@code MissingBackpressureException}.

     *
Scheduler:

     *
This method does not operate by default on a particular {@link Scheduler}.

     *

     * @param <T> the value type
     * @param sources an array of Publishers that need to be eagerly concatenated
     * @param maxConcurrency the maximum number of concurrent subscriptions at a time, Integer.MAX_VALUE
     *                       is interpreted as an indication to subscribe to all sources at once
     * @param prefetch the number of elements to prefetch from each Publisher source
     * @return the new Publisher instance with the specified concatenation behavior
     * @since 2.0
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static <T> Flowable<T> concatArrayEager(int maxConcurrency, int prefetch, Publisher<? extends T>... sources) {
        ObjectHelper.requireNonNull(sources, "sources is null");
        ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency");
        ObjectHelper.verifyPositive(prefetch, "prefetch");
        return RxJavaPlugins.onAssembly(new FlowableConcatMapEager(new FlowableFromArray(sources), Functions.identity(), maxConcurrency, prefetch, ErrorMode.IMMEDIATE));
    }

    /**
     * Concatenates an array of {@link Publisher}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 Publisher}s. The operator buffers the values emitted by these {@code Publisher}s
     * and then drains them in order, each one after the previous one completes.
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. The {@code Publisher}
     *  sources are expected to honor backpressure as well.
     *  If any of the source {@code Publisher}s violate this, the operator will signal a
     *  {@code MissingBackpressureException}.

     *
Scheduler:

     *
This method does not operate by default on a particular {@link Scheduler}.

     *

     * @param <T> the value type
     * @param sources an array of {@code Publisher}s that need to be eagerly concatenated
     * @return the new Flowable instance with the specified concatenation behavior
     * @since 2.2.1 - experimental
     */
    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    @BackpressureSupport(BackpressureKind.FULL)
    public static <T> Flowable<T> concatArrayEagerDelayError(Publisher<? extends T>... sources) {
        return concatArrayEagerDelayError(bufferSize(), bufferSize(), sources);
    }

    /**
     * Concatenates an array of {@link Publisher}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 Publisher}s. The operator buffers the values emitted by these {@code Publisher}s
     * and then drains them in order, each one after the previous one completes.
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. The {@code Publisher}
     *  sources are expected to honor backpressure as well.
     *  If any of the source {@code Publisher}s violate this, the operator will signal a
     *  {@code MissingBackpressureException}.

     *
Scheduler:

     *
This method does not operate by default on a particular {@link Scheduler}.

     *

     * @param <T> the value type
     * @param sources an array of {@code Publisher}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 Publisher} source
     * @return the new Flowable instance with the specified concatenation behavior
     * @since 2.2.1 - experimental
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    @BackpressureSupport(BackpressureKind.FULL)
    public static <T> Flowable<T> concatArrayEagerDelayError(int maxConcurrency, int prefetch, Publisher<? extends T>... sources) {
        return fromArray(sources).concatMapEagerDelayError((Function)Functions.identity(), maxConcurrency, prefetch, true);
    }

    /**
     * Concatenates the Iterable sequence of Publishers into a single sequence by subscribing to each Publisher,
     * one after the other, one at a time and delays any errors till the all inner Publishers terminate.
     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. Both the outer and inner {@code Publisher}
     *  sources are expected to honor backpressure as well. If the outer violates this, a
     *  {@code MissingBackpressureException} is signaled. If any of the inner {@code Publisher}s violates
     *  this, it may throw an {@code IllegalStateException} when an inner {@code Publisher} completes.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param sources the Iterable sequence of Publishers
     * @return the new Publisher with the concatenating behavior
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concatDelayError(Iterable<? extends Publisher<? extends T>> sources) {
        ObjectHelper.requireNonNull(sources, "sources is null");
        return fromIterable(sources).concatMapDelayError((Function)Functions.identity());
    }

    /**
     * Concatenates the Publisher sequence of Publishers into a single sequence by subscribing to each inner Publisher,
     * one after the other, one at a time and delays any errors till the all inner and the outer Publishers terminate.
     *
     *

     *
Backpressure:

     *
{@code concatDelayError} fully supports backpressure.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param sources the Publisher sequence of Publishers
     * @return the new Publisher with the concatenating behavior
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concatDelayError(Publisher<? extends Publisher<? extends T>> sources) {
        return concatDelayError(sources, bufferSize(), true);
    }

    /**
     * Concatenates the Publisher sequence of Publishers into a single sequence by subscribing to each inner Publisher,
     * one after the other, one at a time and delays any errors till the all inner and the outer Publishers terminate.
     *
     *

     *
Backpressure:

     *
{@code concatDelayError} fully supports backpressure.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param sources the Publisher sequence of Publishers
     * @param prefetch the number of elements to prefetch from the outer Publisher
     * @param tillTheEnd if true exceptions from the outer and all inner Publishers are delayed to the end
     *                   if false, exception from the outer Publisher is delayed till the current Publisher terminates
     * @return the new Publisher with the concatenating behavior
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concatDelayError(Publisher<? extends Publisher<? extends T>> sources, int prefetch, boolean tillTheEnd) {
        return fromPublisher(sources).concatMapDelayError((Function)Functions.identity(), prefetch, tillTheEnd);
    }

    /**
     * Concatenates a Publisher sequence of Publishers eagerly into a single stream of values.
     *

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

     *
Backpressure:

     *
Backpressure is honored towards the downstream and both the outer and inner Publishers are
     *  expected to support backpressure. Violating this assumption, the operator will
     *  signal {@code MissingBackpressureException}.

     *
Scheduler:

     *
This method does not operate by default on a particular {@link Scheduler}.

     *

     * @param <T> the value type
     * @param sources a sequence of Publishers that need to be eagerly concatenated
     * @return the new Publisher instance with the specified concatenation behavior
     * @since 2.0
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concatEager(Publisher<? extends Publisher<? extends T>> sources) {
        return concatEager(sources, bufferSize(), bufferSize());
    }

    /**
     * Concatenates a Publisher sequence of Publishers eagerly into a single stream of values.
     *

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

     *
Backpressure:

     *
Backpressure is honored towards the downstream and both the outer and inner Publishers are
     *  expected to support backpressure. Violating this assumption, the operator will
     *  signal {@code MissingBackpressureException}.

     *
Scheduler:

     *
This method does not operate by default on a particular {@link Scheduler}.

     *

     * @param <T> the value type
     * @param sources a sequence of Publishers that need to be eagerly concatenated
     * @param maxConcurrency the maximum number of concurrently running inner Publishers; Integer.MAX_VALUE
     *                       is interpreted as all inner Publishers can be active at the same time
     * @param prefetch the number of elements to prefetch from each inner Publisher source
     * @return the new Publisher instance with the specified concatenation behavior
     * @since 2.0
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static <T> Flowable<T> concatEager(Publisher<? extends Publisher<? extends T>> sources, int maxConcurrency, int prefetch) {
        ObjectHelper.requireNonNull(sources, "sources is null");
        ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency");
        ObjectHelper.verifyPositive(prefetch, "prefetch");
        return RxJavaPlugins.onAssembly(new FlowableConcatMapEagerPublisher(sources, Functions.identity(), maxConcurrency, prefetch, ErrorMode.IMMEDIATE));
    }

    /**
     * Concatenates a sequence of Publishers eagerly into a single stream of values.
     *

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

     *
Backpressure:

     *
Backpressure is honored towards the downstream and the inner Publishers are
     *  expected to support backpressure. Violating this assumption, the operator will
     *  signal {@code MissingBackpressureException}.

     *
Scheduler:

     *
This method does not operate by default on a particular {@link Scheduler}.

     *

     * @param <T> the value type
     * @param sources a sequence of Publishers that need to be eagerly concatenated
     * @return the new Publisher instance with the specified concatenation behavior
     * @since 2.0
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> concatEager(Iterable<? extends Publisher<? extends T>> sources) {
        return concatEager(sources, bufferSize(), bufferSize());
    }

    /**
     * Concatenates a sequence of Publishers eagerly into a single stream of values.
     *

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

     *
Backpressure:

     *
Backpressure is honored towards the downstream and both the outer and inner Publishers are
     *  expected to support backpressure. Violating this assumption, the operator will
     *  signal {@code MissingBackpressureException}.

     *
Scheduler:

     *
This method does not operate by default on a particular {@link Scheduler}.

     *

     * @param <T> the value type
     * @param sources a sequence of Publishers that need to be eagerly concatenated
     * @param maxConcurrency the maximum number of concurrently running inner Publishers; Integer.MAX_VALUE
     *                       is interpreted as all inner Publishers can be active at the same time
     * @param prefetch the number of elements to prefetch from each inner Publisher source
     * @return the new Publisher instance with the specified concatenation behavior
     * @since 2.0
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static <T> Flowable<T> concatEager(Iterable<? extends Publisher<? extends T>> sources, int maxConcurrency, int prefetch) {
        ObjectHelper.requireNonNull(sources, "sources is null");
        ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency");
        ObjectHelper.verifyPositive(prefetch, "prefetch");
        return RxJavaPlugins.onAssembly(new FlowableConcatMapEager(new FlowableFromIterable(sources), Functions.identity(), maxConcurrency, prefetch, ErrorMode.IMMEDIATE));
    }

    /**
     * Provides an API (via a cold Flowable) that bridges the reactive world with the callback-style,
     * generally non-backpressured world.
     *

     * Example:
     *

     * Flowable.<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);
     *
     * }, BackpressureStrategy.BUFFER);
     *

     *

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

     *
Backpressure:

     *
The backpressure behavior is determined by the {@code mode} parameter.

     *
Scheduler:

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

     *

     *
     * @param <T> the element type
     * @param source the emitter that is called when a Subscriber subscribes to the returned {@code Flowable}
     * @param mode the backpressure mode to apply if the downstream Subscriber doesn't request (fast) enough
     * @return the new Flowable instance
     * @see FlowableOnSubscribe
     * @see BackpressureStrategy
     * @see Cancellable
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.SPECIAL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> create(FlowableOnSubscribe<T> source, BackpressureStrategy mode) {
        ObjectHelper.requireNonNull(source, "source is null");
        ObjectHelper.requireNonNull(mode, "mode is null");
        return RxJavaPlugins.onAssembly(new FlowableCreate<T>(source, mode));
    }

    /**
     * Returns a Flowable that calls a Publisher factory to create a Publisher for each new Subscriber
     * that subscribes. That is, for each subscriber, the actual Publisher that subscriber observes is
     * determined by the factory function.
     *

     *
     *

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

     *
Backpressure:

     *
The operator itself doesn't interfere with backpressure which is determined by the {@code Publisher}
     *  returned by the {@code supplier}.

     *
Scheduler:

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

     *

     *
     * @param supplier
     *            the Publisher factory function to invoke for each {@link Subscriber} that subscribes to the
     *            resulting Publisher
     * @param <T>
     *            the type of the items emitted by the Publisher
     * @return a Flowable whose {@link Subscriber}s' subscriptions trigger an invocation of the given
     *         Publisher factory function
     * @see ReactiveX operators documentation: Defer
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> defer(Callable<? extends Publisher<? extends T>> supplier) {
        ObjectHelper.requireNonNull(supplier, "supplier is null");
        return RxJavaPlugins.onAssembly(new FlowableDefer<T>(supplier));
    }

    /**
     * Returns a Flowable that emits no items to the {@link Subscriber} and immediately invokes its
     * {@link Subscriber#onComplete onComplete} method.
     *

     *
     *

     *
Backpressure:

     *
This source doesn't produce any elements and effectively ignores downstream backpressure.

     *
Scheduler:

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

     *

     *
     * @param <T>
     *            the type of the items (ostensibly) emitted by the Publisher
     * @return a Flowable that emits no items to the {@link Subscriber} but immediately invokes the
     *         {@link Subscriber}'s {@link Subscriber#onComplete() onComplete} method
     * @see ReactiveX operators documentation: Empty
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    @SuppressWarnings("unchecked")
    public static <T> Flowable<T> empty() {
        return RxJavaPlugins.onAssembly((Flowable<T>) FlowableEmpty.INSTANCE);
    }

    /**
     * Returns a Flowable that invokes a {@link Subscriber}'s {@link Subscriber#onError onError} method when the
     * Subscriber subscribes to it.
     *

     *
     *

     *
Backpressure:

     *
This source doesn't produce any elements and effectively ignores downstream backpressure.

     *
Scheduler:

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

     *

     *
     * @param supplier
     *            a Callable factory to return a Throwable for each individual Subscriber
     * @param <T>
     *            the type of the items (ostensibly) emitted by the Publisher
     * @return a Flowable that invokes the {@link Subscriber}'s {@link Subscriber#onError onError} method when
     *         the Subscriber subscribes to it
     * @see ReactiveX operators documentation: Throw
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> error(Callable<? extends Throwable> supplier) {
        ObjectHelper.requireNonNull(supplier, "supplier is null");
        return RxJavaPlugins.onAssembly(new FlowableError<T>(supplier));
    }

    /**
     * Returns a Flowable that invokes a {@link Subscriber}'s {@link Subscriber#onError onError} method when the
     * Subscriber subscribes to it.
     *

     *
     *

     *
Backpressure:

     *
This source doesn't produce any elements and effectively ignores downstream backpressure.

     *
Scheduler:

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

     *

     *
     * @param throwable
     *            the particular Throwable to pass to {@link Subscriber#onError onError}
     * @param <T>
     *            the type of the items (ostensibly) emitted by the Publisher
     * @return a Flowable that invokes the {@link Subscriber}'s {@link Subscriber#onError onError} method when
     *         the Subscriber subscribes to it
     * @see ReactiveX operators documentation: Throw
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> error(final Throwable throwable) {
        ObjectHelper.requireNonNull(throwable, "throwable is null");
        return error(Functions.justCallable(throwable));
    }

    /**
     * Converts an Array into a Publisher that emits the items in the Array.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and iterates the given {@code array}
     *  on demand (i.e., when requested).

     *
Scheduler:

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

     *

     *
     * @param items
     *            the array of elements
     * @param <T>
     *            the type of items in the Array and the type of items to be emitted by the resulting Publisher
     * @return a Flowable that emits each item in the source Array
     * @see ReactiveX operators documentation: From
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> 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 FlowableFromArray<T>(items));
    }

    /**
     * Returns a Flowable that, when a Subscriber 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 a Subscriber subscribes to the
     * Publisher. That is to say, it makes the function "lazy."
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream.

     *
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 Subscriber#onError(Throwable)},
     *   except when the downstream has canceled this {@code Flowable} 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 a Subscriber subscribes to the Publisher that {@code fromCallable} returns
     * @param <T>
     *         the type of the item emitted by the Publisher
     * @return a Flowable whose {@link Subscriber}s' subscriptions trigger an invocation of the given function
     * @see #defer(Callable)
     * @since 2.0
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> fromCallable(Callable<? extends T> supplier) {
        ObjectHelper.requireNonNull(supplier, "supplier is null");
        return RxJavaPlugins.onAssembly(new FlowableFromCallable<T>(supplier));
    }

    /**
     * Converts a {@link Future} into a Publisher.
     *

     *
     *

     * You can convert any object that supports the {@link Future} interface into a Publisher 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 Publisher is blocking on the thread it gets subscribed on; you cannot cancel it.
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream.

     *
Scheduler:

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

     *

     *
     * @param future
     *            the source {@link Future}
     * @param <T>
     *            the type of object that the {@link Future} returns, and also the type of item to be emitted by
     *            the resulting Publisher
     * @return a Flowable that emits the item from the source {@link Future}
     * @see ReactiveX operators documentation: From
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> fromFuture(Future<? extends T> future) {
        ObjectHelper.requireNonNull(future, "future is null");
        return RxJavaPlugins.onAssembly(new FlowableFromFuture<T>(future, 0L, null));
    }

    /**
     * Converts a {@link Future} into a Publisher, with a timeout on the Future.
     *

     *
     *

     * You can convert any object that supports the {@link Future} interface into a Publisher that emits the
     * return value of the {@link Future#get} method of that object by passing the object into the {@code fromFuture}
     * method.
     *

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

     * Important note: This Publisher is blocking on the thread it gets subscribed on; you cannot cancel it.
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream.

     *
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 <T>
     *            the type of object that the {@link Future} returns, and also the type of item to be emitted by
     *            the resulting Publisher
     * @return a Flowable that emits the item from the source {@link Future}
     * @see ReactiveX operators documentation: From
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> fromFuture(Future<? extends T> future, long timeout, TimeUnit unit) {
        ObjectHelper.requireNonNull(future, "future is null");
        ObjectHelper.requireNonNull(unit, "unit is null");
        return RxJavaPlugins.onAssembly(new FlowableFromFuture<T>(future, timeout, unit));
    }

    /**
     * Converts a {@link Future} into a Publisher, with a timeout on the Future.
     *

     *
     *

     * You can convert any object that supports the {@link Future} interface into a Publisher 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, canceling the Flowable won't cancel the future. If necessary, one can use composition to achieve the
     * cancellation effect: {@code futurePublisher.doOnCancel(() -> future.cancel(true));}.
     *

     * Important note: This Publisher is blocking; you cannot cancel it.
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream.

     *
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 <T>
     *            the type of object that the {@link Future} returns, and also the type of item to be emitted by
     *            the resulting Publisher
     * @return a Flowable that emits the item from the source {@link Future}
     * @see ReactiveX operators documentation: From
     */
    @SuppressWarnings({ "unchecked", "cast" })
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public static <T> Flowable<T> fromFuture(Future<? extends T> future, long timeout, TimeUnit unit, Scheduler scheduler) {
        ObjectHelper.requireNonNull(scheduler, "scheduler is null");
        return fromFuture((Future<T>)future, timeout, unit).subscribeOn(scheduler);
    }

    /**
     * Converts a {@link Future}, operating on a specified {@link Scheduler}, into a Publisher.
     *

     *
     *

     * You can convert any object that supports the {@link Future} interface into a Publisher 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, canceling the Flowable won't cancel the future. If necessary, one can use composition to achieve the
     * cancellation effect: {@code futurePublisher.doOnCancel(() -> future.cancel(true));}.
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream.

     *
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 <T>
     *            the type of object that the {@link Future} returns, and also the type of item to be emitted by
     *            the resulting Publisher
     * @return a Flowable that emits the item from the source {@link Future}
     * @see ReactiveX operators documentation: From
     */
    @SuppressWarnings({ "cast", "unchecked" })
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public static <T> Flowable<T> fromFuture(Future<? extends T> future, Scheduler scheduler) {
        ObjectHelper.requireNonNull(scheduler, "scheduler is null");
        return fromFuture((Future<T>)future).subscribeOn(scheduler);
    }

    /**
     * Converts an {@link Iterable} sequence into a Publisher that emits the items in the sequence.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and iterates the given {@code iterable}
     *  on demand (i.e., when requested).

     *
Scheduler:

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

     *

     *
     * @param source
     *            the source {@link Iterable} sequence
     * @param <T>
     *            the type of items in the {@link Iterable} sequence and the type of items to be emitted by the
     *            resulting Publisher
     * @return a Flowable that emits each item in the source {@link Iterable} sequence
     * @see ReactiveX operators documentation: From
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> fromIterable(Iterable<? extends T> source) {
        ObjectHelper.requireNonNull(source, "source is null");
        return RxJavaPlugins.onAssembly(new FlowableFromIterable<T>(source));
    }

    /**
     * Converts an arbitrary Reactive-Streams Publisher into a Flowable if not already a
     * Flowable.
     *

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

     * If possible, use {@link #create(FlowableOnSubscribe, BackpressureStrategy)} to create a
     * source-like {@code Flowable} 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 operator is a pass-through for backpressure and its behavior is determined by the
     *  backpressure behavior of the wrapped publisher.

     *
Scheduler:

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

     *

     * @param <T> the value type of the flow
     * @param source the Publisher to convert
     * @return the new Flowable instance
     * @throws NullPointerException if the {@code source} {@code Publisher} is null
     * @see #create(FlowableOnSubscribe, BackpressureStrategy)
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    @SuppressWarnings("unchecked")
    public static <T> Flowable<T> fromPublisher(final Publisher<? extends T> source) {
        if (source instanceof Flowable) {
            return RxJavaPlugins.onAssembly((Flowable<T>)source);
        }
        ObjectHelper.requireNonNull(source, "source is null");

        return RxJavaPlugins.onAssembly(new FlowableFromPublisher<T>(source));
    }

    /**
     * Returns a cold, synchronous, stateless and backpressure-aware 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.
     *

     *
Backpressure:

     *
The operator honors downstream backpressure.

     *
Scheduler:

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

     *

     *
     * @param <T> the generated value type
     * @param generator the Consumer called whenever a particular downstream Subscriber has
     * requested a value. The callback then should call {@code onNext}, {@code onError} or
     * {@code onComplete} to signal a value or a terminal event. Signaling multiple {@code onNext}
     * in a call will make the operator signal {@code IllegalStateException}.
     * @return the new Flowable instance
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> generate(final Consumer<Emitter<T>> generator) {
        ObjectHelper.requireNonNull(generator, "generator is null");
        return generate(Functions.nullSupplier(),
                FlowableInternalHelper.<T, Object>simpleGenerator(generator),
                Functions.emptyConsumer());
    }

    /**
     * Returns a cold, synchronous, stateful and backpressure-aware 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.
     *

     *
Backpressure:

     *
The operator honors downstream backpressure.

     *
Scheduler:

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

     *

     *
     * @param <S> the type of the per-Subscriber state
     * @param <T> the generated value type
     * @param initialState the Callable to generate the initial state for each Subscriber
     * @param generator the Consumer called with the current state whenever a particular downstream Subscriber has
     * requested a value. The callback then should call {@code onNext}, {@code onError} or
     * {@code onComplete} to signal a value or a terminal event. Signaling multiple {@code onNext}
     * in a call will make the operator signal {@code IllegalStateException}.
     * @return the new Flowable instance
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T, S> Flowable<T> generate(Callable<S> initialState, final BiConsumer<S, Emitter<T>> generator) {
        ObjectHelper.requireNonNull(generator, "generator is null");
        return generate(initialState, FlowableInternalHelper.<T, S>simpleBiGenerator(generator),
                Functions.emptyConsumer());
    }

    /**
     * Returns a cold, synchronous, stateful and backpressure-aware 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.
     *

     *
Backpressure:

     *
The operator honors downstream backpressure.

     *
Scheduler:

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

     *

     *
     * @param <S> the type of the per-Subscriber state
     * @param <T> the generated value type
     * @param initialState the Callable to generate the initial state for each Subscriber
     * @param generator the Consumer called with the current state whenever a particular downstream Subscriber has
     * requested a value. The callback then should call {@code onNext}, {@code onError} or
     * {@code onComplete} to signal a value or a terminal event. Signaling 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 canceled
     * @return the new Flowable instance
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T, S> Flowable<T> generate(Callable<S> initialState, final BiConsumer<S, Emitter<T>> generator,
            Consumer<? super S> disposeState) {
        ObjectHelper.requireNonNull(generator, "generator is null");
        return generate(initialState, FlowableInternalHelper.<T, S>simpleBiGenerator(generator), disposeState);
    }

    /**
     * Returns a cold, synchronous, stateful and backpressure-aware 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.
     *

     *
Backpressure:

     *
The operator honors downstream backpressure.

     *
Scheduler:

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

     *

     *
     * @param <S> the type of the per-Subscriber state
     * @param <T> the generated value type
     * @param initialState the Callable to generate the initial state for each Subscriber
     * @param generator the Function called with the current state whenever a particular downstream Subscriber 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. Signaling multiple {@code onNext}
     * in a call will make the operator signal {@code IllegalStateException}.
     * @return the new Flowable instance
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T, S> Flowable<T> generate(Callable<S> initialState, BiFunction<S, Emitter<T>, S> generator) {
        return generate(initialState, generator, Functions.emptyConsumer());
    }

    /**
     * Returns a cold, synchronous, stateful and backpressure-aware 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.
     *

     *
Backpressure:

     *
The operator honors downstream backpressure.

     *
Scheduler:

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

     *

     *
     * @param <S> the type of the per-Subscriber state
     * @param <T> the generated value type
     * @param initialState the Callable to generate the initial state for each Subscriber
     * @param generator the Function called with the current state whenever a particular downstream Subscriber 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. Signaling 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 canceled
     * @return the new Flowable instance
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T, S> Flowable<T> generate(Callable<S> initialState, BiFunction<S, Emitter<T>, S> generator, Consumer<? super S> disposeState) {
        ObjectHelper.requireNonNull(initialState, "initialState is null");
        ObjectHelper.requireNonNull(generator, "generator is null");
        ObjectHelper.requireNonNull(disposeState, "disposeState is null");
        return RxJavaPlugins.onAssembly(new FlowableGenerate<T, S>(initialState, generator, disposeState));
    }

    /**
     * Returns a Flowable that emits a {@code 0L} after the {@code initialDelay} and ever-increasing numbers
     * after each {@code period} of time thereafter.
     *

     *
     *

     *
Backpressure:

     *
The operator generates values based on time and ignores downstream backpressure which
     *  may lead to {@code MissingBackpressureException} at some point in the chain.
     *  Consumers should consider applying one of the {@code onBackpressureXXX} operators as well.

     *
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 a Flowable 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
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.COMPUTATION)
    public static Flowable<Long> interval(long initialDelay, long period, TimeUnit unit) {
        return interval(initialDelay, period, unit, Schedulers.computation());
    }

    /**
     * Returns a Flowable 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}.
     *

     *
     *

     *
Backpressure:

     *
The operator generates values based on time and ignores downstream backpressure which
     *  may lead to {@code MissingBackpressureException} at some point in the chain.
     *  Consumers should consider applying one of the {@code onBackpressureXXX} operators as well.

     *
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 a Flowable 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
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public static Flowable<Long> 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 FlowableInterval(Math.max(0L, initialDelay), Math.max(0L, period), unit, scheduler));
    }

    /**
     * Returns a Flowable that emits a sequential number every specified interval of time.
     *

     *
     *

     *
Backpressure:

     *
The operator signals a {@code MissingBackpressureException} if the downstream
     *  is not ready to receive the next value.

     *
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 a Flowable that emits a sequential number each time interval
     * @see ReactiveX operators documentation: Interval
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.COMPUTATION)
    public static Flowable<Long> interval(long period, TimeUnit unit) {
        return interval(period, period, unit, Schedulers.computation());
    }

    /**
     * Returns a Flowable that emits a sequential number every specified interval of time, on a
     * specified Scheduler.
     *

     *
     *

     *
Backpressure:

     *
The operator generates values based on time and ignores downstream backpressure which
     *  may lead to {@code MissingBackpressureException} at some point in the chain.
     *  Consumers should consider applying one of the {@code onBackpressureXXX} operators as well.

     *
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 a Flowable that emits a sequential number each time interval
     * @see ReactiveX operators documentation: Interval
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public static Flowable<Long> 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.
     *

     *
Backpressure:

     *
The operator signals a {@code MissingBackpressureException} if the downstream can't keep up.

     *
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 signaling 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 Flowable instance
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.COMPUTATION)
    public static Flowable<Long> 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.
     *

     *
Backpressure:

     *
The operator signals a {@code MissingBackpressureException} if the downstream can't keep up.

     *
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 signaling 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 Flowable instance
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public static Flowable<Long> intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit, Scheduler scheduler) {
        if (count < 0L) {
            throw new IllegalArgumentException("count >= 0 required but it was " + count);
        }
        if (count == 0L) {
            return Flowable.<Long>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 FlowableIntervalRange(start, end, Math.max(0L, initialDelay), Math.max(0L, period), unit, scheduler));
    }

    /**
     * Returns a Flowable 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 Subscriber}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)}.
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream.

     *
Scheduler:

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

     *

     *
     * @param item
     *            the item to emit
     * @param <T>
     *            the type of that item
     * @return a Flowable 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
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> just(T item) {
        ObjectHelper.requireNonNull(item, "item is null");
        return RxJavaPlugins.onAssembly(new FlowableJust<T>(item));
    }

    /**
     * Converts two items into a Publisher that emits those items.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and signals each value on-demand (i.e., when requested).

     *
Scheduler:

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

     *

     *
     * @param item1
     *            first item
     * @param item2
     *            second item
     * @param <T>
     *            the type of these items
     * @return a Flowable that emits each item
     * @see ReactiveX operators documentation: Just
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> 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 a Publisher that emits those items.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and signals each value on-demand (i.e., when requested).

     *
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 <T>
     *            the type of these items
     * @return a Flowable that emits each item
     * @see ReactiveX operators documentation: Just
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> 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 a Publisher that emits those items.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and signals each value on-demand (i.e., when requested).

     *
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 <T>
     *            the type of these items
     * @return a Flowable that emits each item
     * @see ReactiveX operators documentation: Just
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> 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 a Publisher that emits those items.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and signals each value on-demand (i.e., when requested).

     *
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 <T>
     *            the type of these items
     * @return a Flowable that emits each item
     * @see ReactiveX operators documentation: Just
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> 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 a Publisher that emits those items.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and signals each value on-demand (i.e., when requested).

     *
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 <T>
     *            the type of these items
     * @return a Flowable that emits each item
     * @see ReactiveX operators documentation: Just
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> 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 a Publisher that emits those items.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and signals each value on-demand (i.e., when requested).

     *
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 <T>
     *            the type of these items
     * @return a Flowable that emits each item
     * @see ReactiveX operators documentation: Just
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> 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 a Publisher that emits those items.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and signals each value on-demand (i.e., when requested).

     *
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 <T>
     *            the type of these items
     * @return a Flowable that emits each item
     * @see ReactiveX operators documentation: Just
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> 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 a Publisher that emits those items.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and signals each value on-demand (i.e., when requested).

     *
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 <T>
     *            the type of these items
     * @return a Flowable that emits each item
     * @see ReactiveX operators documentation: Just
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> 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 a Publisher that emits those items.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and signals each value on-demand (i.e., when requested).

     *
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 <T>
     *            the type of these items
     * @return a Flowable that emits each item
     * @see ReactiveX operators documentation: Just
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> 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 Publishers into one Publisher, without any transformation, while limiting the
     * number of concurrent subscriptions to these Publishers.
     *

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *
Error handling:

     *
If any of the source {@code Publisher}s signal a {@code Throwable} via {@code onError}, the resulting
     *  {@code Flowable} terminates with that {@code Throwable} and all other source {@code Publisher}s are canceled.
     *  If more than one {@code Publisher} signals an error, the resulting {@code Flowable} 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 Flowable} has been canceled 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 Publisher}s
     *  have completed or failed with an error.
     *

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            the Iterable of Publishers
     * @param maxConcurrency
     *            the maximum number of Publishers that may be subscribed to concurrently
     * @param bufferSize
     *            the number of items to prefetch from each inner Publisher
     * @return a Flowable that emits items that are the result of flattening the items emitted by the
     *         Publishers in the Iterable
     * @throws IllegalArgumentException
     *             if {@code maxConcurrency} is less than or equal to 0
     * @see ReactiveX operators documentation: Merge
     * @see #mergeDelayError(Iterable, int, int)
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> merge(Iterable<? extends Publisher<? extends T>> sources, int maxConcurrency, int bufferSize) {
        return fromIterable(sources).flatMap((Function)Functions.identity(), false, maxConcurrency, bufferSize);
    }

    /**
     * Flattens an Iterable of Publishers into one Publisher, without any transformation, while limiting the
     * number of concurrent subscriptions to these Publishers.
     *

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *
Error handling:

     *
If any of the source {@code Publisher}s signal a {@code Throwable} via {@code onError}, the resulting
     *  {@code Flowable} terminates with that {@code Throwable} and all other source {@code Publisher}s are canceled.
     *  If more than one {@code Publisher} signals an error, the resulting {@code Flowable} 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 Flowable} has been canceled or terminated with a
     *  (composite) error will be sent to the same global error handler.
     *  Use {@link #mergeArrayDelayError(int, int, Publisher[])} to merge sources and terminate only when all source {@code Publisher}s
     *  have completed or failed with an error.
     *

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            the array of Publishers
     * @param maxConcurrency
     *            the maximum number of Publishers that may be subscribed to concurrently
     * @param bufferSize
     *            the number of items to prefetch from each inner Publisher
     * @return a Flowable that emits items that are the result of flattening the items emitted by the
     *         Publishers in the Iterable
     * @throws IllegalArgumentException
     *             if {@code maxConcurrency} is less than or equal to 0
     * @see ReactiveX operators documentation: Merge
     * @see #mergeArrayDelayError(int, int, Publisher...)
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> mergeArray(int maxConcurrency, int bufferSize, Publisher<? extends T>... sources) {
        return fromArray(sources).flatMap((Function)Functions.identity(), false, maxConcurrency, bufferSize);
    }

    /**
     * Flattens an Iterable of Publishers into one Publisher, without any transformation.
     *

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *
Error handling:

     *
If any of the source {@code Publisher}s signal a {@code Throwable} via {@code onError}, the resulting
     *  {@code Flowable} terminates with that {@code Throwable} and all other source {@code Publisher}s are canceled.
     *  If more than one {@code Publisher} signals an error, the resulting {@code Flowable} 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 Flowable} has been canceled 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 Publisher}s
     *  have completed or failed with an error.
     *

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            the Iterable of Publishers
     * @return a Flowable that emits items that are the result of flattening the items emitted by the
     *         Publishers in the Iterable
     * @see ReactiveX operators documentation: Merge
     * @see #mergeDelayError(Iterable)
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> merge(Iterable<? extends Publisher<? extends T>> sources) {
        return fromIterable(sources).flatMap((Function)Functions.identity());
    }

    /**
     * Flattens an Iterable of Publishers into one Publisher, without any transformation, while limiting the
     * number of concurrent subscriptions to these Publishers.
     *

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *
Error handling:

     *
If any of the source {@code Publisher}s signal a {@code Throwable} via {@code onError}, the resulting
     *  {@code Flowable} terminates with that {@code Throwable} and all other source {@code Publisher}s are canceled.
     *  If more than one {@code Publisher} signals an error, the resulting {@code Flowable} 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 Flowable} has been canceled 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 Publisher}s
     *  have completed or failed with an error.
     *

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            the Iterable of Publishers
     * @param maxConcurrency
     *            the maximum number of Publishers that may be subscribed to concurrently
     * @return a Flowable that emits items that are the result of flattening the items emitted by the
     *         Publishers in the Iterable
     * @throws IllegalArgumentException
     *             if {@code maxConcurrency} is less than or equal to 0
     * @see ReactiveX operators documentation: Merge
     * @see #mergeDelayError(Iterable, int)
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> merge(Iterable<? extends Publisher<? extends T>> sources, int maxConcurrency) {
        return fromIterable(sources).flatMap((Function)Functions.identity(), maxConcurrency);
    }

    /**
     * Flattens a Publisher that emits Publishers into a single Publisher that emits the items emitted by
     * those Publishers, without any transformation.
     *

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The outer {@code Publisher} is consumed
     *  in unbounded mode (i.e., no backpressure is applied to it). The inner {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *
Error handling:

     *
If any of the source {@code Publisher}s signal a {@code Throwable} via {@code onError}, the resulting
     *  {@code Flowable} terminates with that {@code Throwable} and all other source {@code Publisher}s are canceled.
     *  If more than one {@code Publisher} signals an error, the resulting {@code Flowable} 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 Flowable} has been canceled or terminated with a
     *  (composite) error will be sent to the same global error handler.
     *  Use {@link #mergeDelayError(Publisher)} to merge sources and terminate only when all source {@code Publisher}s
     *  have completed or failed with an error.
     *

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            a Publisher that emits Publishers
     * @return a Flowable that emits items that are the result of flattening the Publishers emitted by the
     *         {@code source} Publisher
     * @see ReactiveX operators documentation: Merge
     * @see #mergeDelayError(Publisher)
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> merge(Publisher<? extends Publisher<? extends T>> sources) {
        return merge(sources, bufferSize());
    }

    /**
     * Flattens a Publisher that emits Publishers into a single Publisher that emits the items emitted by
     * those Publishers, without any transformation, while limiting the maximum number of concurrent
     * subscriptions to these Publishers.
     *

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. Both the outer and inner {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *
Error handling:

     *
If any of the source {@code Publisher}s signal a {@code Throwable} via {@code onError}, the resulting
     *  {@code Flowable} terminates with that {@code Throwable} and all other source {@code Publisher}s are canceled.
     *  If more than one {@code Publisher} signals an error, the resulting {@code Flowable} 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 Flowable} has been canceled or terminated with a
     *  (composite) error will be sent to the same global error handler.
     *  Use {@link #mergeDelayError(Publisher, int)} to merge sources and terminate only when all source {@code Publisher}s
     *  have completed or failed with an error.
     *

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            a Publisher that emits Publishers
     * @param maxConcurrency
     *            the maximum number of Publishers that may be subscribed to concurrently
     * @return a Flowable that emits items that are the result of flattening the Publishers emitted by the
     *         {@code source} Publisher
     * @throws IllegalArgumentException
     *             if {@code maxConcurrency} is less than or equal to 0
     * @see ReactiveX operators documentation: Merge
     * @see #mergeDelayError(Publisher, int)
     * @since 1.1.0
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> merge(Publisher<? extends Publisher<? extends T>> sources, int maxConcurrency) {
        return fromPublisher(sources).flatMap((Function)Functions.identity(), maxConcurrency);
    }

    /**
     * Flattens an Array of Publishers into one Publisher, without any transformation.
     *

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *
Error handling:

     *
If any of the source {@code Publisher}s signal a {@code Throwable} via {@code onError}, the resulting
     *  {@code Flowable} terminates with that {@code Throwable} and all other source {@code Publisher}s are canceled.
     *  If more than one {@code Publisher} signals an error, the resulting {@code Flowable} 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 Flowable} has been canceled or terminated with a
     *  (composite) error will be sent to the same global error handler.
     *  Use {@link #mergeArrayDelayError(Publisher...)} to merge sources and terminate only when all source {@code Publisher}s
     *  have completed or failed with an error.
     *

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            the array of Publishers
     * @return a Flowable that emits all of the items emitted by the Publishers in the Array
     * @see ReactiveX operators documentation: Merge
     * @see #mergeArrayDelayError(Publisher...)
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> mergeArray(Publisher<? extends T>... sources) {
        return fromArray(sources).flatMap((Function)Functions.identity(), sources.length);
    }

    /**
     * Flattens two Publishers into a single Publisher, without any transformation.
     *

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *
Error handling:

     *
If any of the source {@code Publisher}s signal a {@code Throwable} via {@code onError}, the resulting
     *  {@code Flowable} terminates with that {@code Throwable} and all other source {@code Publisher}s are canceled.
     *  If more than one {@code Publisher} signals an error, the resulting {@code Flowable} 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 Flowable} has been canceled or terminated with a
     *  (composite) error will be sent to the same global error handler.
     *  Use {@link #mergeDelayError(Publisher, Publisher)} to merge sources and terminate only when all source {@code Publisher}s
     *  have completed or failed with an error.
     *

     *

     *
     * @param <T> the common element base type
     * @param source1
     *            a Publisher to be merged
     * @param source2
     *            a Publisher to be merged
     * @return a Flowable that emits all of the items emitted by the source Publishers
     * @see ReactiveX operators documentation: Merge
     * @see #mergeDelayError(Publisher, Publisher)
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> merge(Publisher<? extends T> source1, Publisher<? extends T> 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 Publishers into a single Publisher, without any transformation.
     *

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *
Error handling:

     *
If any of the source {@code Publisher}s signal a {@code Throwable} via {@code onError}, the resulting
     *  {@code Flowable} terminates with that {@code Throwable} and all other source {@code Publisher}s are canceled.
     *  If more than one {@code Publisher} signals an error, the resulting {@code Flowable} 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 Flowable} has been canceled or terminated with a
     *  (composite) error will be sent to the same global error handler.
     *  Use {@link #mergeDelayError(Publisher, Publisher, Publisher)} to merge sources and terminate only when all source {@code Publisher}s
     *  have completed or failed with an error.
     *

     *

     *
     * @param <T> the common element base type
     * @param source1
     *            a Publisher to be merged
     * @param source2
     *            a Publisher to be merged
     * @param source3
     *            a Publisher to be merged
     * @return a Flowable that emits all of the items emitted by the source Publishers
     * @see ReactiveX operators documentation: Merge
     * @see #mergeDelayError(Publisher, Publisher, Publisher)
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> merge(Publisher<? extends T> source1, Publisher<? extends T> source2, Publisher<? extends T> 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 Publishers into a single Publisher, without any transformation.
     *

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *
Error handling:

     *
If any of the source {@code Publisher}s signal a {@code Throwable} via {@code onError}, the resulting
     *  {@code Flowable} terminates with that {@code Throwable} and all other source {@code Publisher}s are canceled.
     *  If more than one {@code Publisher} signals an error, the resulting {@code Flowable} 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 Flowable} has been canceled or terminated with a
     *  (composite) error will be sent to the same global error handler.
     *  Use {@link #mergeDelayError(Publisher, Publisher, Publisher, Publisher)} to merge sources and terminate only when all source {@code Publisher}s
     *  have completed or failed with an error.
     *

     *

     *
     * @param <T> the common element base type
     * @param source1
     *            a Publisher to be merged
     * @param source2
     *            a Publisher to be merged
     * @param source3
     *            a Publisher to be merged
     * @param source4
     *            a Publisher to be merged
     * @return a Flowable that emits all of the items emitted by the source Publishers
     * @see ReactiveX operators documentation: Merge
     * @see #mergeDelayError(Publisher, Publisher, Publisher, Publisher)
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> merge(
            Publisher<? extends T> source1, Publisher<? extends T> source2,
            Publisher<? extends T> source3, Publisher<? extends T> source4) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        ObjectHelper.requireNonNull(source3, "source3 is null");
        ObjectHelper.requireNonNull(source4, "source4 is null");
        return fromArray(source1, source2, source3, source4).flatMap((Function)Functions.identity(), false, 4);
    }

    /**
     * Flattens an Iterable of Publishers into one Publisher, in a way that allows a Subscriber to receive all
     * successfully emitted items from each of the source Publishers without being interrupted by an error
     * notification from one of them.
     *

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

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. All inner {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            the Iterable of Publishers
     * @return a Flowable that emits items that are the result of flattening the items emitted by the
     *         Publishers in the Iterable
     * @see ReactiveX operators documentation: Merge
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> mergeDelayError(Iterable<? extends Publisher<? extends T>> sources) {
        return fromIterable(sources).flatMap((Function)Functions.identity(), true);
    }

    /**
     * Flattens an Iterable of Publishers into one Publisher, in a way that allows a Subscriber to receive all
     * successfully emitted items from each of the source Publishers without being interrupted by an error
     * notification from one of them, while limiting the number of concurrent subscriptions to these Publishers.
     *

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

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. All inner {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            the Iterable of Publishers
     * @param maxConcurrency
     *            the maximum number of Publishers that may be subscribed to concurrently
     * @param bufferSize
     *            the number of items to prefetch from each inner Publisher
     * @return a Flowable that emits items that are the result of flattening the items emitted by the
     *         Publishers in the Iterable
     * @see ReactiveX operators documentation: Merge
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> mergeDelayError(Iterable<? extends Publisher<? extends T>> sources, int maxConcurrency, int bufferSize) {
        return fromIterable(sources).flatMap((Function)Functions.identity(), true, maxConcurrency, bufferSize);
    }

    /**
     * Flattens an array of Publishers into one Publisher, in a way that allows a Subscriber to receive all
     * successfully emitted items from each of the source Publishers without being interrupted by an error
     * notification from one of them, while limiting the number of concurrent subscriptions to these Publishers.
     *

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

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. All source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            the array of Publishers
     * @param maxConcurrency
     *            the maximum number of Publishers that may be subscribed to concurrently
     * @param bufferSize
     *            the number of items to prefetch from each inner Publisher
     * @return a Flowable that emits items that are the result of flattening the items emitted by the
     *         Publishers in the Iterable
     * @see ReactiveX operators documentation: Merge
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> mergeArrayDelayError(int maxConcurrency, int bufferSize, Publisher<? extends T>... sources) {
        return fromArray(sources).flatMap((Function)Functions.identity(), true, maxConcurrency, bufferSize);
    }

    /**
     * Flattens an Iterable of Publishers into one Publisher, in a way that allows a Subscriber to receive all
     * successfully emitted items from each of the source Publishers without being interrupted by an error
     * notification from one of them, while limiting the number of concurrent subscriptions to these Publishers.
     *

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

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. All inner {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            the Iterable of Publishers
     * @param maxConcurrency
     *            the maximum number of Publishers that may be subscribed to concurrently
     * @return a Flowable that emits items that are the result of flattening the items emitted by the
     *         Publishers in the Iterable
     * @see ReactiveX operators documentation: Merge
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> mergeDelayError(Iterable<? extends Publisher<? extends T>> sources, int maxConcurrency) {
        return fromIterable(sources).flatMap((Function)Functions.identity(), true, maxConcurrency);
    }

    /**
     * Flattens a Publisher that emits Publishers into one Publisher, in a way that allows a Subscriber to
     * receive all successfully emitted items from all of the source Publishers without being interrupted by
     * an error notification from one of them.
     *

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

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The outer {@code Publisher} is consumed
     *  in unbounded mode (i.e., no backpressure is applied to it). The inner {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            a Publisher that emits Publishers
     * @return a Flowable that emits all of the items emitted by the Publishers emitted by the
     *         {@code source} Publisher
     * @see ReactiveX operators documentation: Merge
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> mergeDelayError(Publisher<? extends Publisher<? extends T>> sources) {
        return mergeDelayError(sources, bufferSize());
    }

    /**
     * Flattens a Publisher that emits Publishers into one Publisher, in a way that allows a Subscriber to
     * receive all successfully emitted items from all of the source Publishers without being interrupted by
     * an error notification from one of them, while limiting the
     * number of concurrent subscriptions to these Publishers.
     *

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

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. Both the outer and inner {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            a Publisher that emits Publishers
     * @param maxConcurrency
     *            the maximum number of Publishers that may be subscribed to concurrently
     * @return a Flowable that emits all of the items emitted by the Publishers emitted by the
     *         {@code source} Publisher
     * @see ReactiveX operators documentation: Merge
     * @since 2.0
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> mergeDelayError(Publisher<? extends Publisher<? extends T>> sources, int maxConcurrency) {
        return fromPublisher(sources).flatMap((Function)Functions.identity(), true, maxConcurrency);
    }

    /**
     * Flattens an array of Publishers into one Flowable, in a way that allows a Subscriber to receive all
     * successfully emitted items from each of the source Publishers without being interrupted by an error
     * notification from one of them.
     *

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

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. Both the outer and inner {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param sources
     *            the Iterable of Publishers
     * @return a Flowable that emits items that are the result of flattening the items emitted by the
     *         Publishers in the Iterable
     * @see ReactiveX operators documentation: Merge
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> mergeArrayDelayError(Publisher<? extends T>... sources) {
        return fromArray(sources).flatMap((Function)Functions.identity(), true, sources.length);
    }

    /**
     * Flattens two Publishers into one Publisher, in a way that allows a Subscriber to receive all
     * successfully emitted items from each of the source Publishers without being interrupted by an error
     * notification from one of them.
     *

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

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param source1
     *            a Publisher to be merged
     * @param source2
     *            a Publisher to be merged
     * @return a Flowable that emits all of the items that are emitted by the two source Publishers
     * @see ReactiveX operators documentation: Merge
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> mergeDelayError(Publisher<? extends T> source1, Publisher<? extends T> 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 Publishers into one Publisher, in a way that allows a Subscriber to receive all
     * successfully emitted items from all of the source Publishers without being interrupted by an error
     * notification from one of them.
     *

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

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param source1
     *            a Publisher to be merged
     * @param source2
     *            a Publisher to be merged
     * @param source3
     *            a Publisher to be merged
     * @return a Flowable that emits all of the items that are emitted by the source Publishers
     * @see ReactiveX operators documentation: Merge
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> mergeDelayError(Publisher<? extends T> source1, Publisher<? extends T> source2, Publisher<? extends T> 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 Publishers into one Publisher, in a way that allows a Subscriber to receive all
     * successfully emitted items from all of the source Publishers without being interrupted by an error
     * notification from one of them.
     *

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

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator may signal {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element base type
     * @param source1
     *            a Publisher to be merged
     * @param source2
     *            a Publisher to be merged
     * @param source3
     *            a Publisher to be merged
     * @param source4
     *            a Publisher to be merged
     * @return a Flowable that emits all of the items that are emitted by the source Publishers
     * @see ReactiveX operators documentation: Merge
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> mergeDelayError(
            Publisher<? extends T> source1, Publisher<? extends T> source2,
            Publisher<? extends T> source3, Publisher<? extends T> source4) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        ObjectHelper.requireNonNull(source3, "source3 is null");
        ObjectHelper.requireNonNull(source4, "source4 is null");
        return fromArray(source1, source2, source3, source4).flatMap((Function)Functions.identity(), true, 4);
    }

    /**
     * Returns a Flowable that never sends any items or notifications to a {@link Subscriber}.
     *

     *
     *

     * This Publisher is useful primarily for testing purposes.
     *

     *
Backpressure:

     *
This source doesn't produce any elements and effectively ignores downstream backpressure.

     *
Scheduler:

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

     *

     *
     * @param <T>
     *            the type of items (not) emitted by the Publisher
     * @return a Flowable that never emits any items or sends any notifications to a {@link Subscriber}
     * @see ReactiveX operators documentation: Never
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    @SuppressWarnings("unchecked")
    public static <T> Flowable<T> never() {
        return RxJavaPlugins.onAssembly((Flowable<T>) FlowableNever.INSTANCE);
    }

    /**
     * Returns a Flowable that emits a sequence of Integers within a specified range.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and signals values on-demand (i.e., when requested).

     *
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 a Flowable 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
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static Flowable<Integer> range(int start, int count) {
        if (count < 0) {
            throw new IllegalArgumentException("count >= 0 required but it was " + count);
        } else
        if (count == 0) {
            return empty();
        } else
        if (count == 1) {
            return just(start);
        } else
        if ((long)start + (count - 1) > Integer.MAX_VALUE) {
            throw new IllegalArgumentException("Integer overflow");
        }
        return RxJavaPlugins.onAssembly(new FlowableRange(start, count));
    }

    /**
     * Returns a Flowable that emits a sequence of Longs within a specified range.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and signals values on-demand (i.e., when requested).

     *
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 a Flowable 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
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static Flowable<Long> 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 FlowableRangeLong(start, count));
    }

    /**
     * Returns a Single that emits a Boolean value that indicates whether two Publisher sequences are the
     * same by comparing the items emitted by each Publisher pairwise.
     *

     *
     *

     *
Backpressure:

     *
This operator honors downstream backpressure and expects both of its sources
     *  to honor backpressure as well. If violated, the operator will emit a MissingBackpressureException.

     *
Scheduler:

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

     *

     *
     * @param source1
     *            the first Publisher to compare
     * @param source2
     *            the second Publisher to compare
     * @param <T>
     *            the type of items emitted by each Publisher
     * @return a Flowable that emits a Boolean value that indicates whether the two sequences are the same
     * @see ReactiveX operators documentation: SequenceEqual
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Single<Boolean> sequenceEqual(Publisher<? extends T> source1, Publisher<? extends T> source2) {
        return sequenceEqual(source1, source2, ObjectHelper.equalsPredicate(), bufferSize());
    }

    /**
     * Returns a Single that emits a Boolean value that indicates whether two Publisher sequences are the
     * same by comparing the items emitted by each Publisher pairwise based on the results of a specified
     * equality function.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator signals a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param source1
     *            the first Publisher to compare
     * @param source2
     *            the second Publisher to compare
     * @param isEqual
     *            a function used to compare items emitted by each Publisher
     * @param <T>
     *            the type of items emitted by each Publisher
     * @return a Single that emits a Boolean value that indicates whether the two Publisher sequences
     *         are the same according to the specified function
     * @see ReactiveX operators documentation: SequenceEqual
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Single<Boolean> sequenceEqual(Publisher<? extends T> source1, Publisher<? extends T> source2,
            BiPredicate<? super T, ? super T> isEqual) {
        return sequenceEqual(source1, source2, isEqual, bufferSize());
    }

    /**
     * Returns a Single that emits a Boolean value that indicates whether two Publisher sequences are the
     * same by comparing the items emitted by each Publisher pairwise based on the results of a specified
     * equality function.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s are expected to honor
     *  backpressure; if violated, the operator signals a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param source1
     *            the first Publisher to compare
     * @param source2
     *            the second Publisher to compare
     * @param isEqual
     *            a function used to compare items emitted by each Publisher
     * @param bufferSize
     *            the number of items to prefetch from the first and second source Publisher
     * @param <T>
     *            the type of items emitted by each Publisher
     * @return a Single that emits a Boolean value that indicates whether the two Publisher sequences
     *         are the same according to the specified function
     * @see ReactiveX operators documentation: SequenceEqual
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Single<Boolean> sequenceEqual(Publisher<? extends T> source1, Publisher<? extends T> source2,
            BiPredicate<? super T, ? super T> 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 FlowableSequenceEqualSingle<T>(source1, source2, isEqual, bufferSize));
    }

    /**
     * Returns a Single that emits a Boolean value that indicates whether two Publisher sequences are the
     * same by comparing the items emitted by each Publisher pairwise.
     *

     *
     *

     *
Backpressure:

     *
This operator honors downstream backpressure and expects both of its sources
     *  to honor backpressure as well. If violated, the operator will emit a MissingBackpressureException.

     *
Scheduler:

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

     *

     *
     * @param source1
     *            the first Publisher to compare
     * @param source2
     *            the second Publisher to compare
     * @param bufferSize
     *            the number of items to prefetch from the first and second source Publisher
     * @param <T>
     *            the type of items emitted by each Publisher
     * @return a Single that emits a Boolean value that indicates whether the two sequences are the same
     * @see ReactiveX operators documentation: SequenceEqual
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Single<Boolean> sequenceEqual(Publisher<? extends T> source1, Publisher<? extends T> source2, int bufferSize) {
        return sequenceEqual(source1, source2, ObjectHelper.equalsPredicate(), bufferSize);
    }

    /**
     * Converts a Publisher that emits Publishers into a Publisher that emits the items emitted by the
     * most recently emitted of those Publishers.
     *

     *
     *

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

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The outer {@code Publisher} is consumed in an
     *  unbounded manner (i.e., without backpressure) and the inner {@code Publisher}s are expected to honor
     *  backpressure but it is not enforced; the operator won't signal a {@code MissingBackpressureException}
     *  but the violation may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T> the item type
     * @param sources
     *            the source Publisher that emits Publishers
     * @param bufferSize
     *            the number of items to prefetch from the inner Publishers
     * @return a Flowable that emits the items emitted by the Publisher most recently emitted by the source
     *         Publisher
     * @see ReactiveX operators documentation: Switch
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> switchOnNext(Publisher<? extends Publisher<? extends T>> sources, int bufferSize) {
        return fromPublisher(sources).switchMap((Function)Functions.identity(), bufferSize);
    }

    /**
     * Converts a Publisher that emits Publishers into a Publisher that emits the items emitted by the
     * most recently emitted of those Publishers.
     *

     *
     *

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

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The outer {@code Publisher} is consumed in an
     *  unbounded manner (i.e., without backpressure) and the inner {@code Publisher}s are expected to honor
     *  backpressure but it is not enforced; the operator won't signal a {@code MissingBackpressureException}
     *  but the violation may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T> the item type
     * @param sources
     *            the source Publisher that emits Publishers
     * @return a Flowable that emits the items emitted by the Publisher most recently emitted by the source
     *         Publisher
     * @see ReactiveX operators documentation: Switch
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> switchOnNext(Publisher<? extends Publisher<? extends T>> sources) {
        return fromPublisher(sources).switchMap((Function)Functions.identity());
    }

    /**
     * Converts a Publisher that emits Publishers into a Publisher that emits the items emitted by the
     * most recently emitted of those Publishers and delays any exception until all Publishers terminate.
     *

     *
     *

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

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The outer {@code Publisher} is consumed in an
     *  unbounded manner (i.e., without backpressure) and the inner {@code Publisher}s are expected to honor
     *  backpressure but it is not enforced; the operator won't signal a {@code MissingBackpressureException}
     *  but the violation may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T> the item type
     * @param sources
     *            the source Publisher that emits Publishers
     * @return a Flowable that emits the items emitted by the Publisher most recently emitted by the source
     *         Publisher
     * @see ReactiveX operators documentation: Switch
     * @since 2.0
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> switchOnNextDelayError(Publisher<? extends Publisher<? extends T>> sources) {
        return switchOnNextDelayError(sources, bufferSize());
    }

    /**
     * Converts a Publisher that emits Publishers into a Publisher that emits the items emitted by the
     * most recently emitted of those Publishers and delays any exception until all Publishers terminate.
     *

     *
     *

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

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

     *
Backpressure:

     *
The operator honors backpressure from downstream. The outer {@code Publisher} is consumed in an
     *  unbounded manner (i.e., without backpressure) and the inner {@code Publisher}s are expected to honor
     *  backpressure but it is not enforced; the operator won't signal a {@code MissingBackpressureException}
     *  but the violation may lead to {@code OutOfMemoryError} due to internal buffer bloat.

     *
Scheduler:

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

     *

     *
     * @param <T> the item type
     * @param sources
     *            the source Publisher that emits Publishers
     * @param prefetch
     *            the number of items to prefetch from the inner Publishers
     * @return a Flowable that emits the items emitted by the Publisher most recently emitted by the source
     *         Publisher
     * @see ReactiveX operators documentation: Switch
     * @since 2.0
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> switchOnNextDelayError(Publisher<? extends Publisher<? extends T>> sources, int prefetch) {
        return fromPublisher(sources).switchMapDelayError(Functions.<Publisher<? extends T>>identity(), prefetch);
    }

    /**
     * Returns a Flowable that emits {@code 0L} after a specified delay, and then completes.
     *

     *
     *

     *
Backpressure:

     *
This operator does not support backpressure as it uses time. If the downstream needs a slower rate
     *      it should slow the timer or use something like {@link #onBackpressureDrop}.

     *
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 a Flowable that emits {@code 0L} after a specified delay, and then completes
     * @see ReactiveX operators documentation: Timer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.COMPUTATION)
    public static Flowable<Long> timer(long delay, TimeUnit unit) {
        return timer(delay, unit, Schedulers.computation());
    }

    /**
     * Returns a Flowable that emits {@code 0L} after a specified delay, on a specified Scheduler, and then
     * completes.
     *

     *
     *

     *
Backpressure:

     *
This operator does not support backpressure as it uses time. If the downstream needs a slower rate
     *      it should slow the timer or use something like {@link #onBackpressureDrop}.

     *
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
     * @return a Flowable that emits {@code 0L} after a specified delay, on a specified Scheduler, and then
     *         completes
     * @see ReactiveX operators documentation: Timer
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public static Flowable<Long> timer(long delay, TimeUnit unit, Scheduler scheduler) {
        ObjectHelper.requireNonNull(unit, "unit is null");
        ObjectHelper.requireNonNull(scheduler, "scheduler is null");

        return RxJavaPlugins.onAssembly(new FlowableTimer(Math.max(0L, delay), unit, scheduler));
    }

    /**
     * Create a Flowable by wrapping a Publisher which has to be implemented according
     * to the Reactive-Streams specification by handling backpressure and
     * cancellation correctly; no safeguards are provided by the Flowable itself.
     *

     *
Backpressure:

     *
This operator is a pass-through for backpressure and the behavior is determined by the
     *  provided Publisher implementation.

     *
Scheduler:

     *
{@code unsafeCreate} by default doesn't operate on any particular {@link Scheduler}.

     *

     * @param <T> the value type emitted
     * @param onSubscribe the Publisher instance to wrap
     * @return the new Flowable instance
     * @throws IllegalArgumentException if {@code onSubscribe} is a subclass of {@code Flowable}; such
     * instances don't need conversion and is possibly a port remnant from 1.x or one should use {@link #hide()}
     * instead.
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.NONE)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T> Flowable<T> unsafeCreate(Publisher<T> onSubscribe) {
        ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null");
        if (onSubscribe instanceof Flowable) {
            throw new IllegalArgumentException("unsafeCreate(Flowable) should be upgraded");
        }
        return RxJavaPlugins.onAssembly(new FlowableFromPublisher<T>(onSubscribe));
    }

    /**
     * Constructs a Publisher that creates a dependent resource object which is disposed of on cancellation.
     *

     *
     *

     *
Backpressure:

     *
The operator is a pass-through for backpressure and otherwise depends on the
     *  backpressure support of the Publisher returned by the {@code resourceFactory}.

     *
Scheduler:

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

     *

     *
     * @param <T> the element type of the generated Publisher
     * @param <D> the type of the resource associated with the output sequence
     * @param resourceSupplier
     *            the factory function to create a resource object that depends on the Publisher
     * @param sourceSupplier
     *            the factory function to create a Publisher
     * @param resourceDisposer
     *            the function that will dispose of the resource
     * @return the Publisher whose lifetime controls the lifetime of the dependent resource object
     * @see ReactiveX operators documentation: Using
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T, D> Flowable<T> using(Callable<? extends D> resourceSupplier,
            Function<? super D, ? extends Publisher<? extends T>> sourceSupplier, Consumer<? super D> resourceDisposer) {
        return using(resourceSupplier, sourceSupplier, resourceDisposer, true);
    }

    /**
     * Constructs a Publisher that creates a dependent resource object which is disposed of just before
     * termination if you have set {@code disposeEagerly} to {@code true} and cancellation does not occur
     * before termination. Otherwise, resource disposal will occur on cancellation.  Eager disposal is
     * particularly appropriate for a synchronous Publisher that reuses resources. {@code disposeAction} will
     * only be called once per subscription.
     *

     *
     *

     *
Backpressure:

     *
The operator is a pass-through for backpressure and otherwise depends on the
     *  backpressure support of the Publisher returned by the {@code resourceFactory}.

     *
Scheduler:

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

     *

     *
     * @param <T> the element type of the generated Publisher
     * @param <D> the type of the resource associated with the output sequence
     * @param resourceSupplier
     *            the factory function to create a resource object that depends on the Publisher
     * @param sourceSupplier
     *            the factory function to create a Publisher
     * @param resourceDisposer
     *            the function that will dispose of the resource
     * @param eager
     *            if {@code true} then disposal will happen either on cancellation or just before emission of
     *            a terminal event ({@code onComplete} or {@code onError}).
     * @return the Publisher whose lifetime controls the lifetime of the dependent resource object
     * @see ReactiveX operators documentation: Using
     * @since 2.0
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T, D> Flowable<T> using(Callable<? extends D> resourceSupplier,
            Function<? super D, ? extends Publisher<? extends T>> sourceSupplier,
                    Consumer<? super D> resourceDisposer, boolean eager) {
        ObjectHelper.requireNonNull(resourceSupplier, "resourceSupplier is null");
        ObjectHelper.requireNonNull(sourceSupplier, "sourceSupplier is null");
        ObjectHelper.requireNonNull(resourceDisposer, "resourceDisposer is null");
        return RxJavaPlugins.onAssembly(new FlowableUsing<T, D>(resourceSupplier, sourceSupplier, resourceDisposer, eager));
    }

    /**
     * Returns a Flowable that emits the results of a specified combiner function applied to combinations of
     * items emitted, in sequence, by an Iterable of other Publishers.
     *

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

     * The resulting {@code Publisher<R>} returned from {@code zip} will invoke {@code onNext} as many times as
     * the number of {@code onNext} invocations of the source Publisher that emits the fewest items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while canceling 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 cancel 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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     * @param <T> the common value type
     * @param <R> the zipped result type
     * @param sources
     *            an Iterable of source Publishers
     * @param zipper
     *            a function that, when applied to an item emitted by each of the source Publishers, results in
     *            an item that will be emitted by the resulting Publisher
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T, R> Flowable<R> zip(Iterable<? extends Publisher<? extends T>> sources, Function<? super Object[], ? extends R> zipper) {
        ObjectHelper.requireNonNull(zipper, "zipper is null");
        ObjectHelper.requireNonNull(sources, "sources is null");
        return RxJavaPlugins.onAssembly(new FlowableZip<T, R>(null, sources, zipper, bufferSize(), false));
    }

    /**
     * Returns a Flowable that emits the results of a specified combiner function applied to combinations of
     * n items emitted, in sequence, by the n Publishers emitted by a specified Publisher.
     *

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

     * The resulting {@code Publisher<R>} returned from {@code zip} will invoke {@code onNext} as many times as
     * the number of {@code onNext} invocations of the source Publisher that emits the fewest items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while cancel 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 cancel 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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     * @param <T> the value type of the inner Publishers
     * @param <R> the zipped result type
     * @param sources
     *            a Publisher of source Publishers
     * @param zipper
     *            a function that, when applied to an item emitted by each of the Publishers emitted by
     *            {@code ws}, results in an item that will be emitted by the resulting Publisher
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @SuppressWarnings({ "rawtypes", "unchecked", "cast" })
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T, R> Flowable<R> zip(Publisher<? extends Publisher<? extends T>> sources,
            final Function<? super Object[], ? extends R> zipper) {
        ObjectHelper.requireNonNull(zipper, "zipper is null");
        return fromPublisher(sources).toList().flatMapPublisher((Function)FlowableInternalHelper.<T, R>zipIterable(zipper));
    }

    /**
     * Returns a Flowable that emits the results of a specified combiner function applied to combinations of
     * two items emitted, in sequence, by two other Publishers.
     *

     *
     *

     * {@code zip} applies this function in strict sequence, so the first item emitted by the new Publisher
     * 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 Publisher 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 Publisher<R>} returned from {@code zip} will invoke {@link Subscriber#onNext onNext}
     * as many times as the number of {@code onNext} invocations of the source Publisher that emits the fewest
     * items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while canceling 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 cancel 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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     * @param <T1> the value type of the first source
     * @param <T2> the value type of the second source
     * @param <R> the zipped result type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            a second source Publisher
     * @param zipper
     *            a function that, when applied to an item emitted by each of the source Publishers, results
     *            in an item that will be emitted by the resulting Publisher
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, R> Flowable<R> zip(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2,
            BiFunction<? super T1, ? super T2, ? extends R> zipper) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2);
    }

    /**
     * Returns a Flowable that emits the results of a specified combiner function applied to combinations of
     * two items emitted, in sequence, by two other Publishers.
     *

     *
     *

     * {@code zip} applies this function in strict sequence, so the first item emitted by the new Publisher
     * 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 Publisher 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 Publisher<R>} returned from {@code zip} will invoke {@link Subscriber#onNext onNext}
     * as many times as the number of {@code onNext} invocations of the source Publisher that emits the fewest
     * items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while canceling 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 cancel 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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     * @param <T1> the value type of the first source
     * @param <T2> the value type of the second source
     * @param <R> the zipped result type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            a second source Publisher
     * @param zipper
     *            a function that, when applied to an item emitted by each of the source Publishers, results
     *            in an item that will be emitted by the resulting Publisher
     * @param delayError delay errors from any of the source Publishers till the other terminates
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, R> Flowable<R> zip(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2,
            BiFunction<? super T1, ? super T2, ? extends R> 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 a Flowable that emits the results of a specified combiner function applied to combinations of
     * two items emitted, in sequence, by two other Publishers.
     *

     *
     *

     * {@code zip} applies this function in strict sequence, so the first item emitted by the new Publisher
     * 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 Publisher 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 Publisher<R>} returned from {@code zip} will invoke {@link Subscriber#onNext onNext}
     * as many times as the number of {@code onNext} invocations of the source Publisher that emits the fewest
     * items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while canceling 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 cancel 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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     * @param <T1> the value type of the first source
     * @param <T2> the value type of the second source
     * @param <R> the zipped result type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            a second source Publisher
     * @param zipper
     *            a function that, when applied to an item emitted by each of the source Publishers, results
     *            in an item that will be emitted by the resulting Publisher
     * @param delayError delay errors from any of the source Publishers till the other terminates
     * @param bufferSize the number of elements to prefetch from each source Publisher
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, R> Flowable<R> zip(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2,
            BiFunction<? super T1, ? super T2, ? extends R> 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 a Flowable that emits the results of a specified combiner function applied to combinations of
     * three items emitted, in sequence, by three other Publishers.
     *

     *
     *

     * {@code zip} applies this function in strict sequence, so the first item emitted by the new Publisher
     * 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
     * Publisher 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 Publisher<R>} returned from {@code zip} will invoke {@link Subscriber#onNext onNext}
     * as many times as the number of {@code onNext} invocations of the source Publisher that emits the fewest
     * items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while canceling 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 cancel 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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     * @param <T1> the value type of the first source
     * @param <T2> the value type of the second source
     * @param <T3> the value type of the third source
     * @param <R> the zipped result type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            a second source Publisher
     * @param source3
     *            a third source Publisher
     * @param zipper
     *            a function that, when applied to an item emitted by each of the source Publishers, results in
     *            an item that will be emitted by the resulting Publisher
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, R> Flowable<R> zip(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2, Publisher<? extends T3> source3,
            Function3<? super T1, ? super T2, ? super T3, ? extends R> 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 a Flowable that emits the results of a specified combiner function applied to combinations of
     * four items emitted, in sequence, by four other Publishers.
     *

     *
     *

     * {@code zip} applies this function in strict sequence, so the first item emitted by the new Publisher
     * 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 Publisher will be the result of the function applied to the second
     * item emitted by each of those Publishers; and so forth.
     *

     * The resulting {@code Publisher<R>} returned from {@code zip} will invoke {@link Subscriber#onNext onNext}
     * as many times as the number of {@code onNext} invocations of the source Publisher that emits the fewest
     * items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while canceling 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 cancel 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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     * @param <T1> the value type of the first source
     * @param <T2> the value type of the second source
     * @param <T3> the value type of the third source
     * @param <T4> the value type of the fourth source
     * @param <R> the zipped result type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            a second source Publisher
     * @param source3
     *            a third source Publisher
     * @param source4
     *            a fourth source Publisher
     * @param zipper
     *            a function that, when applied to an item emitted by each of the source Publishers, results in
     *            an item that will be emitted by the resulting Publisher
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, T4, R> Flowable<R> zip(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2, Publisher<? extends T3> source3,
            Publisher<? extends T4> source4,
            Function4<? super T1, ? super T2, ? super T3, ? super T4, ? extends R> 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 a Flowable that emits the results of a specified combiner function applied to combinations of
     * five items emitted, in sequence, by five other Publishers.
     *

     *
     *

     * {@code zip} applies this function in strict sequence, so the first item emitted by the new Publisher
     * 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 Publisher will be the result of
     * the function applied to the second item emitted by each of those Publishers; and so forth.
     *

     * The resulting {@code Publisher<R>} returned from {@code zip} will invoke {@link Subscriber#onNext onNext}
     * as many times as the number of {@code onNext} invocations of the source Publisher that emits the fewest
     * items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while canceling 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 cancel 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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     * @param <T1> the value type of the first source
     * @param <T2> the value type of the second source
     * @param <T3> the value type of the third source
     * @param <T4> the value type of the fourth source
     * @param <T5> the value type of the fifth source
     * @param <R> the zipped result type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            a second source Publisher
     * @param source3
     *            a third source Publisher
     * @param source4
     *            a fourth source Publisher
     * @param source5
     *            a fifth source Publisher
     * @param zipper
     *            a function that, when applied to an item emitted by each of the source Publishers, results in
     *            an item that will be emitted by the resulting Publisher
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, T4, T5, R> Flowable<R> zip(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2, Publisher<? extends T3> source3,
            Publisher<? extends T4> source4, Publisher<? extends T5> source5,
            Function5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> 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 a Flowable that emits the results of a specified combiner function applied to combinations of
     * six items emitted, in sequence, by six other Publishers.
     *

     *
     *

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

     * The resulting {@code Publisher<R>} returned from {@code zip} will invoke {@link Subscriber#onNext onNext}
     * as many times as the number of {@code onNext} invocations of the source Publisher that emits the fewest
     * items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while canceling 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 cancel 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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     * @param <T1> the value type of the first source
     * @param <T2> the value type of the second source
     * @param <T3> the value type of the third source
     * @param <T4> the value type of the fourth source
     * @param <T5> the value type of the fifth source
     * @param <T6> the value type of the sixth source
     * @param <R> the zipped result type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            a second source Publisher
     * @param source3
     *            a third source Publisher
     * @param source4
     *            a fourth source Publisher
     * @param source5
     *            a fifth source Publisher
     * @param source6
     *            a sixth source Publisher
     * @param zipper
     *            a function that, when applied to an item emitted by each of the source Publishers, results in
     *            an item that will be emitted by the resulting Publisher
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, T4, T5, T6, R> Flowable<R> zip(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2, Publisher<? extends T3> source3,
            Publisher<? extends T4> source4, Publisher<? extends T5> source5, Publisher<? extends T6> source6,
            Function6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> 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 a Flowable that emits the results of a specified combiner function applied to combinations of
     * seven items emitted, in sequence, by seven other Publishers.
     *

     *
     *

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

     * The resulting {@code Publisher<R>} returned from {@code zip} will invoke {@link Subscriber#onNext onNext}
     * as many times as the number of {@code onNext} invocations of the source Publisher that emits the fewest
     * items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while canceling 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 cancel 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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     * @param <T1> the value type of the first source
     * @param <T2> the value type of the second source
     * @param <T3> the value type of the third source
     * @param <T4> the value type of the fourth source
     * @param <T5> the value type of the fifth source
     * @param <T6> the value type of the sixth source
     * @param <T7> the value type of the seventh source
     * @param <R> the zipped result type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            a second source Publisher
     * @param source3
     *            a third source Publisher
     * @param source4
     *            a fourth source Publisher
     * @param source5
     *            a fifth source Publisher
     * @param source6
     *            a sixth source Publisher
     * @param source7
     *            a seventh source Publisher
     * @param zipper
     *            a function that, when applied to an item emitted by each of the source Publishers, results in
     *            an item that will be emitted by the resulting Publisher
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, T4, T5, T6, T7, R> Flowable<R> zip(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2, Publisher<? extends T3> source3,
            Publisher<? extends T4> source4, Publisher<? extends T5> source5, Publisher<? extends T6> source6,
            Publisher<? extends T7> source7,
            Function7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> 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 a Flowable that emits the results of a specified combiner function applied to combinations of
     * eight items emitted, in sequence, by eight other Publishers.
     *

     *
     *

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

     * The resulting {@code Publisher<R>} returned from {@code zip} will invoke {@link Subscriber#onNext onNext}
     * as many times as the number of {@code onNext} invocations of the source Publisher that emits the fewest
     * items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while canceling 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 cancel 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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     * @param <T1> the value type of the first source
     * @param <T2> the value type of the second source
     * @param <T3> the value type of the third source
     * @param <T4> the value type of the fourth source
     * @param <T5> the value type of the fifth source
     * @param <T6> the value type of the sixth source
     * @param <T7> the value type of the seventh source
     * @param <T8> the value type of the eighth source
     * @param <R> the zipped result type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            a second source Publisher
     * @param source3
     *            a third source Publisher
     * @param source4
     *            a fourth source Publisher
     * @param source5
     *            a fifth source Publisher
     * @param source6
     *            a sixth source Publisher
     * @param source7
     *            a seventh source Publisher
     * @param source8
     *            an eighth source Publisher
     * @param zipper
     *            a function that, when applied to an item emitted by each of the source Publishers, results in
     *            an item that will be emitted by the resulting Publisher
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, T4, T5, T6, T7, T8, R> Flowable<R> zip(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2, Publisher<? extends T3> source3,
            Publisher<? extends T4> source4, Publisher<? extends T5> source5, Publisher<? extends T6> source6,
            Publisher<? extends T7> source7, Publisher<? extends T8> source8,
            Function8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> 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 a Flowable that emits the results of a specified combiner function applied to combinations of
     * nine items emitted, in sequence, by nine other Publishers.
     *

     *
     *

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

     * The resulting {@code Publisher<R>} returned from {@code zip} will invoke {@link Subscriber#onNext onNext}
     * as many times as the number of {@code onNext} invocations of the source Publisher that emits the fewest
     * items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while canceling 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 cancel 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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     * @param <T1> the value type of the first source
     * @param <T2> the value type of the second source
     * @param <T3> the value type of the third source
     * @param <T4> the value type of the fourth source
     * @param <T5> the value type of the fifth source
     * @param <T6> the value type of the sixth source
     * @param <T7> the value type of the seventh source
     * @param <T8> the value type of the eighth source
     * @param <T9> the value type of the ninth source
     * @param <R> the zipped result type
     * @param source1
     *            the first source Publisher
     * @param source2
     *            a second source Publisher
     * @param source3
     *            a third source Publisher
     * @param source4
     *            a fourth source Publisher
     * @param source5
     *            a fifth source Publisher
     * @param source6
     *            a sixth source Publisher
     * @param source7
     *            a seventh source Publisher
     * @param source8
     *            an eighth source Publisher
     * @param source9
     *            a ninth source Publisher
     * @param zipper
     *            a function that, when applied to an item emitted by each of the source Publishers, results in
     *            an item that will be emitted by the resulting Publisher
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Flowable<R> zip(
            Publisher<? extends T1> source1, Publisher<? extends T2> source2, Publisher<? extends T3> source3,
            Publisher<? extends T4> source4, Publisher<? extends T5> source5, Publisher<? extends T6> source6,
            Publisher<? extends T7> source7, Publisher<? extends T8> source8, Publisher<? extends T9> source9,
            Function9<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9, ? extends R> 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 a Flowable that emits the results of a specified combiner function applied to combinations of
     * items emitted, in sequence, by an array of other Publishers.
     *

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

     * The resulting {@code Publisher<R>} returned from {@code zip} will invoke {@code onNext} as many times as
     * the number of {@code onNext} invocations of the source Publisher that emits the fewest items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while canceling 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 cancel B immediately. For example:
     *
zip(new Publisher[]{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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     * @param <T> the common element type
     * @param <R> the result type
     * @param sources
     *            an array of source Publishers
     * @param zipper
     *            a function that, when applied to an item emitted by each of the source Publishers, results in
     *            an item that will be emitted by the resulting Publisher
     * @param delayError
     *            delay errors signaled by any of the source Publisher until all Publishers terminate
     * @param bufferSize
     *            the number of elements to prefetch from each source Publisher
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T, R> Flowable<R> zipArray(Function<? super Object[], ? extends R> zipper,
            boolean delayError, int bufferSize, Publisher<? extends T>... sources) {
        if (sources.length == 0) {
            return empty();
        }
        ObjectHelper.requireNonNull(zipper, "zipper is null");
        ObjectHelper.verifyPositive(bufferSize, "bufferSize");
        return RxJavaPlugins.onAssembly(new FlowableZip<T, R>(sources, null, zipper, bufferSize, delayError));
    }

    /**
     * Returns a Flowable that emits the results of a specified combiner function applied to combinations of
     * items emitted, in sequence, by an Iterable of other Publishers.
     *

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

     * The resulting {@code Publisher<R>} returned from {@code zip} will invoke {@code onNext} as many times as
     * the number of {@code onNext} invocations of the source Publisher that emits the fewest items.
     *

     * The operator subscribes to its sources in the order they are specified and completes eagerly if
     * one of the sources is shorter than the rest while canceling 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 cancel 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 #doOnCancel(Action)} as well or use {@code using()} to do cleanup in case of completion
     * or cancellation.
     *

     *
     *

     *
Backpressure:

     *
The operator expects backpressure from the sources and honors backpressure from the downstream.
     *  (I.e., zipping with {@link #interval(long, TimeUnit)} may result in MissingBackpressureException, use
     *  one of the {@code onBackpressureX} to handle similar, backpressure-ignoring sources.

     *
Scheduler:

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

     *

     *
     *
     * @param sources
     *            an Iterable of source Publishers
     * @param zipper
     *            a function that, when applied to an item emitted by each of the source Publishers, results in
     *            an item that will be emitted by the resulting Publisher
     * @param delayError
     *            delay errors signaled by any of the source Publisher until all Publishers terminate
     * @param bufferSize
     *            the number of elements to prefetch from each source Publisher
     * @param <T> the common source value type
     * @param <R> the zipped result type
     * @return a Flowable that emits the zipped results
     * @see ReactiveX operators documentation: Zip
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T, R> Flowable<R> zipIterable(Iterable<? extends Publisher<? extends T>> sources,
            Function<? super Object[], ? extends R> 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 FlowableZip<T, R>(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
     * Publisher satisfy a condition.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and consumes the source {@code Publisher} in an unbounded
     *  manner (i.e., without applying backpressure).

     *
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 Publisher satisfy the
     *         predicate; otherwise, {@code false}
     * @see ReactiveX operators documentation: All
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Single<Boolean> all(Predicate<? super T> predicate) {
        ObjectHelper.requireNonNull(predicate, "predicate is null");
        return RxJavaPlugins.onAssembly(new FlowableAllSingle<T>(this, predicate));
    }

    /**
     * Mirrors the Publisher (current or provided) that first either emits an item or sends a termination
     * notification.
     *

     *
     *

     *
Backpressure:

     *
The operator itself doesn't interfere with backpressure which is determined by the winning
     *  {@code Publisher}'s backpressure behavior.

     *
Scheduler:

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

     *

     *
     * @param other
     *            a Publisher competing to react first. A subscription to this provided Publisher will occur after subscribing
     *            to the current Publisher.
     * @return a Flowable that emits the same sequence as whichever of the source Publishers first
     *         emitted an item or sent a termination notification
     * @see ReactiveX operators documentation: Amb
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> ambWith(Publisher<? extends T> 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 Publisher satisfies a
     * specified condition, otherwise {@code false}. Note: this always emits {@code false} if the
     * source Publisher is empty.
     *

     *
     *

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

     *
Backpressure:

     *
The operator honors backpressure from downstream and consumes the source {@code Publisher} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
Scheduler:

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

     *

     *
     * @param predicate
     *            the condition to test items emitted by the source Publisher
     * @return a Single that emits a Boolean that indicates whether any item emitted by the source
     *         Publisher satisfies the {@code predicate}
     * @see ReactiveX operators documentation: Contains
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Single<Boolean> any(Predicate<? super T> predicate) {
        ObjectHelper.requireNonNull(predicate, "predicate is null");
        return RxJavaPlugins.onAssembly(new FlowableAnySingle<T>(this, predicate));
    }

    /**
     * Calls the specified converter function during assembly time and returns its resulting value.
     *

     * This allows fluent conversion to any other type.
     *

     *
Backpressure:

     *
The backpressure behavior depends on what happens in the {@code converter} function.

     *
Scheduler:

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

     *

     *
History: 2.1.7 - experimental
     * @param <R> the resulting object type
     * @param converter the function that receives the current Flowable instance and returns a value
     * @return the converted value
     * @throws NullPointerException if converter is null
     * @since 2.2
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.SPECIAL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> R as(@NonNull FlowableConverter<T, ? extends R> converter) {
        return ObjectHelper.requireNonNull(converter, "converter is null").apply(this);
    }

    /**
     * Returns the first item emitted by this {@code Flowable}, or throws
     * {@code NoSuchElementException} if it emits no items.
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
Scheduler:

     *
{@code blockingFirst} 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 first item emitted by this {@code Flowable}
     * @throws NoSuchElementException
     *             if this {@code Flowable} emits no items
     * @see ReactiveX documentation: First
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final T blockingFirst() {
        BlockingFirstSubscriber<T> s = new BlockingFirstSubscriber<T>();
        subscribe(s);
        T v = s.blockingGet();
        if (v != null) {
            return v;
        }
        throw new NoSuchElementException();
    }

    /**
     * Returns the first item emitted by this {@code Flowable}, or a default value if it emits no
     * items.
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
Scheduler:

     *
{@code blockingFirst} 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 Flowable} emits no items
     * @return the first item emitted by this {@code Flowable}, or the default value if it emits no
     *         items
     * @see ReactiveX documentation: First
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final T blockingFirst(T defaultItem) {
        BlockingFirstSubscriber<T> s = new BlockingFirstSubscriber<T>();
        subscribe(s);
        T v = s.blockingGet();
        return v != null ? v : defaultItem;
    }

    /**
     * Consumes the upstream {@code Flowable} 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.
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
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 Flowable}
     * @throws RuntimeException
     *             if an error occurs
     * @see ReactiveX documentation: Subscribe
     * @see #subscribe(Consumer)
     */
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final void blockingForEach(Consumer<? super T> onNext) {
        Iterator<T> 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 Flowable} into an {@link Iterable}.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to honor backpressure otherwise the returned
     *  Iterable's iterator will throw a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @return an {@link Iterable} version of this {@code Flowable}
     * @see ReactiveX documentation: To
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Iterable<T> blockingIterable() {
        return blockingIterable(bufferSize());
    }

    /**
     * Converts this {@code Flowable} into an {@link Iterable}.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to honor backpressure otherwise the returned
     *  Iterable's iterator will throw a {@code MissingBackpressureException}.
     *

     *
Scheduler:

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

     *

     *
     * @param bufferSize the number of items to prefetch from the current Flowable
     * @return an {@link Iterable} version of this {@code Flowable}
     * @see ReactiveX documentation: To
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Iterable<T> blockingIterable(int bufferSize) {
        ObjectHelper.verifyPositive(bufferSize, "bufferSize");
        return new BlockingFlowableIterable<T>(this, bufferSize);
    }

    /**
     * Returns the last item emitted by this {@code Flowable}, or throws
     * {@code NoSuchElementException} if this {@code Flowable} emits no items.
     *

     *
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
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 Flowable}
     * @throws NoSuchElementException
     *             if this {@code Flowable} emits no items
     * @see ReactiveX documentation: Last
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final T blockingLast() {
        BlockingLastSubscriber<T> s = new BlockingLastSubscriber<T>();
        subscribe(s);
        T v = s.blockingGet();
        if (v != null) {
            return v;
        }
        throw new NoSuchElementException();
    }

    /**
     * Returns the last item emitted by this {@code Flowable}, or a default value if it emits no
     * items.
     *

     *
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
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 Flowable} emits no items
     * @return the last item emitted by the {@code Flowable}, or the default value if it emits no
     *         items
     * @see ReactiveX documentation: Last
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final T blockingLast(T defaultItem) {
        BlockingLastSubscriber<T> s = new BlockingLastSubscriber<T>();
        subscribe(s);
        T v = s.blockingGet();
        return v != null ? v : defaultItem;
    }

    /**
     * Returns an {@link Iterable} that returns the latest item emitted by this {@code Flowable},
     * waiting if necessary for one to become available.
     *

     * If this {@code Flowable} 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.
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
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 Flowable}
     * @see ReactiveX documentation: First
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Iterable<T> blockingLatest() {
        return new BlockingFlowableLatest<T>(this);
    }

    /**
     * Returns an {@link Iterable} that always returns the item most recently emitted by this
     * {@code Flowable}.
     *

     *
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
Scheduler:

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

     *

     *
     * @param initialItem
     *            the initial item that the {@link Iterable} sequence will yield if this
     *            {@code Flowable} has not yet emitted an item
     * @return an {@link Iterable} that on each iteration returns the item that this {@code Flowable}
     *         has most recently emitted
     * @see ReactiveX documentation: First
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Iterable<T> blockingMostRecent(T initialItem) {
        return new BlockingFlowableMostRecent<T>(this, initialItem);
    }

    /**
     * Returns an {@link Iterable} that blocks until this {@code Flowable} emits another item, then
     * returns that item.
     *

     *
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
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 Flowable} emits
     *         a new item, whereupon the Iterable returns that item
     * @see ReactiveX documentation: TakeLast
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Iterable<T> blockingNext() {
        return new BlockingFlowableNext<T>(this);
    }

    /**
     * If this {@code Flowable} completes after emitting a single item, return that item, otherwise
     * throw a {@code NoSuchElementException}.
     *

     *
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
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 Flowable}
     * @see ReactiveX documentation: First
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final T blockingSingle() {
        return singleOrError().blockingGet();
    }

    /**
     * If this {@code Flowable} 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.
     *

     *
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
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 Flowable} emits no items
     * @return the single item emitted by this {@code Flowable}, or the default value if it emits no
     *         items
     * @see ReactiveX documentation: First
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @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 Flowable}.
     *

     *
     *

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

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

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
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 Flowable}
     * @see ReactiveX documentation: To
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Future<T> toFuture() {
        return subscribeWith(new FutureSubscriber<T>());
    }

    /**
     * Runs the source Flowable 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.
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
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)
     */
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final void blockingSubscribe() {
        FlowableBlockingSubscribe.subscribe(this);
    }

    /**
     * Subscribes to the source and calls the given callbacks on the current thread.
     *

     * If the Flowable 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.
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
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)
     */
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final void blockingSubscribe(Consumer<? super T> onNext) {
        FlowableBlockingSubscribe.subscribe(this, onNext, Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION);
    }

    /**
     * Subscribes to the source and calls the given callbacks on the current thread.
     *

     * If the Flowable 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.
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an bounded manner (up to bufferSize
     *  outstanding request amount for items).

     *
Scheduler:

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

     *

     *
History: 2.1.15 - experimental
     * @param onNext the callback action for each source value
     * @param bufferSize the size of the buffer
     * @see #blockingSubscribe(Consumer, Consumer)
     * @see #blockingSubscribe(Consumer, Consumer, Action)
     * @since 2.2
     */
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final void blockingSubscribe(Consumer<? super T> onNext, int bufferSize) {
        FlowableBlockingSubscribe.subscribe(this, onNext, Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION, bufferSize);
    }

    /**
     * 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.
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
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)
     */
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final void blockingSubscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError) {
        FlowableBlockingSubscribe.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.
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an bounded manner (up to bufferSize
     *  outstanding request amount for items).

     *
Scheduler:

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

     *

     *
History: 2.1.15 - experimental
     * @param onNext the callback action for each source value
     * @param onError the callback action for an error event
     * @param bufferSize the size of the buffer
     * @since 2.2
     * @see #blockingSubscribe(Consumer, Consumer, Action)
     */
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final void blockingSubscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError,
        int bufferSize) {
        FlowableBlockingSubscribe.subscribe(this, onNext, onError, Functions.EMPTY_ACTION, bufferSize);
    }

    /**
     * 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.
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an unbounded manner
     *  (i.e., no backpressure applied to it).

     *
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
     */
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final void blockingSubscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError, Action onComplete) {
        FlowableBlockingSubscribe.subscribe(this, onNext, onError, onComplete);
    }

    /**
     * Subscribes to the source and calls the given callbacks on the current thread.
     *

     * Note that calling this method will block the caller thread until the upstream terminates
     * normally or with an error. Therefore, calling this method from special threads such as the
     * Android Main Thread or the Swing Event Dispatch Thread is not recommended.
     *

     *
Backpressure:

     *
The operator consumes the source {@code Flowable} in an bounded manner (up to bufferSize
     *  outstanding request amount for items).

     *
Scheduler:

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

     *

     *
History: 2.1.15 - experimental
     * @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.
     * @param bufferSize the size of the buffer
     * @since 2.2
     */
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final void blockingSubscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError, Action onComplete,
        int bufferSize) {
        FlowableBlockingSubscribe.subscribe(this, onNext, onError, onComplete, bufferSize);
    }

    /**
     * Subscribes to the source and calls the {@link Subscriber} 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 Subscriber} cancels the {@link Subscription} it receives via
     * {@link Subscriber#onSubscribe(Subscription)}.
     * Therefore, calling this method from special threads such as the
     * Android Main Thread or the Swing Event Dispatch Thread is not recommended.
     *

     *
Backpressure:

     *
The supplied {@code Subscriber} determines how backpressure is applied.

     *
Scheduler:

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

     *

     * The cancellation and backpressure is composed through.
     * @param subscriber the subscriber to forward events and calls to in the current thread
     * @since 2.0
     */
    @BackpressureSupport(BackpressureKind.SPECIAL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final void blockingSubscribe(Subscriber<? super T> subscriber) {
        FlowableBlockingSubscribe.subscribe(this, subscriber);
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher emits connected, non-overlapping buffers, each containing {@code count} items. When the source
     * Publisher completes, the resulting Publisher emits the current buffer and propagates the notification from the
     * source Publisher. Note that if the source Publisher issues an onError notification the event is passed on
     * immediately without first emitting the buffer it is in the process of assembling.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and expects the source {@code Publisher} to honor it as
     *  well, although not enforced; violation may lead to {@code MissingBackpressureException} somewhere
     *  downstream.

     *
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 a Flowable that emits connected, non-overlapping buffers, each containing at most
     *         {@code count} items from the source Publisher
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<List<T>> buffer(int count) {
        return buffer(count, count);
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher emits buffers every {@code skip} items, each containing {@code count} items. When the source
     * Publisher completes, the resulting Publisher emits the current buffer and propagates the notification from the
     * source Publisher. Note that if the source Publisher issues an onError notification the event is passed on
     * immediately without first emitting the buffer it is in the process of assembling.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and expects the source {@code Publisher} to honor it as
     *  well, although not enforced; violation may lead to {@code MissingBackpressureException} somewhere
     *  downstream.

     *
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 Publisher 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 a Flowable that emits buffers for every {@code skip} item from the source Publisher and
     *         containing at most {@code count} items
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<List<T>> buffer(int count, int skip) {
        return buffer(count, skip, ArrayListSupplier.<T>asCallable());
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher emits buffers every {@code skip} items, each containing {@code count} items. When the source
     * Publisher completes, the resulting Publisher emits the current buffer and propagates the notification from the
     * source Publisher. Note that if the source Publisher issues an onError notification the event is passed on
     * immediately without first emitting the buffer it is in the process of assembling.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and expects the source {@code Publisher} to honor it as
     *  well, although not enforced; violation may lead to {@code MissingBackpressureException} somewhere
     *  downstream.

     *
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 Publisher 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 a Flowable that emits buffers for every {@code skip} item from the source Publisher and
     *         containing at most {@code count} items
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <U extends Collection<? super T>> Flowable 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 FlowableBuffer<T, U>(this, count, skip, bufferSupplier));
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher emits connected, non-overlapping buffers, each containing {@code count} items. When the source
     * Publisher completes, the resulting Publisher emits the current buffer and propagates the notification from the
     * source Publisher. Note that if the source Publisher issues an onError notification the event is passed on
     * immediately without first emitting the buffer it is in the process of assembling.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and expects the source {@code Publisher} to honor it as
     *  well, although not enforced; violation may lead to {@code MissingBackpressureException} somewhere
     *  downstream.

     *
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 a Flowable that emits connected, non-overlapping buffers, each containing at most
     *         {@code count} items from the source Publisher
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <U extends Collection<? super T>> Flowable buffer(int count, Callable bufferSupplier) {
        return buffer(count, count, bufferSupplier);
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher 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
     * Publisher completes, the resulting Publisher emits the current buffer and propagates the notification from the
     * source Publisher. Note that if the source Publisher issues an onError notification the event is passed on
     * immediately without first emitting the buffer it is in the process of assembling.
     *

     *
     *

     *
Backpressure:

     *
This operator does not support backpressure as it uses time. It requests {@code Long.MAX_VALUE}
     *      upstream and does not obey downstream requests.

     *
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 a Flowable that emits new buffers of items emitted by the source Publisher periodically after
     *         a fixed timespan has elapsed
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.COMPUTATION)
    public final Flowable<List<T>> buffer(long timespan, long timeskip, TimeUnit unit) {
        return buffer(timespan, timeskip, unit, Schedulers.computation(), ArrayListSupplier.<T>asCallable());
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher 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 Publisher completes, the resulting Publisher emits the current buffer
     * and propagates the notification from the source Publisher. Note that if the source Publisher issues an onError
     * notification the event is passed on immediately without first emitting the buffer it is in the process of
     * assembling.
     *

     *
     *

     *
Backpressure:

     *
This operator does not support backpressure as it uses time. It requests {@code Long.MAX_VALUE}
     *      upstream and does not obey downstream requests.

     *
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 a Flowable that emits new buffers of items emitted by the source Publisher periodically after
     *         a fixed timespan has elapsed
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public final Flowable<List<T>> buffer(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler) {
        return buffer(timespan, timeskip, unit, scheduler, ArrayListSupplier.<T>asCallable());
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher 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 Publisher completes, the resulting Publisher emits the current buffer
     * and propagates the notification from the source Publisher. Note that if the source Publisher issues an onError
     * notification the event is passed on immediately without first emitting the buffer it is in the process of
     * assembling.
     *

     *
     *

     *
Backpressure:

     *
This operator does not support backpressure as it uses time. It requests {@code Long.MAX_VALUE}
     *      upstream and does not obey downstream requests.

     *
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 a Flowable that emits new buffers of items emitted by the source Publisher periodically after
     *         a fixed timespan has elapsed
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public final <U extends Collection<? super T>> Flowable 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 FlowableBufferTimed<T, U>(this, timespan, timeskip, unit, scheduler, bufferSupplier, Integer.MAX_VALUE, false));
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher emits connected, non-overlapping buffers, each of a fixed duration specified by the
     * {@code timespan} argument. When the source Publisher completes, the resulting Publisher emits the current buffer
     * and propagates the notification from the source Publisher. Note that if the source Publisher issues an onError
     * notification the event is passed on immediately without first emitting the buffer it is in the process of
     * assembling.
     *

     *
     *

     *
Backpressure:

     *
This operator does not support backpressure as it uses time. It requests {@code Long.MAX_VALUE}
     *      upstream and does not obey downstream requests.

     *
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 a Flowable that emits connected, non-overlapping buffers of items emitted by the source
     *         Publisher within a fixed duration
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.COMPUTATION)
    public final Flowable<List<T>> buffer(long timespan, TimeUnit unit) {
        return buffer(timespan, unit, Schedulers.computation(), Integer.MAX_VALUE);
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher 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 Publisher completes, the resulting Publisher emits the current buffer and propagates the
     * notification from the source Publisher. Note that if the source Publisher issues an onError notification the event
     * is passed on immediately without first emitting the buffer it is in the process of assembling.
     *

     *
     *

     *
Backpressure:

     *
This operator does not support backpressure as it uses time. It requests {@code Long.MAX_VALUE}
     *      upstream and does not obey downstream requests.

     *
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 a Flowable that emits connected, non-overlapping buffers of items emitted by the source
     *         Publisher, after a fixed duration or when the buffer reaches maximum capacity (whichever occurs
     *         first)
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.COMPUTATION)
    public final Flowable<List<T>> buffer(long timespan, TimeUnit unit, int count) {
        return buffer(timespan, unit, Schedulers.computation(), count);
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher 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 Publisher completes, the resulting
     * Publisher emits the current buffer and propagates the notification from the source Publisher. Note that if the
     * source Publisher issues an onError notification the event is passed on immediately without first emitting the
     * buffer it is in the process of assembling.
     *

     *
     *

     *
Backpressure:

     *
This operator does not support backpressure as it uses time. It requests {@code Long.MAX_VALUE}
     *      upstream and does not obey downstream requests.

     *
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 a Flowable that emits connected, non-overlapping buffers of items emitted by the source
     *         Publisher after a fixed duration or when the buffer reaches maximum capacity (whichever occurs
     *         first)
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public final Flowable<List<T>> buffer(long timespan, TimeUnit unit, Scheduler scheduler, int count) {
        return buffer(timespan, unit, scheduler, count, ArrayListSupplier.<T>asCallable(), false);
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher 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 Publisher completes, the resulting
     * Publisher emits the current buffer and propagates the notification from the source Publisher. Note that if the
     * source Publisher issues an onError notification the event is passed on immediately without first emitting the
     * buffer it is in the process of assembling.
     *

     *
     *

     *
Backpressure:

     *
This operator does not support backpressure as it uses time. It requests {@code Long.MAX_VALUE}
     *      upstream and does not obey downstream requests.

     *
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 a Flowable that emits connected, non-overlapping buffers of items emitted by the source
     *         Publisher after a fixed duration or when the buffer reaches maximum capacity (whichever occurs
     *         first)
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public final <U extends Collection<? super T>> Flowable 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 FlowableBufferTimed<T, U>(this, timespan, timespan, unit, scheduler, bufferSupplier, count, restartTimerOnMaxSize));
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher 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 Publisher completes, the
     * resulting Publisher emits the current buffer and propagates the notification from the source Publisher. Note that
     * if the source Publisher issues an onError notification the event is passed on immediately without first emitting
     * the buffer it is in the process of assembling.
     *

     *
     *

     *
Backpressure:

     *
This operator does not support backpressure as it uses time. It requests {@code Long.MAX_VALUE}
     *      upstream and does not obey downstream requests.

     *
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 a Flowable that emits connected, non-overlapping buffers of items emitted by the source
     *         Publisher within a fixed duration
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public final Flowable<List<T>> buffer(long timespan, TimeUnit unit, Scheduler scheduler) {
        return buffer(timespan, unit, scheduler, Integer.MAX_VALUE, ArrayListSupplier.<T>asCallable(), false);
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher emits buffers that it creates when the specified {@code openingIndicator} Publisher emits an
     * item, and closes when the Publisher returned from {@code closingIndicator} emits an item. If any of the source
     * Publisher, {@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.
     *

     *
     *

     *
Backpressure:

     *
This operator does not support backpressure as it is instead controlled by the given Publishers and
     *      buffers data. It requests {@code Long.MAX_VALUE} upstream and does not obey downstream requests.

     *
Scheduler:

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

     *

     *
     * @param <TOpening> the element type of the buffer-opening Publisher
     * @param <TClosing> the element type of the individual buffer-closing Publishers
     * @param openingIndicator
     *            the Publisher that, when it emits an item, causes a new buffer to be created
     * @param closingIndicator
     *            the {@link Function} that is used to produce a Publisher for every buffer created. When this
     *            Publisher emits an item, the associated buffer is emitted.
     * @return a Flowable that emits buffers, containing items from the source Publisher, that are created
     *         and closed when the specified Publishers emit items
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <TOpening, TClosing> Flowable<List<T>> buffer(
            Flowable<? extends TOpening> openingIndicator,
            Function<? super TOpening, ? extends Publisher<? extends TClosing>> closingIndicator) {
        return buffer(openingIndicator, closingIndicator, ArrayListSupplier.<T>asCallable());
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher emits buffers that it creates when the specified {@code openingIndicator} Publisher emits an
     * item, and closes when the Publisher returned from {@code closingIndicator} emits an item. If any of the source
     * Publisher, {@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.
     *

     *
     *

     *
Backpressure:

     *
This operator does not support backpressure as it is instead controlled by the given Publishers and
     *      buffers data. It requests {@code Long.MAX_VALUE} upstream and does not obey downstream requests.

     *
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 <TOpening> the element type of the buffer-opening Publisher
     * @param <TClosing> the element type of the individual buffer-closing Publishers
     * @param openingIndicator
     *            the Publisher that, when it emits an item, causes a new buffer to be created
     * @param closingIndicator
     *            the {@link Function} that is used to produce a Publisher for every buffer created. When this
     *            Publisher 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 a Flowable that emits buffers, containing items from the source Publisher, that are created
     *         and closed when the specified Publishers emit items
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <TOpening, TClosing, U extends Collection<? super T>> Flowable buffer(
            Flowable<? extends TOpening> openingIndicator,
            Function<? super TOpening, ? extends Publisher<? extends TClosing>> 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 FlowableBufferBoundary<T, U, TOpening, TClosing>(this, openingIndicator, closingIndicator, bufferSupplier));
    }

    /**
     * Returns a Flowable that emits non-overlapping buffered items from the source Publisher each time the
     * specified boundary Publisher emits an item.
     *

     *
     *

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

     *
Backpressure:

     *
This operator does not support backpressure as it is instead controlled by the {@code Publisher}
     *      {@code boundary} and buffers data. It requests {@code Long.MAX_VALUE} upstream and does not obey
     *      downstream requests.

     *
Scheduler:

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

     *

     *
     * @param
     *            the boundary value type (ignored)
     * @param boundaryIndicator
     *            the boundary Publisher
     * @return a Flowable that emits buffered items from the source Publisher when the boundary Publisher
     *         emits an item
     * @see #buffer(Publisher, int)
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final  Flowable<List<T>> buffer(Publisher boundaryIndicator) {
        return buffer(boundaryIndicator, ArrayListSupplier.<T>asCallable());
    }

    /**
     * Returns a Flowable that emits non-overlapping buffered items from the source Publisher each time the
     * specified boundary Publisher emits an item.
     *

     *
     *

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

     *
Backpressure:

     *
This operator does not support backpressure as it is instead controlled by the {@code Publisher}
     *      {@code boundary} and buffers data. It requests {@code Long.MAX_VALUE} upstream and does not obey
     *      downstream requests.

     *
Scheduler:

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

     *

     *
     * @param
     *            the boundary value type (ignored)
     * @param boundaryIndicator
     *            the boundary Publisher
     * @param initialCapacity
     *            the initial capacity of each buffer chunk
     * @return a Flowable that emits buffered items from the source Publisher when the boundary Publisher
     *         emits an item
     * @see ReactiveX operators documentation: Buffer
     * @see #buffer(Publisher)
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final  Flowable<List<T>> buffer(Publisher boundaryIndicator, final int initialCapacity) {
        ObjectHelper.verifyPositive(initialCapacity, "initialCapacity");
        return buffer(boundaryIndicator, Functions.<T>createArrayList(initialCapacity));
    }

    /**
     * Returns a Flowable that emits non-overlapping buffered items from the source Publisher each time the
     * specified boundary Publisher emits an item.
     *

     *
     *

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

     *
Backpressure:

     *
This operator does not support backpressure as it is instead controlled by the {@code Publisher}
     *      {@code boundary} and buffers data. It requests {@code Long.MAX_VALUE} upstream and does not obey
     *      downstream requests.

     *
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 boundaryIndicator
     *            the boundary Publisher
     * @param bufferSupplier
     *            a factory function that returns an instance of the collection subclass to be used and returned
     *            as the buffer
     * @return a Flowable that emits buffered items from the source Publisher when the boundary Publisher
     *         emits an item
     * @see #buffer(Publisher, int)
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <B, U extends Collection<? super T>> Flowable buffer(Publisher boundaryIndicator, Callable bufferSupplier) {
        ObjectHelper.requireNonNull(boundaryIndicator, "boundaryIndicator is null");
        ObjectHelper.requireNonNull(bufferSupplier, "bufferSupplier is null");
        return RxJavaPlugins.onAssembly(new FlowableBufferExactBoundary<T, U, B>(this, boundaryIndicator, bufferSupplier));
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher emits connected, non-overlapping buffers. It emits the current buffer and replaces it with a
     * new buffer whenever the Publisher produced by the specified {@code boundaryIndicatorSupplier} emits an item.
     *

     *
     *

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

     *
Backpressure:

     *
This operator does not support backpressure as it is instead controlled by the given Publishers and
     *      buffers data. It requests {@code Long.MAX_VALUE} upstream and does not obey downstream requests.

     *
Scheduler:

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

     *

     *
     * @param  the value type of the boundary-providing Publisher
     * @param boundaryIndicatorSupplier
     *            a {@link Callable} that produces a Publisher that governs the boundary between buffers.
     *            Whenever the supplied {@code Publisher} emits an item, {@code buffer} emits the current buffer and
     *            begins to fill a new one
     * @return a Flowable that emits a connected, non-overlapping buffer of items from the source Publisher
     *         each time the Publisher created with the {@code closingIndicator} argument emits an item
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final  Flowable<List<T>> buffer(Callable<? extends Publisher> boundaryIndicatorSupplier) {
        return buffer(boundaryIndicatorSupplier, ArrayListSupplier.<T>asCallable());
    }

    /**
     * Returns a Flowable that emits buffers of items it collects from the source Publisher. The resulting
     * Publisher emits connected, non-overlapping buffers. It emits the current buffer and replaces it with a
     * new buffer whenever the Publisher produced by the specified {@code boundaryIndicatorSupplier} emits an item.
     *

     *
     *

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

     *
Backpressure:

     *
This operator does not support backpressure as it is instead controlled by the given Publishers and
     *      buffers data. It requests {@code Long.MAX_VALUE} upstream and does not obey downstream requests.

     *
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 Publisher
     * @param boundaryIndicatorSupplier
     *            a {@link Callable} that produces a Publisher that governs the boundary between buffers.
     *            Whenever the supplied {@code Publisher} 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 a Flowable that emits a connected, non-overlapping buffer of items from the source Publisher
     *         each time the Publisher created with the {@code closingIndicator} argument emits an item
     * @see ReactiveX operators documentation: Buffer
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <B, U extends Collection<? super T>> Flowable buffer(Callable<? extends Publisher> boundaryIndicatorSupplier,
            Callable bufferSupplier) {
        ObjectHelper.requireNonNull(boundaryIndicatorSupplier, "boundaryIndicatorSupplier is null");
        ObjectHelper.requireNonNull(bufferSupplier, "bufferSupplier is null");
        return RxJavaPlugins.onAssembly(new FlowableBufferBoundarySupplier<T, U, B>(this, boundaryIndicatorSupplier, bufferSupplier));
    }

    /**
     * Returns a Flowable that subscribes to this Publisher 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 a Publisher to cache responses and you can't control the
     * subscribe/cancel behavior of all the {@link Subscriber}s.
     *

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

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

     *

     *
Backpressure:

     *
The operator consumes this Publisher in an unbounded fashion but respects the backpressure
     *  of each downstream Subscriber individually.

     *
Scheduler:

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

     *

     *
     * @return a Flowable that, when first subscribed to, caches all of its items and notifications for the
     *         benefit of subsequent subscribers
     * @see ReactiveX operators documentation: Replay
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> cache() {
        return cacheWithInitialCapacity(16);
    }

    /**
     * Returns a Flowable that subscribes to this Publisher 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 a Publisher to cache responses and you can't control the
     * subscribe/cancel behavior of all the {@link Subscriber}s.
     *

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

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

     *

     *
Backpressure:

     *
The operator consumes this Publisher in an unbounded fashion but respects the backpressure
     *  of each downstream Subscriber individually.

     *
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 ConnectableFlowable#autoConnect()} or similar.
     *
     * @param initialCapacity hint for number of items to cache (for optimizing underlying data structure)
     * @return a Flowable that, when first subscribed to, caches all of its items and notifications for the
     *         benefit of subsequent subscribers
     * @see ReactiveX operators documentation: Replay
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> cacheWithInitialCapacity(int initialCapacity) {
        ObjectHelper.verifyPositive(initialCapacity, "initialCapacity");
        return RxJavaPlugins.onAssembly(new FlowableCache<T>(this, initialCapacity));
    }

    /**
     * Returns a Flowable that emits the items emitted by the source Publisher, converted to the specified
     * type.
     *

     *
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
     *  backpressure behavior.

     *
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 Publisher
     *            into before emitting them from the resulting Publisher
     * @return a Flowable that emits each item from the source Publisher after converting it to the
     *         specified type
     * @see ReactiveX operators documentation: Map
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final  Flowable cast(final Class clazz) {
        ObjectHelper.requireNonNull(clazz, "clazz is null");
        return map(Functions.castFunction(clazz));
    }

    /**
     * Collects items emitted by the finite source Publisher 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}.
     *

     *
Backpressure:

     *
This operator does not support backpressure because by intent it will receive all values and reduce
     *      them to a single {@code onNext}.

     *
Scheduler:

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

     *

     *
     * @param  the accumulator and output type
     * @param initialItemSupplier
     *           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 Publisher
     *         into a single mutable data structure
     * @see ReactiveX operators documentation: Reduce
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final  Single collect(Callable<? extends U> initialItemSupplier, BiConsumer<? super U, ? super T> collector) {
        ObjectHelper.requireNonNull(initialItemSupplier, "initialItemSupplier is null");
        ObjectHelper.requireNonNull(collector, "collector is null");
        return RxJavaPlugins.onAssembly(new FlowableCollectSingle<T, U>(this, initialItemSupplier, collector));
    }

    /**
     * Collects items emitted by the finite source Publisher 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}.
     *

     *
Backpressure:

     *
This operator does not support backpressure because by intent it will receive all values and reduce
     *      them to a single {@code onNext}.

     *
Scheduler:

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

     *

     *
     * @param  the accumulator and output type
     * @param initialItem
     *           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 Publisher
     *         into a single mutable data structure
     * @see ReactiveX operators documentation: Reduce
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final  Single collectInto(final U initialItem, BiConsumer<? super U, ? super T> collector) {
        ObjectHelper.requireNonNull(initialItem, "initialItem is null");
        return collect(Functions.justCallable(initialItem), collector);
    }

    /**
     * Transform a Publisher by applying a particular Transformer function to it.
     *

     * This method operates on the Publisher itself whereas {@link #lift} operates on the Publisher's
     * Subscribers or Subscribers.
     *

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

     *
Backpressure:

     *
The operator itself doesn't interfere with the backpressure behavior which only depends
     *  on what kind of {@code Publisher} the transformer returns.

     *
Scheduler:

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

     *

     *
     * @param <R> the value type of the output Publisher
     * @param composer implements the function that transforms the source Publisher
     * @return the source Publisher, transformed by the transformer function
     * @see RxJava wiki: Implementing Your Own Operators
     */
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> compose(FlowableTransformer<? super T, ? extends R> composer) {
        return fromPublisher(((FlowableTransformer<T, R>) ObjectHelper.requireNonNull(composer, "composer is null")).apply(this));
    }

    /**
     * Returns a new Flowable that emits items resulting from applying a function that you supply to each item
     * emitted by the source Publisher, where that function returns a Publisher, and then emitting the items
     * that result from concatenating those resulting Publishers.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. Both this and the inner {@code Publisher}s are
     *  expected to honor backpressure as well. If the source {@code Publisher} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}. If any of the inner {@code Publisher}s doesn't honor
     *  backpressure, that may throw an {@code IllegalStateException} when that
     *  {@code Publisher} completes.

     *
Scheduler:

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

     *

     *
     * @param <R> the type of the inner Publisher sources and thus the output type
     * @param mapper
     *            a function that, when applied to an item emitted by the source Publisher, returns a
     *            Publisher
     * @return a Flowable that emits the result of applying the transformation function to each item emitted
     *         by the source Publisher and concatenating the Publishers obtained from this transformation
     * @see ReactiveX operators documentation: FlatMap
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMap(Function<? super T, ? extends Publisher<? extends R>> mapper) {
        return concatMap(mapper, 2);
    }

    /**
     * Returns a new Flowable that emits items resulting from applying a function that you supply to each item
     * emitted by the source Publisher, where that function returns a Publisher, and then emitting the items
     * that result from concatenating those resulting Publishers.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. Both this and the inner {@code Publisher}s are
     *  expected to honor backpressure as well. If the source {@code Publisher} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}. If any of the inner {@code Publisher}s doesn't honor
     *  backpressure, that may throw an {@code IllegalStateException} when that
     *  {@code Publisher} completes.

     *
Scheduler:

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

     *

     *
     * @param <R> the type of the inner Publisher sources and thus the output type
     * @param mapper
     *            a function that, when applied to an item emitted by the source Publisher, returns a
     *            Publisher
     * @param prefetch
     *            the number of elements to prefetch from the current Flowable
     * @return a Flowable that emits the result of applying the transformation function to each item emitted
     *         by the source Publisher and concatenating the Publishers obtained from this transformation
     * @see ReactiveX operators documentation: FlatMap
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMap(Function<? super T, ? extends Publisher<? extends R>> mapper, int prefetch) {
        ObjectHelper.requireNonNull(mapper, "mapper is null");
        ObjectHelper.verifyPositive(prefetch, "prefetch");
        if (this instanceof ScalarCallable) {
            @SuppressWarnings("unchecked")
            T v = ((ScalarCallable<T>)this).call();
            if (v == null) {
                return empty();
            }
            return FlowableScalarXMap.scalarXMap(v, mapper);
        }
        return RxJavaPlugins.onAssembly(new FlowableConcatMap<T, R>(this, mapper, prefetch, ErrorMode.IMMEDIATE));
    }

    /**
     * Maps the upstream items into {@link CompletableSource}s and subscribes to them one after the
     * other completes.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

     *
{@code concatMapCompletable} 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 #concatMapCompletableDelayError(Function)
     * @since 2.2
     */
    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    @BackpressureSupport(BackpressureKind.FULL)
    public final Completable concatMapCompletable(Function<? super T, ? extends CompletableSource> mapper) {
        return concatMapCompletable(mapper, 2);
    }

    /**
     * Maps the upstream items into {@link CompletableSource}s and subscribes to them one after the
     * other completes.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

     *
{@code concatMapCompletable} 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 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 #concatMapCompletableDelayError(Function, boolean, int)
     * @since 2.2
     */
    @CheckReturnValue
    @NonNull
    @SchedulerSupport(SchedulerSupport.NONE)
    @BackpressureSupport(BackpressureKind.FULL)
    public final Completable concatMapCompletable(Function<? super T, ? extends CompletableSource> mapper, int prefetch) {
        ObjectHelper.requireNonNull(mapper, "mapper is null");
        ObjectHelper.verifyPositive(prefetch, "prefetch");
        return RxJavaPlugins.onAssembly(new FlowableConcatMapCompletable<T>(this, mapper, ErrorMode.IMMEDIATE, prefetch));
    }

    /**
     * Maps the upstream items into {@link CompletableSource}s and subscribes to them one after the
     * other terminates, delaying all errors till both this {@code Flowable} and all
     * inner {@code CompletableSource}s terminate.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
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)
    @BackpressureSupport(BackpressureKind.FULL)
    public final Completable concatMapCompletableDelayError(Function<? super T, ? extends CompletableSource> 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 Flowable} and all
     * inner {@code CompletableSource}s terminate.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
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 Flowable} or any of the
     *                   inner {@code CompletableSource}s are delayed until all
     *                   of them terminate. If {@code false}, an error from this
     *                   {@code Flowable} 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)
    @BackpressureSupport(BackpressureKind.FULL)
    public final Completable concatMapCompletableDelayError(Function<? super T, ? extends CompletableSource> 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 Flowable} and all
     * inner {@code CompletableSource}s terminate.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
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 Flowable} or any of the
     *                   inner {@code CompletableSource}s are delayed until all
     *                   of them terminate. If {@code false}, an error from this
     *                   {@code Flowable} 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
    @NonNull
    @SchedulerSupport(SchedulerSupport.NONE)
    @BackpressureSupport(BackpressureKind.FULL)
    public final Completable concatMapCompletableDelayError(Function<? super T, ? extends CompletableSource> mapper, boolean tillTheEnd, int prefetch) {
        ObjectHelper.requireNonNull(mapper, "mapper is null");
        ObjectHelper.verifyPositive(prefetch, "prefetch");
        return RxJavaPlugins.onAssembly(new FlowableConcatMapCompletable<T>(this, mapper, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY, prefetch));
    }

    /**
     * Maps each of the items into a Publisher, 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 Publishers
     * till all of them terminate.
     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. Both this and the inner {@code Publisher}s are
     *  expected to honor backpressure as well. If the source {@code Publisher} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}. If any of the inner {@code Publisher}s doesn't honor
     *  backpressure, that may throw an {@code IllegalStateException} when that
     *  {@code Publisher} completes.

     *
Scheduler:

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

     *

     *
     * @param <R> the result value type
     * @param mapper the function that maps the items of this Publisher into the inner Publishers.
     * @return the new Publisher instance with the concatenation behavior
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper) {
        return concatMapDelayError(mapper, 2, true);
    }

    /**
     * Maps each of the items into a Publisher, 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 Publishers
     * till all of them terminate.
     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. Both this and the inner {@code Publisher}s are
     *  expected to honor backpressure as well. If the source {@code Publisher} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}. If any of the inner {@code Publisher}s doesn't honor
     *  backpressure, that may throw an {@code IllegalStateException} when that
     *  {@code Publisher} completes.

     *
Scheduler:

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

     *

     *
     * @param <R> the result value type
     * @param mapper the function that maps the items of this Publisher into the inner Publishers.
     * @param prefetch
     *            the number of elements to prefetch from the current Flowable
     * @param tillTheEnd
     *            if true, all errors from the outer and inner Publisher sources are delayed until the end,
     *            if false, an error from the main source is signaled when the current Publisher source terminates
     * @return the new Publisher instance with the concatenation behavior
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper,
            int prefetch, boolean tillTheEnd) {
        ObjectHelper.requireNonNull(mapper, "mapper is null");
        ObjectHelper.verifyPositive(prefetch, "prefetch");
        if (this instanceof ScalarCallable) {
            @SuppressWarnings("unchecked")
            T v = ((ScalarCallable<T>)this).call();
            if (v == null) {
                return empty();
            }
            return FlowableScalarXMap.scalarXMap(v, mapper);
        }
        return RxJavaPlugins.onAssembly(new FlowableConcatMap<T, R>(this, mapper, prefetch, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY));
    }

    /**
     * Maps a sequence of values into Publishers and concatenates these Publishers eagerly into a single
     * Publisher.
     *

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

     *
Backpressure:

     *
Backpressure is honored towards the downstream, however, due to the eagerness requirement, sources
     *      are subscribed to in unbounded mode and their values are queued up in an unbounded buffer.

     *
Scheduler:

     *
This method does not operate by default on a particular {@link Scheduler}.

     *

     * @param <R> the value type
     * @param mapper the function that maps a sequence of values into a sequence of Publishers that will be
     *               eagerly concatenated
     * @return the new Publisher instance with the specified concatenation behavior
     * @since 2.0
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapEager(Function<? super T, ? extends Publisher<? extends R>> mapper) {
        return concatMapEager(mapper, bufferSize(), bufferSize());
    }

    /**
     * Maps a sequence of values into Publishers and concatenates these Publishers eagerly into a single
     * Publisher.
     *

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

     *
Backpressure:

     *
Backpressure is honored towards the downstream, however, due to the eagerness requirement, sources
     *      are subscribed to in unbounded mode and their values are queued up in an unbounded buffer.

     *
Scheduler:

     *
This method does not operate by default on a particular {@link Scheduler}.

     *

     * @param <R> the value type
     * @param mapper the function that maps a sequence of values into a sequence of Publishers that will be
     *               eagerly concatenated
     * @param maxConcurrency the maximum number of concurrent subscribed Publishers
     * @param prefetch hints about the number of expected values from each inner Publisher, must be positive
     * @return the new Publisher instance with the specified concatenation behavior
     * @since 2.0
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapEager(Function<? super T, ? extends Publisher<? extends R>> mapper,
            int maxConcurrency, int prefetch) {
        ObjectHelper.requireNonNull(mapper, "mapper is null");
        ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency");
        ObjectHelper.verifyPositive(prefetch, "prefetch");
        return RxJavaPlugins.onAssembly(new FlowableConcatMapEager<T, R>(this, mapper, maxConcurrency, prefetch, ErrorMode.IMMEDIATE));
    }

    /**
     * Maps a sequence of values into Publishers and concatenates these Publishers eagerly into a single
     * Publisher.
     *

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

     *
Backpressure:

     *
Backpressure is honored towards the downstream, however, due to the eagerness requirement, sources
     *      are subscribed to in unbounded mode and their values are queued up in an unbounded buffer.

     *
Scheduler:

     *
This method does not operate by default on a particular {@link Scheduler}.

     *

     * @param <R> the value type
     * @param mapper the function that maps a sequence of values into a sequence of Publishers that will be
     *               eagerly concatenated
     * @param tillTheEnd
     *            if true, all errors from the outer and inner Publisher sources are delayed until the end,
     *            if false, an error from the main source is signaled when the current Publisher source terminates
     * @return the new Publisher instance with the specified concatenation behavior
     * @since 2.0
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapEagerDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper,
            boolean tillTheEnd) {
        return concatMapEagerDelayError(mapper, bufferSize(), bufferSize(), tillTheEnd);
    }

    /**
     * Maps a sequence of values into Publishers and concatenates these Publishers eagerly into a single
     * Publisher.
     *

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

     *
Backpressure:

     *
Backpressure is honored towards the downstream, however, due to the eagerness requirement, sources
     *      are subscribed to in unbounded mode and their values are queued up in an unbounded buffer.

     *
Scheduler:

     *
This method does not operate by default on a particular {@link Scheduler}.

     *

     * @param <R> the value type
     * @param mapper the function that maps a sequence of values into a sequence of Publishers that will be
     *               eagerly concatenated
     * @param maxConcurrency the maximum number of concurrent subscribed Publishers
     * @param prefetch
     *               the number of elements to prefetch from each source Publisher
     * @param tillTheEnd
     *               if true, exceptions from the current Flowable and all the inner Publishers are delayed until
     *               all of them terminate, if false, exception from the current Flowable is delayed until the
     *               currently running Publisher terminates
     * @return the new Publisher instance with the specified concatenation behavior
     * @since 2.0
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapEagerDelayError(Function<? super T, ? extends Publisher<? extends R>> 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 FlowableConcatMapEager<T, R>(this, mapper, maxConcurrency, prefetch, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY));
    }

    /**
     * Returns a Flowable that concatenate each item emitted by the source Publisher with the values in an
     * Iterable corresponding to that item that is generated by a selector.
     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s is
     *  expected to honor backpressure as well. If the source {@code Publisher} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param
     *            the type of item emitted by the resulting Publisher
     * @param mapper
     *            a function that returns an Iterable sequence of values for when given an item emitted by the
     *            source Publisher
     * @return a Flowable that emits the results of concatenating the items emitted by the source Publisher with
     *         the values in the Iterables corresponding to those items, as generated by {@code collectionSelector}
     * @see ReactiveX operators documentation: FlatMap
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final  Flowable concatMapIterable(Function<? super T, ? extends Iterable<? extends U>> mapper) {
        return concatMapIterable(mapper, 2);
    }

    /**
     * Returns a Flowable that concatenate each item emitted by the source Publisher with the values in an
     * Iterable corresponding to that item that is generated by a selector.
     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. The source {@code Publisher}s is
     *  expected to honor backpressure as well. If the source {@code Publisher} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
     * @param
     *            the type of item emitted by the resulting Publisher
     * @param mapper
     *            a function that returns an Iterable sequence of values for when given an item emitted by the
     *            source Publisher
     * @param prefetch
     *            the number of elements to prefetch from the current Flowable
     * @return a Flowable that emits the results of concatenating the items emitted by the source Publisher with
     *         the values in the Iterables corresponding to those items, as generated by {@code collectionSelector}
     * @see ReactiveX operators documentation: FlatMap
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final  Flowable concatMapIterable(final Function<? super T, ? extends Iterable<? extends U>> mapper, int prefetch) {
        ObjectHelper.requireNonNull(mapper, "mapper is null");
        ObjectHelper.verifyPositive(prefetch, "prefetch");
        return RxJavaPlugins.onAssembly(new FlowableFlattenIterable<T, U>(this, 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 Flowable} or the current inner {@code MaybeSource} fail.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure and honors
     *  the backpressure from downstream. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
History: 2.1.11 - experimental
     * @param <R> 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 Flowable instance
     * @see #concatMapMaybeDelayError(Function)
     * @see #concatMapMaybe(Function, int)
     * @since 2.2
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapMaybe(Function<? super T, ? extends MaybeSource<? extends R>> 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 Flowable} or the current inner {@code MaybeSource} fail.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure and honors
     *  the backpressure from downstream. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
History: 2.1.11 - experimental
     * @param <R> 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 Flowable instance
     * @see #concatMapMaybe(Function)
     * @see #concatMapMaybeDelayError(Function, boolean, int)
     * @since 2.2
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapMaybe(Function<? super T, ? extends MaybeSource<? extends R>> mapper, int prefetch) {
        ObjectHelper.requireNonNull(mapper, "mapper is null");
        ObjectHelper.verifyPositive(prefetch, "prefetch");
        return RxJavaPlugins.onAssembly(new FlowableConcatMapMaybe<T, R>(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 Flowable} and all inner {@code MaybeSource}s terminate.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure and honors
     *  the backpressure from downstream. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
History: 2.1.11 - experimental
     * @param <R> 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 Flowable instance
     * @see #concatMapMaybe(Function)
     * @see #concatMapMaybeDelayError(Function, boolean)
     * @since 2.2
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapMaybeDelayError(Function<? super T, ? extends MaybeSource<? extends R>> 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 Flowable} and all inner {@code MaybeSource}s terminate.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure and honors
     *  the backpressure from downstream. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
History: 2.1.11 - experimental
     * @param <R> 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 Flowable} or any of the
     *                   inner {@code MaybeSource}s are delayed until all
     *                   of them terminate. If {@code false}, an error from this
     *                   {@code Flowable} is delayed until the current inner
     *                   {@code MaybeSource} terminates and only then is
     *                   it emitted to the downstream.
     * @return a new Flowable instance
     * @see #concatMapMaybe(Function, int)
     * @see #concatMapMaybeDelayError(Function, boolean, int)
     * @since 2.2
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapMaybeDelayError(Function<? super T, ? extends MaybeSource<? extends R>> 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 Flowable} and all inner {@code MaybeSource}s terminate.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure and honors
     *  the backpressure from downstream. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
History: 2.1.11 - experimental
     * @param <R> 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 Flowable} or any of the
     *                   inner {@code MaybeSource}s are delayed until all
     *                   of them terminate. If {@code false}, an error from this
     *                   {@code Flowable} 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 Flowable instance
     * @see #concatMapMaybe(Function, int)
     * @since 2.2
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapMaybeDelayError(Function<? super T, ? extends MaybeSource<? extends R>> mapper, boolean tillTheEnd, int prefetch) {
        ObjectHelper.requireNonNull(mapper, "mapper is null");
        ObjectHelper.verifyPositive(prefetch, "prefetch");
        return RxJavaPlugins.onAssembly(new FlowableConcatMapMaybe<T, R>(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 Flowable} or the current inner {@code SingleSource} fail.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure and honors
     *  the backpressure from downstream. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
History: 2.1.11 - experimental
     * @param <R> 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 Flowable instance
     * @see #concatMapSingleDelayError(Function)
     * @see #concatMapSingle(Function, int)
     * @since 2.2
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapSingle(Function<? super T, ? extends SingleSource<? extends R>> 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 Flowable} or the current inner {@code SingleSource} fail.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure and honors
     *  the backpressure from downstream. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
History: 2.1.11 - experimental
     * @param <R> 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 Flowable instance
     * @see #concatMapSingle(Function)
     * @see #concatMapSingleDelayError(Function, boolean, int)
     * @since 2.2
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapSingle(Function<? super T, ? extends SingleSource<? extends R>> mapper, int prefetch) {
        ObjectHelper.requireNonNull(mapper, "mapper is null");
        ObjectHelper.verifyPositive(prefetch, "prefetch");
        return RxJavaPlugins.onAssembly(new FlowableConcatMapSingle<T, R>(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 Flowable} and all inner {@code SingleSource}s terminate.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure and honors
     *  the backpressure from downstream. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
History: 2.1.11 - experimental
     * @param <R> 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 Flowable instance
     * @see #concatMapSingle(Function)
     * @see #concatMapSingleDelayError(Function, boolean)
     * @since 2.2
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapSingleDelayError(Function<? super T, ? extends SingleSource<? extends R>> 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 Flowable} and all inner {@code SingleSource}s terminate.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure and honors
     *  the backpressure from downstream. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
History: 2.1.11 - experimental
     * @param <R> 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 Flowable} or any of the
     *                   inner {@code SingleSource}s are delayed until all
     *                   of them terminate. If {@code false}, an error from this
     *                   {@code Flowable} is delayed until the current inner
     *                   {@code SingleSource} terminates and only then is
     *                   it emitted to the downstream.
     * @return a new Flowable instance
     * @see #concatMapSingle(Function, int)
     * @see #concatMapSingleDelayError(Function, boolean, int)
     * @since 2.2
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapSingleDelayError(Function<? super T, ? extends SingleSource<? extends R>> 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 Flowable} and all inner {@code SingleSource}s terminate.
     *

     *
     *

     *
Backpressure:

     *
The operator expects the upstream to support backpressure and honors
     *  the backpressure from downstream. If this {@code Flowable} violates the rule, the operator will
     *  signal a {@code MissingBackpressureException}.

     *
Scheduler:

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

     *

     *
History: 2.1.11 - experimental
     * @param <R> 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 Flowable} or any of the
     *                   inner {@code SingleSource}s are delayed until all
     *                   of them terminate. If {@code false}, an error from this
     *                   {@code Flowable} 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 Flowable instance
     * @see #concatMapSingle(Function, int)
     * @since 2.2
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Flowable<R> concatMapSingleDelayError(Function<? super T, ? extends SingleSource<? extends R>> mapper, boolean tillTheEnd, int prefetch) {
        ObjectHelper.requireNonNull(mapper, "mapper is null");
        ObjectHelper.verifyPositive(prefetch, "prefetch");
        return RxJavaPlugins.onAssembly(new FlowableConcatMapSingle<T, R>(this, mapper, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY, prefetch));
    }

    /**
     * Returns a Flowable that emits the items emitted from the current Publisher, then the next, one after
     * the other, without interleaving them.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream. Both this and the {@code other} {@code Publisher}s
     *  are expected to honor backpressure as well. If any of then violates this rule, it may throw an
     *  {@code IllegalStateException} when the source {@code Publisher} completes.

     *
Scheduler:

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

     *

     *
     * @param other
     *            a Publisher to be concatenated after the current
     * @return a Flowable that emits items emitted by the two source Publishers, one after the other,
     *         without interleaving them
     * @see ReactiveX operators documentation: Concat
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> concatWith(Publisher<? extends T> other) {
        ObjectHelper.requireNonNull(other, "other is null");
        return concat(this, other);
    }

    /**
     * Returns a {@code Flowable} that emits the items from this {@code Flowable} followed by the success item or error event
     * of the other {@link SingleSource}.
     *

     *
     *

     *
Backpressure:

     *
The operator supports backpressure and makes sure the success item of the other {@code SingleSource}
     *  is only emitted when there is a demand for it.

     *
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 Flowable} completes normally.
     * @return the new Flowable instance
     * @since 2.2
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> concatWith(@NonNull SingleSource<? extends T> other) {
        ObjectHelper.requireNonNull(other, "other is null");
        return RxJavaPlugins.onAssembly(new FlowableConcatWithSingle<T>(this, other));
    }

    /**
     * Returns a {@code Flowable} that emits the items from this {@code Flowable} followed by the success item or terminal events
     * of the other {@link MaybeSource}.
     *

     *
     *

     *
Backpressure:

     *
The operator supports backpressure and makes sure the success item of the other {@code MaybeSource}
     *  is only emitted when there is a demand for it.

     *
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 Flowable completes normally.
     * @return the new Flowable instance
     * @since 2.2
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> concatWith(@NonNull MaybeSource<? extends T> other) {
        ObjectHelper.requireNonNull(other, "other is null");
        return RxJavaPlugins.onAssembly(new FlowableConcatWithMaybe<T>(this, other));
    }

    /**
     * Returns a {@code Flowable} that emits items from this {@code Flowable} and when it completes normally, the
     * other {@link CompletableSource} is subscribed to and the returned {@code Flowable} emits its terminal events.
     *

     *
     *

     *
Backpressure:

     *
The operator does not interfere with backpressure between the current Flowable and the
     *  downstream consumer (i.e., acts as pass-through). When the operator switches to the
     *  {@code Completable}, backpressure is no longer present because {@code Completable} doesn't
     *  have items to apply backpressure to.

     *
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 Flowable} completes normally
     * @return the new Flowable instance
     * @since 2.2
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> concatWith(@NonNull CompletableSource other) {
        ObjectHelper.requireNonNull(other, "other is null");
        return RxJavaPlugins.onAssembly(new FlowableConcatWithCompletable<T>(this, other));
    }

    /**
     * Returns a Single that emits a Boolean that indicates whether the source Publisher emitted a
     * specified item.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
     *  unbounded manner (i.e., without applying backpressure).

     *
Scheduler:

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

     *

     *
     * @param item
     *            the item to search for in the emissions from the source Publisher
     * @return a Flowable that emits {@code true} if the specified item is emitted by the source Publisher,
     *         or {@code false} if the source Publisher completes without emitting that item
     * @see ReactiveX operators documentation: Contains
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Single<Boolean> contains(final Object item) {
        ObjectHelper.requireNonNull(item, "item is null");
        return any(Functions.equalsWith(item));
    }

    /**
     * Returns a Single that counts the total number of items emitted by the source Publisher and emits
     * this count as a 64-bit Long.
     *

     *
     *

     *
Backpressure:

     *
The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
     *  unbounded manner (i.e., without applying backpressure).

     *
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 Publisher as a
     *         64-bit Long item
     * @see ReactiveX operators documentation: Count
     * @see #count()
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Single<Long> count() {
        return RxJavaPlugins.onAssembly(new FlowableCountSingle<T>(this));
    }

    /**
     * Returns a Flowable that mirrors the source Publisher, except that it drops items emitted by the
     * source Publisher 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 Publisher} sequence,
     * which if takes too long, a newer item may arrive from the upstream, causing the
     * generated sequence to get cancelled, 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.
     *

     *
Backpressure:

     *
This operator does not support backpressure as it uses the {@code debounceSelector} to mark
     *      boundaries.

     *
Scheduler:

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

     *

     *
     * @param
     *            the debounce value type (ignored)
     * @param debounceIndicator
     *            function to retrieve a sequence that indicates the throttle duration for each item
     * @return a Flowable that omits items emitted by the source Publisher that are followed by another item
     *         within a computed debounce duration
     * @see ReactiveX operators documentation: Debounce
     * @see RxJava wiki: Backpressure
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final  Flowable<T> debounce(Function<? super T, ? extends Publisher> debounceIndicator) {
        ObjectHelper.requireNonNull(debounceIndicator, "debounceIndicator is null");
        return RxJavaPlugins.onAssembly(new FlowableDebounce<T, U>(this, debounceIndicator));
    }

    /**
     * Returns a Flowable that mirrors the source Publisher, except that it drops items emitted by the
     * source Publisher 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 Publisher faster than the timeout then no items
     * will be emitted by the resulting Publisher.
     *

     *
     *

     * 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.
     *

     *
Backpressure:

     *
This operator does not support backpressure as it uses time to control data flow.

     *
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
     *            Publisher in which that Publisher emits no items in order for the item to be emitted by the
     *            resulting Publisher
     * @param unit
     *            the unit of time for the specified {@code timeout}
     * @return a Flowable that filters out items from the source Publisher that are too quickly followed by
     *         newer items
     * @see ReactiveX operators documentation: Debounce
     * @see RxJava wiki: Backpressure
     * @see #throttleWithTimeout(long, TimeUnit)
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.COMPUTATION)
    public final Flowable<T> debounce(long timeout, TimeUnit unit) {
        return debounce(timeout, unit, Schedulers.computation());
    }

    /**
     * Returns a Flowable that mirrors the source Publisher, except that it drops items emitted by the
     * source Publisher 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 Publisher faster than the timeout then no items
     * will be emitted by the resulting Publisher.
     *

     *
     *

     * 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.
     *

     *
Backpressure:

     *
This operator does not support backpressure as it uses time to control data flow.

     *
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 Publisher 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 a Flowable that filters out items from the source Publisher that are too quickly followed by
     *         newer items
     * @see ReactiveX operators documentation: Debounce
     * @see RxJava wiki: Backpressure
     * @see #throttleWithTimeout(long, TimeUnit, Scheduler)
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.ERROR)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public final Flowable<T> debounce(long timeout, TimeUnit unit, Scheduler scheduler) {
        ObjectHelper.requireNonNull(unit, "unit is null");
        ObjectHelper.requireNonNull(scheduler, "scheduler is null");
        return RxJavaPlugins.onAssembly(new FlowableDebounceTimed<T>(this, timeout, unit, scheduler));
    }

    /**
     * Returns a Flowable that emits the items emitted by the source Publisher or a specified default item
     * if the source Publisher is empty.
     *

     *
     *

     *
Backpressure:

     *
If the source {@code Publisher} is empty, this operator is guaranteed to honor backpressure from downstream.
     *  If the source {@code Publisher} is non-empty, it is expected to honor backpressure as well; if the rule is violated,
     *  a {@code MissingBackpressureException} may get signaled somewhere downstream.
     *

     *
Scheduler:

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

     *

     *
     * @param defaultItem
     *            the item to emit if the source Publisher emits no items
     * @return a Flowable that emits either the specified default item if the source Publisher emits no
     *         items, or the items emitted by the source Publisher
     * @see ReactiveX operators documentation: DefaultIfEmpty
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> defaultIfEmpty(T defaultItem) {
        ObjectHelper.requireNonNull(defaultItem, "defaultItem is null");
        return switchIfEmpty(just(defaultItem));
    }

    /**
     * Returns a Flowable that delays the emissions of the source Publisher via another Publisher on a
     * per-item basis.
     *

     *
     *

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

     *
Backpressure:

     *
The operator doesn't interfere with the backpressure behavior which is determined by the source {@code Publisher}.
     *  All of the other {@code Publisher}s supplied by the function are consumed
     *  in an unbounded manner (i.e., no backpressure applied to them).

     *
Scheduler:

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

     *

     *
     * @param
     *            the item delay value type (ignored)
     * @param itemDelayIndicator
     *            a function that returns a Publisher for each item emitted by the source Publisher, which is
     *            then used to delay the emission of that item by the resulting Publisher until the Publisher
     *            returned from {@code itemDelay} emits an item
     * @return a Flowable that delays the emissions of the source Publisher via another Publisher on a
     *         per-item basis
     * @see ReactiveX operators documentation: Delay
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final  Flowable<T> delay(final Function<? super T, ? extends Publisher> itemDelayIndicator) {
        ObjectHelper.requireNonNull(itemDelayIndicator, "itemDelayIndicator is null");
        return flatMap(FlowableInternalHelper.itemDelay(itemDelayIndicator));
    }

    /**
     * Returns a Flowable that emits the items emitted by the source Publisher shifted forward in time by a
     * specified delay. Error notifications from the source Publisher are not delayed.
     *

     *
     *

     *
Backpressure:

     *
The operator doesn't interfere with the backpressure behavior which is determined by the source {@code Publisher}.

     *
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 Publisher shifted in time by the specified delay
     * @see ReactiveX operators documentation: Delay
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.COMPUTATION)
    public final Flowable<T> delay(long delay, TimeUnit unit) {
        return delay(delay, unit, Schedulers.computation(), false);
    }

    /**
     * Returns a Flowable that emits the items emitted by the source Publisher shifted forward in time by a
     * specified delay. If {@code delayError} is true, error notifications will also be delayed.
     *

     *
     *

     *
Backpressure:

     *
The operator doesn't interfere with the backpressure behavior which is determined by the source {@code Publisher}.

     *
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 signaled with the given delay, after all preceding normal elements,
     *            if false, the upstream exception is signaled immediately
     * @return the source Publisher shifted in time by the specified delay
     * @see ReactiveX operators documentation: Delay
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.COMPUTATION)
    public final Flowable<T> delay(long delay, TimeUnit unit, boolean delayError) {
        return delay(delay, unit, Schedulers.computation(), delayError);
    }

    /**
     * Returns a Flowable that emits the items emitted by the source Publisher shifted forward in time by a
     * specified delay. Error notifications from the source Publisher are not delayed.
     *

     *
     *

     *
Backpressure:

     *
The operator doesn't interfere with the backpressure behavior which is determined by the source {@code Publisher}.

     *
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 Publisher shifted in time by the specified delay
     * @see ReactiveX operators documentation: Delay
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public final Flowable<T> delay(long delay, TimeUnit unit, Scheduler scheduler) {
        return delay(delay, unit, scheduler, false);
    }

    /**
     * Returns a Flowable that emits the items emitted by the source Publisher shifted forward in time by a
     * specified delay. If {@code delayError} is true, error notifications will also be delayed.
     *

     *
     *

     *
Backpressure:

     *
The operator doesn't interfere with the backpressure behavior which is determined by the source {@code Publisher}.

     *
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 signaled with the given delay, after all preceding normal elements,
     *            if false, the upstream exception is signaled immediately
     * @return the source Publisher shifted in time by the specified delay
     * @see ReactiveX operators documentation: Delay
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public final Flowable<T> 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 FlowableDelay<T>(this, Math.max(0L, delay), unit, scheduler, delayError));
    }

    /**
     * Returns a Flowable that delays the subscription to and emissions from the source Publisher via another
     * Publisher on a per-item basis.
     *

     *
     *

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

     *
Backpressure:

     *
The operator doesn't interfere with the backpressure behavior which is determined by the source {@code Publisher}.
     *  All of the other {@code Publisher}s supplied by the functions are consumed
     *  in an unbounded manner (i.e., no backpressure applied to them).

     *
Scheduler:

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

     *

     *
     * @param
     *            the subscription delay value type (ignored)
     * @param <V>
     *            the item delay value type (ignored)
     * @param subscriptionIndicator
     *            a function that returns a Publisher that triggers the subscription to the source Publisher
     *            once it emits any item
     * @param itemDelayIndicator
     *            a function that returns a Publisher for each item emitted by the source Publisher, which is
     *            then used to delay the emission of that item by the resulting Publisher until the Publisher
     *            returned from {@code itemDelay} emits an item
     * @return a Flowable that delays the subscription and emissions of the source Publisher via another
     *         Publisher on a per-item basis
     * @see ReactiveX operators documentation: Delay
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final  Flowable<T> delay(Publisher subscriptionIndicator,
            Function<? super T, ? extends Publisher<V>> itemDelayIndicator) {
        return delaySubscription(subscriptionIndicator).delay(itemDelayIndicator);
    }

    /**
     * Returns a Flowable that delays the subscription to this Publisher
     * until the other Publisher emits an element or completes normally.
     *

     *
Backpressure:

     *
The operator forwards the backpressure requests to this Publisher once
     *  the subscription happens and requests Long.MAX_VALUE from the other Publisher

     *
Scheduler:

     *
This method does not operate by default on a particular {@link Scheduler}.

     *

     *
     * @param  the value type of the other Publisher, irrelevant
     * @param subscriptionIndicator the other Publisher that should trigger the subscription
     *        to this Publisher.
     * @return a Flowable that delays the subscription to this Publisher
     *         until the other Publisher emits an element or completes normally.
     * @since 2.0
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final  Flowable<T> delaySubscription(Publisher subscriptionIndicator) {
        ObjectHelper.requireNonNull(subscriptionIndicator, "subscriptionIndicator is null");
        return RxJavaPlugins.onAssembly(new FlowableDelaySubscriptionOther<T, U>(this, subscriptionIndicator));
    }

    /**
     * Returns a Flowable that delays the subscription to the source Publisher by a given amount of time.
     *

     *
     *

     *
Backpressure:

     *
The operator doesn't interfere with the backpressure behavior which is determined by the source {@code Publisher}.

     *
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 a Flowable that delays the subscription to the source Publisher by the given amount
     * @see ReactiveX operators documentation: Delay
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.COMPUTATION)
    public final Flowable<T> delaySubscription(long delay, TimeUnit unit) {
        return delaySubscription(delay, unit, Schedulers.computation());
    }

    /**
     * Returns a Flowable that delays the subscription to the source Publisher by a given amount of time,
     * both waiting and subscribing on a given Scheduler.
     *

     *
     *

     *
Backpressure:

     *
The operator doesn't interfere with the backpressure behavior which is determined by the source {@code Publisher}.

     *
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 a Flowable that delays the subscription to the source Publisher by a given
     *         amount, waiting and subscribing on the given Scheduler
     * @see ReactiveX operators documentation: Delay
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public final Flowable<T> delaySubscription(long delay, TimeUnit unit, Scheduler scheduler) {
        return delaySubscription(timer(delay, unit, scheduler));
    }

    /**
     * Returns a Flowable that reverses the effect of {@link #materialize materialize} by transforming the
     * {@link Notification} objects emitted by the source Publisher 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 Flowable cancels the flow and terminates with that type of terminal event:
     *

     * Flowable.just(createOnNext(1), createOnComplete(), createOnNext(2))
     * .doOnCancel(() -> System.out.println("Cancelled!"));
     * .dematerialize()
     * .test()
     * .assertResult(1);
     *

     * If the upstream signals {@code onError} or {@code onComplete} directly, the flow is terminated
     * with the same event.
     *

     * Flowable.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(Publisher)}
     * with a {@link #never()} source.
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
     *  backpressure behavior.

     *
Scheduler:

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

     *

     *
     * @param <T2> the output value type
     * @return a Flowable that emits the items and notifications embedded in the {@link Notification} objects
     *         emitted by the source Publisher
     * @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)
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @Deprecated
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public final <T2> Flowable<T2> dematerialize() {
        return RxJavaPlugins.onAssembly(new FlowableDematerialize(this, Functions.identity()));
    }

    /**
     * Returns a Flowable 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 Subscriber} 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<T>}. The Java language doesn't allow
     * limiting instance methods to a certain generic argument shape, therefore,
     * a function is used to ensure the conversion remains type safe.
     *

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

     * Flowable.just(createOnNext(1), createOnComplete(), createOnNext(2))
     * .doOnCancel(() -> System.out.println("Canceled!"));
     * .dematerialize(notification -> notification)
     * .test()
     * .assertResult(1);
     *

     * If the upstream signals {@code onError} or {@code onComplete} directly, the flow is terminated
     * with the same event.
     *

     * Flowable.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(Publisher)}
     * with a {@link #never()} source.
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
     *  backpressure behavior.

     *
Scheduler:

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

     *

     *
     * @param <R> the output value type
     * @param selector function that returns the upstream item and should return a Notification to signal
     * the corresponding {@code Subscriber} event to the downstream.
     * @return a Flowable that emits the items and notifications embedded in the {@link Notification} objects
     *         selected from the items emitted by the source Flowable
     * @see ReactiveX operators documentation: Dematerialize
     * @since 2.2.4 - experimental
     */
    @Experimental
    @CheckReturnValue
    @NonNull
    @SchedulerSupport(SchedulerSupport.NONE)
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    public final <R> Flowable<R> dematerialize(Function<? super T, Notification<R>> selector) {
        ObjectHelper.requireNonNull(selector, "selector is null");
        return RxJavaPlugins.onAssembly(new FlowableDematerialize<T, R>(this, selector));
    }

    /**
     * Returns a Flowable that emits all items emitted by the source Publisher 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
     * a 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 Subscriber 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.
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
     *  backpressure behavior.

     *
Scheduler:

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

     *

     *
     * @return a Flowable that emits only those items emitted by the source Publisher that are distinct from
     *         each other
     * @see ReactiveX operators documentation: Distinct
     * @see #distinct(Function)
     * @see #distinct(Function, Callable)
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> distinct() {
        return distinct((Function)Functions.identity(), Functions.<T>createHashSet());
    }

    /**
     * Returns a Flowable that emits all items emitted by the source Publisher 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
     * a 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 Subscriber 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.
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
     *  backpressure behavior.

     *
Scheduler:

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

     *

     *
     * @param <K> 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 a Flowable that emits those items emitted by the source Publisher that have distinct keys
     * @see ReactiveX operators documentation: Distinct
     * @see #distinct(Function, Callable)
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <K> Flowable<T> distinct(Function<? super T, K> keySelector) {
        return distinct(keySelector, Functions.<K>createHashSet());
    }

    /**
     * Returns a Flowable that emits all items emitted by the source Publisher 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
     * a meaningful comparison between the key objects as the default Java implementation only considers reference equivalence.
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
     *  backpressure behavior.

     *
Scheduler:

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

     *

     *
     * @param <K> 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 Subscriber to return a Collection subtype for holding the extracted
     *            keys and whose add() method's return indicates uniqueness.
     * @return a Flowable that emits those items emitted by the source Publisher that have distinct keys
     * @see ReactiveX operators documentation: Distinct
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <K> Flowable<T> distinct(Function<? super T, K> keySelector,
            Callable<? extends Collection<? super K>> collectionSupplier) {
        ObjectHelper.requireNonNull(keySelector, "keySelector is null");
        ObjectHelper.requireNonNull(collectionSupplier, "collectionSupplier is null");
        return RxJavaPlugins.onAssembly(new FlowableDistinct<T, K>(this, keySelector, collectionSupplier));
    }

    /**
     * Returns a Flowable that emits all items emitted by the source Publisher 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
     * a 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)))}.
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
     *  backpressure behavior.

     *
Scheduler:

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

     *

     *
     * @return a Flowable that emits those items from the source Publisher that are distinct from their
     *         immediate predecessors
     * @see ReactiveX operators documentation: Distinct
     * @see #distinctUntilChanged(BiPredicate)
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> distinctUntilChanged() {
        return distinctUntilChanged(Functions.identity());
    }

    /**
     * Returns a Flowable that emits all items emitted by the source Publisher 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
     * a 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)))}.
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
     *  backpressure behavior.

     *
Scheduler:

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

     *

     *
     * @param <K> 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 a Flowable that emits those items from the source Publisher whose keys are distinct from
     *         those of their immediate predecessors
     * @see ReactiveX operators documentation: Distinct
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <K> Flowable<T> distinctUntilChanged(Function<? super T, K> keySelector) {
        ObjectHelper.requireNonNull(keySelector, "keySelector is null");
        return RxJavaPlugins.onAssembly(new FlowableDistinctUntilChanged<T, K>(this, keySelector, ObjectHelper.equalsPredicate()));
    }

    /**
     * Returns a Flowable that emits all items emitted by the source Publisher 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)))}.
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
     *  backpressure behavior.

     *
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 a Flowable that emits those items from the source Publisher that are distinct from their
     *         immediate predecessors
     * @see ReactiveX operators documentation: Distinct
     * @since 2.0
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.FULL)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> distinctUntilChanged(BiPredicate<? super T, ? super T> comparer) {
        ObjectHelper.requireNonNull(comparer, "comparer is null");
        return RxJavaPlugins.onAssembly(new FlowableDistinctUntilChanged<T, T>(this, Functions.<T>identity(), comparer));
    }

    /**
     * Calls the specified action after this Flowable signals onError or onCompleted or gets canceled by
     * the downstream.
     *
In case of a race between a terminal event and a cancellation, 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.
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s backpressure
     *  behavior.

     *
Scheduler:

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

     *
Operator-fusion:

     *
This operator supports normal and conditional Subscribers as well as boundary-limited
     *  synchronous or asynchronous queue-fusion.

     *

     *
History: 2.0.1 - experimental
     * @param onFinally the action called when this Flowable terminates or gets canceled
     * @return the new Flowable instance
     * @since 2.1
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> doFinally(Action onFinally) {
        ObjectHelper.requireNonNull(onFinally, "onFinally is null");
        return RxJavaPlugins.onAssembly(new FlowableDoFinally<T>(this, onFinally));
    }

    /**
     * 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.
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s backpressure
     *  behavior.

     *
Scheduler:

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

     *
Operator-fusion:

     *
This operator supports normal and conditional Subscribers as well as 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 Flowable instance
     * @since 2.1
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> doAfterNext(Consumer<? super T> onAfterNext) {
        ObjectHelper.requireNonNull(onAfterNext, "onAfterNext is null");
        return RxJavaPlugins.onAssembly(new FlowableDoAfterNext<T>(this, onAfterNext));
    }

    /**
     * Registers an {@link Action} to be called when this Publisher invokes either
     * {@link Subscriber#onComplete onComplete} or {@link Subscriber#onError onError}.
     *

     *
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s backpressure
     *  behavior.

     *
Scheduler:

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

     *

     *
     * @param onAfterTerminate
     *            an {@link Action} to be invoked when the source Publisher finishes
     * @return a Flowable that emits the same items as the source Publisher, then invokes the
     *         {@link Action}
     * @see ReactiveX operators documentation: Do
     * @see #doOnTerminate(Action)
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> doAfterTerminate(Action onAfterTerminate) {
        return doOnEach(Functions.emptyConsumer(), Functions.emptyConsumer(),
                Functions.EMPTY_ACTION, onAfterTerminate);
    }

    /**
     * Calls the cancel {@code Action} if the downstream cancels 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 onCancel()} call,
     * sometimes as a {@code CompositeException} if there were multiple exceptions along the way.
     *

     * Note that terminal events trigger the action unless the {@code Publisher} is subscribed to via {@code unsafeSubscribe()}.
     *

     *
     *

     *
Backpressure:

     *
{@code doOnCancel} does not interact with backpressure requests or value delivery; backpressure
     *  behavior is preserved between its upstream and its downstream.

     *
Scheduler:

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

     *

     *
     * @param onCancel
     *            the action that gets called when the source {@code Publisher}'s Subscription is canceled
     * @return the source {@code Publisher} modified so as to call this Action when appropriate
     * @see ReactiveX operators documentation: Do
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> doOnCancel(Action onCancel) {
        return doOnLifecycle(Functions.emptyConsumer(), Functions.EMPTY_LONG_CONSUMER, onCancel);
    }

    /**
     * Modifies the source Publisher so that it invokes an action when it calls {@code onComplete}.
     *

     *
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
     *  backpressure behavior.

     *
Scheduler:

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

     *

     *
     * @param onComplete
     *            the action to invoke when the source Publisher calls {@code onComplete}
     * @return the source Publisher with the side-effecting behavior applied
     * @see ReactiveX operators documentation: Do
     */
    @CheckReturnValue
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> 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.
     *

     *
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
     *  backpressure behavior.

     *
Scheduler:

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

     *

     *
     * @return the source Publisher with the side-effecting behavior applied
     * @see ReactiveX operators documentation: Do
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    private Flowable<T> doOnEach(Consumer<? super T> onNext, Consumer<? super Throwable> 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 FlowableDoOnEach<T>(this, onNext, onError, onComplete, onAfterTerminate));
    }

    /**
     * Modifies the source Publisher so that it invokes an action for each item it emits.
     *

     *
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
     *  backpressure behavior.

     *
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 Publisher
     * @return the source Publisher with the side-effecting behavior applied
     * @see ReactiveX operators documentation: Do
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> doOnEach(final Consumer<? super Notification<T>> onNotification) {
        ObjectHelper.requireNonNull(onNotification, "onNotification is null");
        return doOnEach(
                Functions.notificationOnNext(onNotification),
                Functions.notificationOnError(onNotification),
                Functions.notificationOnComplete(onNotification),
                Functions.EMPTY_ACTION
            );
    }

    /**
     * Modifies the source Publisher so that it notifies a Subscriber for each item and terminal event it emits.
     *

     * In case the {@code onError} of the supplied Subscriber 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 Subscriber throws, the downstream will be
     * terminated and will receive this thrown exception.
     *

     *
     *

     *
Backpressure:

     *
The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
     *  backpressure behavior.

     *
Scheduler:

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

     *

     *
     * @param subscriber
     *            the Subscriber to be notified about onNext, onError and onComplete events on its
     *            respective methods before the actual downstream Subscriber gets notified.
     * @return the source Publisher with the side-effecting behavior applied
     * @see ReactiveX operators documentation: Do
     */
    @CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.PASS_THROUGH)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final Flowable<T> doOnEach(final Subscriber<? super T> subscriber) {
        ObjectHelper.requireNonNull(subscriber, "subscriber is null");
        return doOnEach(
                FlowableInternalHelper.subscriberOnNext(subscriber),
                FlowableInternalHelper.subscriberOnError(subscriber),
                FlowableInternalHelper.subscriberOnComplete(subscriber),
                Functions.EMPTY_ACTION);
    }

    /**
     * Modifies the source Publisher 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