I have a code flow that generates an Iterable of Observables of the same type. I then go through them all, combining them and returning the result as an Observable. At the moment I'm using zip with a FuncN, which seems horrible and I think I've missed the point somewhere. Here's an example that uses a Map, it's obviously nonsense but you get the idea.
final ImmutableList.Builder<Map<String, Object>> observables =
ImmutableList.builder();
for (String key: keys) {
if (someTest(key)) {
observables.add(generateObservableMap(key));
}
}
return Observable.zip(observables.build(), data -> {
final Map<String, Object> result = Maps.newHashMap();
// THIS IS REALLY UGLY
for (Object d: data) {
for (Object e: ((Map) d).entrySet()) {
final Map.Entry entry = (Map.Entry) e;
final String key = (Model) entry.getKey();
final Object value = (AuthData) entry.getValue();
result.put(key, value);
}
}
return ImmutableMap.copyOf(result);
});
I'm sure there's a better way of doing this.