I use RxAndroid and I'd like to filter the result of an Observable<List<Item>>
.
Here is the code :
Observable<List<Item>> observable =
Observable.create((Observable.OnSubscribe<List<Item>>) subscriber -> {
subscriber.onNext(ItemManager.getItems());
subscriber.onCompleted();
});
I would like to use .filter()
to only get the valid items. Doing this would be perfect :
observable.filter(new Func1<Item, Boolean>() {
@Override
public Boolean call(Item item) {
return item.isValid();
}
});
However, .filter()
forces me to implement new Func1() :
observable.filter(new Func1<List<Item>, Boolean>() {
@Override
public Boolean call(Item item) {
}
});
Does somebody know how to solve the problem?
Thank you in advance :)
Observable.defer(() -> Observable.just(ItemManager.getItems())
.subscribeOn(Schedulers.io())
.flatMapIterable(items -> items)
.filter(item -> item.isValid())
.toList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With