RxJava - zip list of Observable

前端 未结 3 963
眼角桃花
眼角桃花 2021-02-13 02:02

I have a list of Observables (RxJava 1).

List observableList = new ArrayList<>();

It can contain at least 1 Observable.

3条回答
  •  失恋的感觉
    2021-02-13 02:42

    You can use the static zip(java.lang.Iterable> ws,FuncN zipFunction) method.

    It is a zip method that takes an Iterable of Observables and a FuncN (which takes a varargs parameter for its call method) and uses it to combine the corresponding emitted Objects 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;
        }
    });
    

提交回复
热议问题