title: How can multiple requests used to populate models be handled using RXJava Observables?
body: <p>We are using ReactiveX and Retrofit in our network stack to handle all API requests in an asynchronous way. </p>
  
  <p>Our goal is to create one method that will return a completely populated collection of <code>User</code> models. Each <code>User</code> model has a list of <code>Pet</code> objects. We can fetch all of the <code>User</code> models with one request. However, <code>Pet</code> models need to be requested per <code>User</code>. </p>
  
  <p>Getting users is simple:</p>
  
  <pre><code>// Service.java
  @GET("users/?locationId={id}")
  Observable&lt;List&lt;User&gt;&gt; getUsersForLocation(@Path("id") int locationId);
  
  @GET("pets/?userId={id}")
  Observable&lt;List&lt;Pet&gt;&gt; getPetsForUser(@Path("id") int userId);
  
  // DataManager.java
  public Observable&lt;List&lt;User&gt;&gt; getUsersForLocation(int locationId) {
      return api.getUsersForLocation(locationId);
  }
  
  public Observable&lt;List&lt;Pet&gt;&gt; getPetsForUser(int userId) {
      return api.getPetsForUser(userId);
  }
  </code></pre>
  
  <p>We would like to find some convenient (RX style) way of looping through the <code>User</code> list, fetching the <code>Pet</code>s for that each user, assigning them to the <code>User</code> and ultimately returning the <code>Observable&lt;List&lt;User&gt;&gt;</code>.</p>
  
  <p>I am fairly new to RX. I've looked over the documentation and have tried using various methods such as <code>flatMap()</code> and <code>zip</code>, however, I have yet to find the exact combination of transforms or combiners to make it happen. </p>