I have two methods that return an Observable< Response< ResponseBody > >
firstAPI.getFirstInfo("1", "2");
secondApi.getSecondInfo(resultFirstObservable, "3");
I'm trying to get an information from the first one and use it as a parameter in the second one.
I started by trying to use a flatMap:
Observable<Integer> mergedObservers = firstAPI.getFirstInfo("1","2")
.flatMap((Response<ResponseBody> resultFirstObservable) -> {
try {
return secondApi.getSecondInfo(transformToTheFormatNeeded(resultFirstObservable.body().string()), "3");
} catch (IOException e) {
e.printStackTrace();
return secondApi.getSecondInfo("defaultValue", "3");
}
}, ((Response<ResponseBody> resultFirstObservable), (Response<ResponseBody> resultSecondObservable)) -> {
try {
return transformToWhatINeed(resultSecondObservable.body().string());
} catch (IOException e) {
e.printStackTrace();
}
});
I would try then to subscribeOn this new Observable and onNext I would send the returned value to my Activity.
Subscription sub = mergedObservers.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.repeatWhen(completed -> completed.delay(30, TimeUnit.SECONDS))
.subscribe(new Observer<Integer>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Integer integer) {
view.updateInfo(integer);
}
});
My problem is that the flatMap throws 2 errors at compilation:
error: lambda body is neither value nor void compatible
error: no suitable method found for flatMap((__)->{ tr[...]; } },(.. ,..)->{ [...]; } })
What am I doing wrong ?