java - RxJava: dynamically create Observables and send the final resut as Observable -


i using rxjava in want dynamically create number of observables based on condition. once i'm done creating, want processing on different values returned observables , send single observable can subscribe on. here how code :

list<string> valuelist = ....   list<observable<string>> listofobservables = new arraylist<observable<string>>();  for(int =; <valuelist.size(); i++){         listofobservables.add(new someclass.dooperation(valuelist(i)));         // someclass.dooperation return observable<string>     }  return observable.merge(listofobservables); 

but here , want operation on values emitted different observables in listofobservable , return single observable<string>

like in observable.zip() , can

return observable.zip(observable1, observable2, (string1, string2) -> {             // joining final string here             return string1 + string2; 

but know number of arguments here. please let me know how can achieve this.

use zip overload that takes variable number of arguments, has signature of

<r> observable<r> zip(iterable<? extends observable<?>> ws,                       funcn<? extends r> zipfunction) 

example usage:

list<string> valuelist = ....   return observable.from(valuelist)     .map(string -> someclass.dooperationthatreturnsobservable(string))     .tolist()     .flatmap(listofobs -> observable.zip(listofobs, (object[] results) -> {        // strings in array.        return arrays.stream(results)                     .map(object::tostring)                     .collect(collectors.joining(","));     })); 

Comments

Popular posts from this blog

loops - Spock: How to use test data with @Stepwise -

amazon web services - S3 Pre-signed POST validate file type? -