Skip to content

Commit

Permalink
Javadoc: explain that distinctUntilChanged requires non-mutating data…
Browse files Browse the repository at this point in the history
… to work as expected (#6311)

* Javadoc : Explain distinctUntilChanged requires non-mutating data type in flow(Observable)

Add few tests for scenarios related to mutable data type flow in distinctUntilChanged() methods for Observable

* Javadoc : Explain distinctUntilChanged requires non-mutating data type in flow(Flowable)

Add few tests for scenarios related to mutable data type flow in distinctUntilChanged() methods for Flowable

* Remove tests and fix typo in javadoc
  • Loading branch information
punitda authored and akarnokd committed Nov 16, 2018
1 parent f800b30 commit 7058126
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/io/reactivex/Flowable.java
Original file line number Diff line number Diff line change
Expand Up @@ -8740,6 +8740,13 @@ public final <K> Flowable<T> distinct(Function<? super T, K> keySelector,
* <p>
* Note that the operator always retains the latest item from upstream regardless of the comparison result
* and uses it in the next comparison with the next upstream item.
* <p>
* Note that if element type {@code T} in the flow is mutable, the comparison of the previous and current
* item may yield unexpected results if the items are mutated externally. Common cases are mutable
* {@code CharSequence}s or {@code List}s where the objects will actually have the same
* references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same.
* To avoid such situation, it is recommended that mutable data is converted to an immutable one,
* for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
Expand Down Expand Up @@ -8776,6 +8783,13 @@ public final Flowable<T> distinctUntilChanged() {
* <p>
* Note that the operator always retains the latest key from upstream regardless of the comparison result
* and uses it in the next comparison with the next key derived from the next upstream item.
* <p>
* Note that if element type {@code T} in the flow is mutable, the comparison of the previous and current
* item may yield unexpected results if the items are mutated externally. Common cases are mutable
* {@code CharSequence}s or {@code List}s where the objects will actually have the same
* references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same.
* To avoid such situation, it is recommended that mutable data is converted to an immutable one,
* for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
Expand Down Expand Up @@ -8808,6 +8822,13 @@ public final <K> Flowable<T> distinctUntilChanged(Function<? super T, K> keySele
* <p>
* Note that the operator always retains the latest item from upstream regardless of the comparison result
* and uses it in the next comparison with the next upstream item.
* <p>
* Note that if element type {@code T} in the flow is mutable, the comparison of the previous and current
* item may yield unexpected results if the items are mutated externally. Common cases are mutable
* {@code CharSequence}s or {@code List}s where the objects will actually have the same
* references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same.
* To avoid such situation, it is recommended that mutable data is converted to an immutable one,
* for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/io/reactivex/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7824,6 +7824,13 @@ public final <K> Observable<T> distinct(Function<? super T, K> keySelector, Call
* <p>
* Note that the operator always retains the latest item from upstream regardless of the comparison result
* and uses it in the next comparison with the next upstream item.
* <p>
* Note that if element type {@code T} in the flow is mutable, the comparison of the previous and current
* item may yield unexpected results if the items are mutated externally. Common cases are mutable
* {@code CharSequence}s or {@code List}s where the objects will actually have the same
* references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same.
* To avoid such situation, it is recommended that mutable data is converted to an immutable one,
* for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.</dd>
Expand Down Expand Up @@ -7856,6 +7863,13 @@ public final Observable<T> distinctUntilChanged() {
* <p>
* Note that the operator always retains the latest key from upstream regardless of the comparison result
* and uses it in the next comparison with the next key derived from the next upstream item.
* <p>
* Note that if element type {@code T} in the flow is mutable, the comparison of the previous and current
* item may yield unexpected results if the items are mutated externally. Common cases are mutable
* {@code CharSequence}s or {@code List}s where the objects will actually have the same
* references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same.
* To avoid such situation, it is recommended that mutable data is converted to an immutable one,
* for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.</dd>
Expand Down Expand Up @@ -7884,6 +7898,13 @@ public final <K> Observable<T> distinctUntilChanged(Function<? super T, K> keySe
* <p>
* Note that the operator always retains the latest item from upstream regardless of the comparison result
* and uses it in the next comparison with the next upstream item.
* <p>
* Note that if element type {@code T} in the flow is mutable, the comparison of the previous and current
* item may yield unexpected results if the items are mutated externally. Common cases are mutable
* {@code CharSequence}s or {@code List}s where the objects will actually have the same
* references when they are modified and {@code distinctUntilChanged} will evaluate subsequent items as same.
* To avoid such situation, it is recommended that mutable data is converted to an immutable one,
* for example using `map(CharSequence::toString)` or `map(Collections::unmodifiableList)`.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.</dd>
Expand Down

0 comments on commit 7058126

Please sign in to comment.