diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 992653169c..c49689484c 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -10723,18 +10723,22 @@ public final Maybe reduce(BiFunction reducer) { * "compress," or "inject" in other programming contexts. Groovy, for instance, has an {@code inject} method * that does a similar operation on lists. *

- * Note that the {@code initialValue} is shared among all subscribers to the resulting Publisher + * Note that the {@code seed} is shared among all subscribers to the resulting Publisher * 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)}: *


      * Publisher<T> source = ...
-     * Publisher.defer(() -> source.reduce(new ArrayList<>(), (list, item) -> list.add(item)));
+     * Single.defer(() -> source.reduce(new ArrayList<>(), (list, item) -> list.add(item)));
      *
      * // alternatively, by using compose to stay fluent
      *
      * source.compose(o ->
-     *     Publisher.defer(() -> o.reduce(new ArrayList<>(), (list, item) -> list.add(item)))
-     * );
+     *     Flowable.defer(() -> o.reduce(new ArrayList<>(), (list, item) -> list.add(item)).toFlowable())
+     * ).firstOrError();
+     *
+     * // or, by using reduceWith instead of reduce
+     *
+     * source.reduceWith(() -> new ArrayList<>(), (list, item) -> list.add(item)));
      * 
*
*
Backpressure:
@@ -10754,6 +10758,7 @@ public final Maybe reduce(BiFunction reducer) { * items emitted by the source Publisher * @see ReactiveX operators documentation: Reduce * @see Wikipedia: Fold (higher-order function) + * @see #reduceWith(Callable, BiFunction) */ @CheckReturnValue @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @@ -10766,29 +10771,16 @@ public final Single reduce(R seed, BiFunction reducer) { /** * Returns a Flowable that applies a specified accumulator function to the first item emitted by a source - * Publisher and a specified seed value, then feeds the result of that function along with the second item - * emitted by a Publisher into the same function, and so on until all items have been emitted by the - * source Publisher, emitting the final result from the final call to your function as its sole item. + * Publisher and a seed value derived from calling a specified seedSupplier, then feeds the result + * of that function along with the second item emitted by a Publisher into the same function, and so on until + * all items have been emitted by the source Publisher, emitting the final result from the final call to your + * function as its sole item. *

* *

* This technique, which is called "reduce" here, is sometimes called "aggregate," "fold," "accumulate," * "compress," or "inject" in other programming contexts. Groovy, for instance, has an {@code inject} method * that does a similar operation on lists. - *

- * Note that the {@code initialValue} is shared among all subscribers to the resulting Publisher - * 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)}: - *


-     * Publisher<T> source = ...
-     * Publisher.defer(() -> source.reduce(new ArrayList<>(), (list, item) -> list.add(item)));
-     *
-     * // alternatively, by using compose to stay fluent
-     *
-     * source.compose(o ->
-     *     Publisher.defer(() -> o.reduce(new ArrayList<>(), (list, item) -> list.add(item)))
-     * );
-     * 
*
*
Backpressure:
*
The operator honors backpressure of its downstream consumer and consumes the diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index a0e945af7f..c28c846d26 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -8922,18 +8922,22 @@ public final Maybe reduce(BiFunction reducer) { * "compress," or "inject" in other programming contexts. Groovy, for instance, has an {@code inject} method * that does a similar operation on lists. *

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


      * ObservableSource<T> source = ...
-     * Observable.defer(() -> source.reduce(new ArrayList<>(), (list, item) -> list.add(item)));
+     * Single.defer(() -> source.reduce(new ArrayList<>(), (list, item) -> list.add(item)));
      *
      * // alternatively, by using compose to stay fluent
      *
      * source.compose(o ->
-     *     Observable.defer(() -> o.reduce(new ArrayList<>(), (list, item) -> list.add(item)))
-     * );
+     *     Observable.defer(() -> o.reduce(new ArrayList<>(), (list, item) -> list.add(item)).toObservable())
+     * ).firstOrError();
+     *
+     * // or, by using reduceWith instead of reduce
+     *
+     * source.reduceWith(() -> new ArrayList<>(), (list, item) -> list.add(item)));
      * 
*
*
Scheduler:
@@ -8950,6 +8954,7 @@ public final Maybe reduce(BiFunction reducer) { * items emitted by the source ObservableSource * @see ReactiveX operators documentation: Reduce * @see Wikipedia: Fold (higher-order function) + * @see #reduceWith(Callable, BiFunction) */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @@ -8961,29 +8966,16 @@ public final Single reduce(R seed, BiFunction 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 - * source ObservableSource, emitting the final result from the final call to your function as its sole item. + * ObservableSource and a seed value derived from calling a specified seedSupplier, then feeds the result + * of that function along with the second item emitted by an ObservableSource into the same function, + * and so on until all items have been emitted by the source ObservableSource, emitting the final result + * from the final call to your function as its sole item. *

* *

* This technique, which is called "reduce" here, is sometimes called "aggregate," "fold," "accumulate," * "compress," or "inject" in other programming contexts. Groovy, for instance, has an {@code inject} method * that does a similar operation on lists. - *

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


-     * ObservableSource<T> source = ...
-     * Observable.defer(() -> source.reduce(new ArrayList<>(), (list, item) -> list.add(item)));
-     *
-     * // alternatively, by using compose to stay fluent
-     *
-     * source.compose(o ->
-     *     Observable.defer(() -> o.reduce(new ArrayList<>(), (list, item) -> list.add(item)))
-     * );
-     * 
*
*
Scheduler:
*
{@code reduceWith} does not operate by default on a particular {@link Scheduler}.