Reputation: 25
Need help to resolve issue with return value in RxJava. So, here is what I have done so far:
private Observable<Boolean> updatedMenuItems() {
return Observable.fromIterable(getAliases())
.doOnNext(alias -> {
return ApiRepository.getMenuItemBlocks(alias)
.subscribeOn(Schedulers.io())
.flatMapIterable(list -> list)
.map(item -> item.getFileTimeStamp() == null ? "" : item.getFileTimeStamp().toString())
.toList()
.doOnSuccess(apiContents -> {
return Observable.fromCallable(DataStoreRepository::loadMenuItemsBlock)
.subscribeOn(Schedulers.io())
.flatMapIterable(list -> list)
.map(item -> item.fileTimeStamp == null ? "" : item.fileTimeStamp.toString())
.toList()
.map(dbContents -> {
return DBUtil.isContentEqual(dbContents, apiContents);
});
});
});
}
I need to return Observable<Boolean>
data type from this method but inside the block of .doOnSuccess(...);
I am getting an error concerning return value. Could you please, help me to solve this issue. Thanks!
Upvotes: 0
Views: 560
Reputation: 2835
doOnNext, doOnSuccess, doOnError, doOnCompleted
These are called Side-effect operators, they don't really affect the chain in anyway, they might be used as a logging mechanism for ex.
What you're looking for is probably flatMap
, from the docs:
FlatMap: Transforms the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable.
Upvotes: 1