android - How to apply a RxJava operator? -


i have following object structure

class object1 {   a[] item1;    //array of object   b[] item2;    //array of object b   c[] item3;    //array of object c }  class c {   int value1;   int value2;   string imageurl; //null, updated api call } 

i observable<object> making retrofit api call. imageurl field of object c null, have update making retrofit api call. use rxjava update imageurl each object c in c[] in observable<object1> . how can rxjava operators ?

i want method return updated observable<object1>.

this should work:

getobject1()         .flatmap(obj1 -> observable.from(obj1.item3)                 .cast(c.class)                 .flatmap(item -> getimageurl(item.value1).doonnext(url -> item.imageurl = url))                 .tolist()                 .map(items -> obj1)) 

for test purposes getimageurl looked this:

observable<string> getimageurl(int id) {     return observable.just(string.format("id = %d", id)); } 

it can this:

observable<string> getimageurl(int id) {     return api.getimageurl(id).map(someresponse::getimageurl); } 

Comments