The structure:
The api.vehicles()
endpoint returns a list of ids. The api.driveState(int id)
returns a state for a vehicle with the id as parameter.
What I need:
Make a call to the .vehicles()
. For the returned ids, make a call per id on the .driveState(id)
endpoint and wait for all the calls to succeed and return a list of states together. Let's ignore the retrys()
and network failures for now.
What I have tried is:
api.vehicles()
.flatMap(vehicles -> merge(getVehicleStates(vehicles)))
.toList()
.doOnNext(driveStates -> {
});
where getVehicleStates() is:
private List<Observable<DriveState>> getVehicleStates(List<Vehicle> vehicles){
List<Observable<DriveState>> states = new ArrayList<>();
for (Vehicle vehicle : vehicles) {
states.add(api.driveState(vehicle.getId()));
}
return states;
}
What would have been better I believe is the .zip() function. However I do not know how to deal with the FuncN() method:
api.vehicles()
.flatMap(vehicles ->
zip(getVehicleStates(vehicles), new FuncN<DriveState>() {
@Override public DriveState call(Object... args) {
return null;
}
}
));
PS: slightly similar but unanswered: Combining 'n' Observables of the same type (RxJava)