src/main/java/io/reactivex/Observable.java
@CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Single<R> reduce(R seed, BiFunction<R, ? super T, R> reducer) {
        ObjectHelper.requireNonNull(seed, "seed is null");
        ObjectHelper.requireNonNull(reducer, "reducer is null");
        return RxJavaPlugins.onAssembly(new ObservableReduceSeedSingle<T, R>(this, seed, reducer));
    }
@CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <R> Single<R> reduce(R seed, BiFunction<R, ? super T, R> reducer) {
        ObjectHelper.requireNonNull(seed, "seed is null");
        ObjectHelper.requireNonNull(reducer, "reducer is null");
        return RxJavaPlugins.onAssembly(new ObservableReduceSeedSingle<T, R>(this, seed, reducer));
    }
@ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final < R > Single < R > reduce ( R seed , BiFunction < R , ? super T , R > reducer ) { ObjectHelper . requireNonNull ( seed , "seed is null" ) ; ObjectHelper . requireNonNull ( reducer , "reducer is null" ) ; return RxJavaPlugins . onAssembly ( new ObservableReduceSeedSingle < T , R > ( this , seed , reducer ) ) ; }
Returns a Single that applies a specified accumulator function to the first item emitted by a source
ObservableSource and a specified seed value, then feeds the result of that function along with the second item
emitted by an ObservableSource into the same function, and so on until all items have been emitted by the
finite source ObservableSource, emitting the final result from the final call to your function as its sole item.
<p>
<img width="640" height="325" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/reduceSeed.o.png" alt="">
<p>
This technique, which is called "reduce" here, is sometimes called "aggregate," "fold," "accumulate,"
"compress," or "inject" in other programming contexts. Groovy, for instance, has an {@code inject} method
that does a similar operation on lists.
<p>
Note that the {@code seed} is shared among all subscribers to the resulting ObservableSource
and may cause problems if it is mutable. To make sure each subscriber gets its own value, defer
the application of this operator via {@link #defer(Callable)}:
<pre><code>
ObservableSource&lt;T&gt; source = ...
Single.defer(() -&gt; source.reduce(new ArrayList&lt;&gt;(), (list, item) -&gt; list.add(item)));

// alternatively, by using compose to stay fluent

source.compose(o -&gt;
Observable.defer(() -&gt; o.reduce(new ArrayList&lt;&gt;(), (list, item) -&gt; list.add(item)).toObservable())
).firstOrError();

// or, by using reduceWith instead of reduce

source.reduceWith(() -&gt; new ArrayList&lt;&gt;(), (list, item) -&gt; list.add(item)));
</code></pre>
<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 reduce} does not operate by default on a particular {@link Scheduler}.</dd>
</dl>

@param <R> the accumulator and output value type
@param seed
the initial (seed) accumulator value
@param reducer
an accumulator function to be invoked on each item emitted by the source ObservableSource, the
result of which will be used in the next accumulator call
@return a Single that emits a single item that is the result of accumulating the output from the
items emitted by the source ObservableSource
@see <a href="http://reactivex.io/documentation/operators/reduce.html">ReactiveX operators documentation: Reduce</a>
@see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
@see #reduceWith(Callable, BiFunction)
Returns a Single that applies a specified accumulator function to the first item emitted by a source ObservableSource and a specified seed value then feeds the result of that function along with the second item emitted by an ObservableSource into the same function and so on until all items have been emitted by the finite source ObservableSource emitting the final result from the final call to your function as its sole item . <p > <img width = 640 height = 325 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / reduceSeed . o . png alt = > <p > This technique which is called reduce here is sometimes called aggregate fold accumulate compress or inject in other programming contexts . Groovy for instance has an { @code inject } method that does a similar operation on lists . <p > Note that the { @code seed } is shared among all subscribers to the resulting ObservableSource and may cause problems if it is mutable . To make sure each subscriber gets its own value defer the application of this operator via { @link #defer ( Callable ) } : <pre > <code > ObservableSource&lt ; T&gt ; source = ... Single . defer (( ) - &gt ; source . reduce ( new ArrayList&lt ; &gt ; () ( list item ) - &gt ; list . add ( item ))) ;