Observable { @NonNull public Observable<T> filter(@NonNull final Predicate<T> pred) { return flatMap(new Function<T, Observable<T>>() { @NonNull @Override public Observable<T> apply(@NonNull T value) { if (pred.apply(value)) { return just(value); } else { return empty(); } } }); } protected  Observable(); protected  Observable(@Nullable Function<Observer<T>, Subscription> onSubscribe); @NonNull static Observable<T> create(@NonNull Function<Observer<T>, Subscription> func); @NonNull static Observable<T> just(@NonNull final T value); @NonNull static Observable<T> empty(); @NonNull static Observable<T> never(); @NonNull static Observable<T> error(@NonNull final Exception e); @NonNull static Observable<T> from(@NonNull final Collection<T> collection); @NonNull Subscription subscribe(@NonNull Observer<T> observer); @NonNull Observable<R> flatMap(@NonNull final Function<T, Observable<R>> func); @NonNull Observable<R> map(@NonNull final Function<T, R> func); @NonNull Observable<T> filter(@NonNull final Predicate<T> pred); @NonNull Observable<T> distinctUntilChanged(); @NonNull Observable<T> defaultIfEmpty(@NonNull final T defaultValue); @NonNull Observable<T> observeOn(@NonNull final Scheduler scheduler); @NonNull Observable<T> subscribeOn(@NonNull final Scheduler scheduler); @NonNull static Observable<T> merge(@NonNull final Observable<T> lh, @NonNull final Observable<T> rh); @NonNull static Observable<T> merge(@NonNull Collection<Observable<T>> observables); @NonNull static Observable<T> concat(@NonNull final Observable<T> lh, @NonNull final Observable<T> rh); @NonNull static Observable<T> defer(@NonNull final Supplier<Observable<T>> func); @NonNull static Observable<R> zip(@NonNull final Observable<T> lh, @NonNull final Observable<T> rh, @NonNull final BiFunction<T, T, R> func);  }
@Test public void testFilter() throws Exception { List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5, 6); Observable<Integer> three = Observable.from(ints); Observable<Integer> filtered = three.filter(new Predicate<Integer>() { @Override public boolean apply(Integer value) { return value > 3; } }); List<Integer> expectedInts = Arrays.asList(4, 5, 6); validateObservable(filtered, expectedInts, 3, 1, 0); }