RxJava for-loop with async methoods?
<p>I am learning to use RxJava with Android. In my project, I have a single situation where I get a <code>List</code> of items from the server, and I need to get the details of each item, before returning the response to the UI.</p>

<p>The problem is: I am not sure how to <code>sync</code> the API calls that are called inside the <code>for loop</code>. I want the end result returned to the UI only after all calls in the <code>foor loop</code> complete.</p>

<p>Any hints are <strong>highly appreciated</strong>.</p>

<p>Sample code:</p>

<pre><code>Observable&lt;List&lt;Favorite&gt;&gt; result = ApiWrapper.getFavorites(userData)
            .flatMap(new Func1&lt;List&lt;Favorite&gt;, Observable&lt;List&lt;Favorite&gt;&gt;&gt;() {
              @Override
              public Observable&lt;List&lt;Favorite&gt;&gt; call(@NonNull final List&lt;Favorite&gt; response) {
                for(int i = 0; i &lt; response.size(); i++){
                  getDetailsForFavoriteItem(response.get(i));
                }
                return Observable.just(response);              
              }
            });

private Observable&lt;Favorite&gt; getDetailsForFavoriteItem (Favorite item){
  return ApiWrapper.getDetails(item.getId())
        .flatMap(new Func1&lt;FavoriteDetailsResponse, Observable&lt;Favorite&gt;&gt;() {
              @Override
              public Observable&lt;Favorite&gt; call(@NonNull final FavoriteDetailsResponse response) {
                item.setParam1(response.getParam1());
                item.setParam2(response.getParam2);
                //so on
                return Observable.just(item)//!!!issue is here ! I want this return to be called only after all the details (in the for loop) have been called              
              }
            });
}
</code></pre>