src/main/java/io/reactivex/Observable.java
@CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <U> Single<U> collect(Callable<? extends U> initialValueSupplier, BiConsumer<? super U, ? super T> collector) {
        ObjectHelper.requireNonNull(initialValueSupplier, "initialValueSupplier is null");
        ObjectHelper.requireNonNull(collector, "collector is null");
        return RxJavaPlugins.onAssembly(new ObservableCollectSingle<T, U>(this, initialValueSupplier, collector));
    }
@CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <U> Single<U> collect(Callable<? extends U> initialValueSupplier, BiConsumer<? super U, ? super T> collector) {
        ObjectHelper.requireNonNull(initialValueSupplier, "initialValueSupplier is null");
        ObjectHelper.requireNonNull(collector, "collector is null");
        return RxJavaPlugins.onAssembly(new ObservableCollectSingle<T, U>(this, initialValueSupplier, collector));
    }
@ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final < U > Single < U > collect ( Callable < ? extends U > initialValueSupplier , BiConsumer < ? super U , ? super T > collector ) { ObjectHelper . requireNonNull ( initialValueSupplier , "initialValueSupplier is null" ) ; ObjectHelper . requireNonNull ( collector , "collector is null" ) ; return RxJavaPlugins . onAssembly ( new ObservableCollectSingle < T , U > ( this , initialValueSupplier , collector ) ) ; }
Collects items emitted by the finite source ObservableSource into a single mutable data structure and returns
a Single that emits this structure.
<p>
<img width="640" height="330" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/collect.2.png" alt="">
<p>
This is a simplified version of {@code reduce} that does not need to return the state on each pass.
<p>
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}.
<dl>
<dt><b>Scheduler:</b></dt>
<dd>{@code collect} does not operate by default on a particular {@link Scheduler}.</dd>
</dl>

@param <U> the accumulator and output type
@param initialValueSupplier
the mutable data structure that will collect the items
@param collector
a function that accepts the {@code state} and an emitted item, and modifies {@code state}
accordingly
@return a Single that emits the result of collecting the values emitted by the source ObservableSource
into a single mutable data structure
@see <a href="http://reactivex.io/documentation/operators/reduce.html">ReactiveX operators documentation: Reduce</a>
Collects items emitted by the finite source ObservableSource into a single mutable data structure and returns a Single that emits this structure . <p > <img width = 640 height = 330 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / collect . 2 . png alt = > <p > This is a simplified version of { @code reduce } that does not need to return the state on each pass . <p > 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 } . <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { @code collect } does not operate by default on a particular { @link Scheduler } . < / dd > < / dl >