From 141a9f8108f2a7249734cf2611e6ad71e1503c39 Mon Sep 17 00:00:00 2001 From: prabirshrestha Date: Wed, 13 Mar 2013 19:01:15 -0400 Subject: [PATCH] added where operation to Observable --- rxjava-core/src/main/java/rx/Observable.java | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/rxjava-core/src/main/java/rx/Observable.java b/rxjava-core/src/main/java/rx/Observable.java index c125682bd0..5d11c7b9ed 100644 --- a/rxjava-core/src/main/java/rx/Observable.java +++ b/rxjava-core/src/main/java/rx/Observable.java @@ -40,6 +40,7 @@ import rx.operators.OperationDefer; import rx.operators.OperationDematerialize; import rx.operators.OperationFilter; +import rx.operators.OperationWhere; import rx.operators.OperationMap; import rx.operators.OperationMaterialize; import rx.operators.OperationMerge; @@ -722,6 +723,21 @@ public Boolean call(T t1) { }); } + /** + * Filters an Observable by discarding any of its emissions that do not meet some test. + *

+ * + * + * @param that + * the Observable to filter + * @param predicate + * a function that evaluates the items emitted by the source Observable, returning true if they pass the filter + * @return an Observable that emits only those items in the original Observable that the filter evaluates as true + */ + public static Observable where(Observable that, Func1 predicate) { + return _create(OperationWhere.where(that, predicate)); + } + /** * Converts an {@link Iterable} sequence to an Observable sequence. * @@ -2419,6 +2435,21 @@ public Boolean call(T t1) { }); } + /** + * Filters an Observable by discarding any of its emissions that do not meet some test. + *

+ * + * + * @param predicate + * a function that evaluates the items emitted by the source Observable, returning + * true if they pass the filter + * @return an Observable that emits only those items in the original Observable that the filter + * evaluates as true + */ + public Observable where(Func1 predicate) { + return where(this, predicate); + } + /** * Returns the last element of an observable sequence with a specified source. *