I have a list of Observables (RxJava 1).
List<Observable> observableList = new ArrayList<>();
It can contain at least 1 Observable. Each has the same type of the result.
How can I zip results of the all Observables?
I thought about zip-operator but it doesn't support List and I don't know quantity of observables (it can be 1,2,3,4....)
You can use the static zip(java.lang.Iterable<? extends Observable<?>> ws,FuncN<? extends R> zipFunction)
method.
It is a zip
method that takes an Iterable
of Observable
s and a FuncN
(which takes a varargs parameter for its call
method) and uses it to combine the corresponding emitted Object
s into the result to be omitted by the new returned Observable
.
So for example you could do:
Observable.zip(observableList, new FuncN(){
public ReturnType call(java.lang.Object... args){
ReturnType result; //to be made
//preparatory code for using the args
for (Object obj : args){
ReturnType retObj = (ReturnType)obj;
//code to use the arg once at a time to combine N of them into one.
}
return result;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With