@@ -8922,18 +8922,22 @@ public final Maybe<T> reduce(BiFunction<T, T, T> reducer) {
8922
8922
* "compress," or "inject" in other programming contexts. Groovy, for instance, has an {@code inject} method
8923
8923
* that does a similar operation on lists.
8924
8924
* <p>
8925
- * Note that the {@code initialValue } is shared among all subscribers to the resulting ObservableSource
8925
+ * Note that the {@code seed } is shared among all subscribers to the resulting ObservableSource
8926
8926
* and may cause problems if it is mutable. To make sure each subscriber gets its own value, defer
8927
8927
* the application of this operator via {@link #defer(Callable)}:
8928
8928
* <pre><code>
8929
8929
* ObservableSource<T> source = ...
8930
- * Observable .defer(() -> source.reduce(new ArrayList<>(), (list, item) -> list.add(item)));
8930
+ * Single .defer(() -> source.reduce(new ArrayList<>(), (list, item) -> list.add(item)));
8931
8931
*
8932
8932
* // alternatively, by using compose to stay fluent
8933
8933
*
8934
8934
* source.compose(o ->
8935
- * Observable.defer(() -> o.reduce(new ArrayList<>(), (list, item) -> list.add(item)))
8936
- * );
8935
+ * Observable.defer(() -> o.reduce(new ArrayList<>(), (list, item) -> list.add(item)).toObservable())
8936
+ * ).firstOrError();
8937
+ *
8938
+ * // or, by using reduceWith instead of reduce
8939
+ *
8940
+ * source.reduceWith(() -> new ArrayList<>(), (list, item) -> list.add(item)));
8937
8941
* </code></pre>
8938
8942
* <dl>
8939
8943
* <dt><b>Scheduler:</b></dt>
@@ -8950,6 +8954,7 @@ public final Maybe<T> reduce(BiFunction<T, T, T> reducer) {
8950
8954
* items emitted by the source ObservableSource
8951
8955
* @see <a href="http://reactivex.io/documentation/operators/reduce.html">ReactiveX operators documentation: Reduce</a>
8952
8956
* @see <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Wikipedia: Fold (higher-order function)</a>
8957
+ * @see #reduceWith(Callable, BiFunction)
8953
8958
*/
8954
8959
@CheckReturnValue
8955
8960
@SchedulerSupport(SchedulerSupport.NONE)
@@ -8961,29 +8966,16 @@ public final <R> Single<R> reduce(R seed, BiFunction<R, ? super T, R> reducer) {
8961
8966
8962
8967
/**
8963
8968
* Returns a Single that applies a specified accumulator function to the first item emitted by a source
8964
- * ObservableSource and a specified seed value, then feeds the result of that function along with the second item
8965
- * emitted by an ObservableSource into the same function, and so on until all items have been emitted by the
8966
- * source ObservableSource, emitting the final result from the final call to your function as its sole item.
8969
+ * ObservableSource and a seed value derived from calling a specified seedSupplier, then feeds the result
8970
+ * of that function along with the second item emitted by an ObservableSource into the same function,
8971
+ * and so on until all items have been emitted by the source ObservableSource, emitting the final result
8972
+ * from the final call to your function as its sole item.
8967
8973
* <p>
8968
8974
* <img width="640" height="325" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/reduceSeed.2.png" alt="">
8969
8975
* <p>
8970
8976
* This technique, which is called "reduce" here, is sometimes called "aggregate," "fold," "accumulate,"
8971
8977
* "compress," or "inject" in other programming contexts. Groovy, for instance, has an {@code inject} method
8972
8978
* that does a similar operation on lists.
8973
- * <p>
8974
- * Note that the {@code initialValue} is shared among all subscribers to the resulting ObservableSource
8975
- * and may cause problems if it is mutable. To make sure each subscriber gets its own value, defer
8976
- * the application of this operator via {@link #defer(Callable)}:
8977
- * <pre><code>
8978
- * ObservableSource<T> source = ...
8979
- * Observable.defer(() -> source.reduce(new ArrayList<>(), (list, item) -> list.add(item)));
8980
- *
8981
- * // alternatively, by using compose to stay fluent
8982
- *
8983
- * source.compose(o ->
8984
- * Observable.defer(() -> o.reduce(new ArrayList<>(), (list, item) -> list.add(item)))
8985
- * );
8986
- * </code></pre>
8987
8979
* <dl>
8988
8980
* <dt><b>Scheduler:</b></dt>
8989
8981
* <dd>{@code reduceWith} does not operate by default on a particular {@link Scheduler}.</dd>
0 commit comments