0

I have a method that creates an observable from list of strings.

public Observable makeUrls() {
    List<String> urls = new ArrayList<>();
    return Observable.from(urls)
            .flatMap(url -> upload(url));
}

Now I want to return method b after all values in the list is emitted.

public Observable b(List<String> strings){
    return Observable.from(strings)
                     ..some other work here...;
}

The expected code i need is something like this:

public Observable makeUrls() {
    List<String> urls = new ArrayList<>();
    return Observable.from(urls)
            .flatMap(url -> upload(url))
            // This part is what i can't figure out how to write...
            // I want to call this after all items are emitted but I can't return Observable
            .doOnCompleted(()->b(strings));
}
Morteza Rastgoo
  • 6,772
  • 7
  • 40
  • 61
  • What is "strings"? If this your original urls or a collection of your return value from upload(String url)? – Will Aug 16 '15 at 07:46

1 Answers1

4

Use .ignoreElements and concatWith:

Suppose b(strings) returns Observable<Thing>:

return Observable.from(urls)
        .flatMap(url -> upload(url))
        .ignoreElements()
        .castAs(Thing.class)
        .concatWith(b(strings));
Dave Moten
  • 11,957
  • 2
  • 40
  • 47
  • Ok I've updated it with my guess. Can you refine the question so we know what the signature of b is for starters and where strings comes from? – Dave Moten Aug 16 '15 at 05:33
  • 1
    ok good. Yeah toList works if you need to do stuff with all the emissions but that wasn't clear from the question. Should I leave the answer as is or shall we clean up question and answer? – Dave Moten Aug 17 '15 at 22:45