Skip to content

Commit 141a9f8

Browse files
added where operation to Observable
1 parent 6152588 commit 141a9f8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import rx.operators.OperationDefer;
4141
import rx.operators.OperationDematerialize;
4242
import rx.operators.OperationFilter;
43+
import rx.operators.OperationWhere;
4344
import rx.operators.OperationMap;
4445
import rx.operators.OperationMaterialize;
4546
import rx.operators.OperationMerge;
@@ -722,6 +723,21 @@ public Boolean call(T t1) {
722723
});
723724
}
724725

726+
/**
727+
* Filters an Observable by discarding any of its emissions that do not meet some test.
728+
* <p>
729+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/filter.png">
730+
*
731+
* @param that
732+
* the Observable to filter
733+
* @param predicate
734+
* a function that evaluates the items emitted by the source Observable, returning <code>true</code> if they pass the filter
735+
* @return an Observable that emits only those items in the original Observable that the filter evaluates as true
736+
*/
737+
public static <T> Observable<T> where(Observable<T> that, Func1<T, Boolean> predicate) {
738+
return _create(OperationWhere.where(that, predicate));
739+
}
740+
725741
/**
726742
* Converts an {@link Iterable} sequence to an Observable sequence.
727743
*
@@ -2419,6 +2435,21 @@ public Boolean call(T t1) {
24192435
});
24202436
}
24212437

2438+
/**
2439+
* Filters an Observable by discarding any of its emissions that do not meet some test.
2440+
* <p>
2441+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/filter.png">
2442+
*
2443+
* @param predicate
2444+
* a function that evaluates the items emitted by the source Observable, returning
2445+
* <code>true</code> if they pass the filter
2446+
* @return an Observable that emits only those items in the original Observable that the filter
2447+
* evaluates as <code>true</code>
2448+
*/
2449+
public Observable<T> where(Func1<T, Boolean> predicate) {
2450+
return where(this, predicate);
2451+
}
2452+
24222453
/**
24232454
* Returns the last element of an observable sequence with a specified source.
24242455
*

0 commit comments

Comments
 (0)