Skip to content

1.x: scan & reduce give javadoc about unsharing the initialValue #4063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7201,8 +7201,8 @@ public final Observable<T> rebatchRequests(int n) {
* that does a similar operation on lists.
* <dl>
* <dt><b>Backpressure Support:</b></dt>
* <dd>This operator does not support backpressure because by intent it will receive all values and reduce
* them to a single {@code onNext}.</dd>
* <dd>The operator honors backpressure of its downstream consumer and consumes the
* upstream source in unbounded mode.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code reduce} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
Expand Down Expand Up @@ -7238,10 +7238,24 @@ public final Observable<T> reduce(Func2<T, T, T> accumulator) {
* 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 initialValue} is shared among all subscribers to the resulting Observable
* 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(Func0)}:
* <pre><code>
* Observable&lt;T> source = ...
* Observable.defer(() -> source.reduce(new ArrayList&lt;>(), (list, item) -> list.add(item)));
*
* // alternatively, by using compose to stay fluent
*
* source.compose(o ->
* Observable.defer(() -> o.reduce(new ArrayList&lt;>(), (list, item) -> list.add(item)))
* );
* </code></pre>
* <dl>
* <dt><b>Backpressure Support:</b></dt>
* <dd>This operator does not support backpressure because by intent it will receive all values and reduce
* them to a single {@code onNext}.</dd>
* <dd>The operator honors backpressure of its downstream consumer and consumes the
* upstream source in unbounded mode.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code reduce} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
Expand Down Expand Up @@ -8167,7 +8181,23 @@ public final Observable<T> scan(Func2<T, T, T> accumulator) {
* <p>
* Note that the Observable that results from this method will emit {@code initialValue} as its first
* emitted item.
* <p>
* Note that the {@code initialValue} is shared among all subscribers to the resulting Observable
* 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(Func0)}:
* <pre><code>
* Observable&lt;T> source = ...
* Observable.defer(() -> source.scan(new ArrayList&lt;>(), (list, item) -> list.add(item)));
*
* // alternatively, by using compose to stay fluent
*
* source.compose(o ->
* Observable.defer(() -> o.scan(new ArrayList&lt;>(), (list, item) -> list.add(item)))
* );
* </code></pre>
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator honors backpressure.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code scan} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
Expand Down