Skip to content

Commit ea90264

Browse files
author
Joachim Hofer
committed
Added distinctUntilChanged member methods to Observable
1 parent 1d183a3 commit ea90264

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import rx.operators.OperationConcat;
3737
import rx.operators.OperationDefer;
3838
import rx.operators.OperationDematerialize;
39+
import rx.operators.OperationDistinctUntilChanged;
3940
import rx.operators.OperationFilter;
4041
import rx.operators.OperationFinally;
4142
import rx.operators.OperationFirstOrDefault;
@@ -2925,6 +2926,30 @@ public Observable<T> filter(Func1<? super T, Boolean> predicate) {
29252926
return create(OperationFilter.filter(this, predicate));
29262927
}
29272928

2929+
/**
2930+
* Returns an Observable that forwards all sequentially distinct items emitted from the source Observable.
2931+
*
2932+
* @return an Observable of sequentially distinct items
2933+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229494%28v=vs.103%29.aspx">MSDN: Observable.distinctUntilChanged</a>
2934+
*/
2935+
public Observable<T> distinctUntilChanged() {
2936+
return create(OperationDistinctUntilChanged.distinctUntilChanged(this));
2937+
}
2938+
2939+
/**
2940+
* Returns an Observable that forwards all items emitted from the source Observable that are sequentially distinct according to
2941+
* a key selector function.
2942+
*
2943+
* @param keySelector
2944+
* a function that projects an emitted item to a key value which is used for deciding whether an item is sequentially
2945+
* distinct from another one or not
2946+
* @return an Observable of sequentially distinct items
2947+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229508%28v=vs.103%29.aspx">MSDN: Observable.distinctUntilChanged</a>
2948+
*/
2949+
public <U> Observable<T> distinctUntilChanged(Func1<? super T, ? extends U> keySelector) {
2950+
return create(OperationDistinctUntilChanged.distinctUntilChanged(this, keySelector));
2951+
}
2952+
29282953
/**
29292954
* Registers an {@link Action0} to be called when this Observable invokes {@link Observer#onCompleted onCompleted} or {@link Observer#onError onError}.
29302955
* <p>

0 commit comments

Comments
 (0)