You are looking for a zip
operator, as described here: Zip Operator . I think you want the flatmap to zip all your calls, so something like this:
mService.getExampleObject().flatMap(new Func1<List<ExampleObject>, Observable<ExampleObject>>() { @Override public Observable<List<ExampleObject>> call(List<ExampleObject> exampleObjects) { List<Observable<ExampleObject>> allTheObservables = new ArrayList<Observable<ExampleObject>>(); for (ExampleObject entry : exampleObjects) { allTheObservables.add(mService.getMissingObjectByFoo(foo).map(new Func1<MissingObject, ExampleObject>() { @Override public ExampleObject call(MissingObject missingObject) { return entry.setBar(missingObject); } })); } return Observable.zip(allTheObservables, new FuncN<ExampleObject>() { @Override public ExampleObject call(ExampleObject... args) { return Arrays.asList(args); } }); } });
and in case this does not work or there are problems with the syntax, here is a specific example using the github api:
service.getContributorsObservable("square", "dagger") .flatMap(new Func1<List<Contributor>, Observable<List<String>>>() { @Override public Observable<List<String>> call(List<Contributor> contributors) { List<Observable<String>> allTheObservables = new ArrayList<>(contributors.size()); for (final Contributor contributor : contributors) { allTheObservables.add(service.getContributorsObservable(contributor.login).map(new Func1<User, String>() { @Override public String call(User user) { return contributor.login + " is " + user.name; } })); } return Observable.zip(allTheObservables, new FuncN<List<String>>() { @Override public List<String> call(Object... args) { return Arrays.asList((String[]) args); } }); } });
Keep in mind that this will make n + 1 network calls, 1 for the ExampleObject
s list, and then 1 for the ExampleObject
in this list. If at all possible, I highly recommend that you speak with the companion API for information on searching the sides of the API. Just know that it will use some bandwidth!
source share