title: RxJava: Chaining Observables w/ Builder object
body: <p>I'm using a Builder pattern to build upon a model object which combines data from different network calls and I'm having a hard time understanding the best way to take the model object from the first network call and combine the data from the second network call into the original model object.</p>
  
  <p>My actual subscription:</p>
  
  <pre><code>myFirstApiRepository.getFirstModelObjectBuilder()
      .flatmap(firstModelObjectBuilder -&gt; mySecondApiRepository.getSomeExtraData(firstModelObjectBuilder))
      .observable.subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(getMySubscriber());
  </code></pre>
  
  <p>First network call:</p>
  
  <pre><code>public Observable&lt;FirstModelObject.Builder&gt; getFirstModelObjectBuilder() {
      return myFirstApiResource.getSomeData(...)
              .flatMap(someData -&gt; Observable.just(new FirstModelObject.Builder()
                  .setFirstAttribute(someData.getFirstAttribute())
                  .setSecondAttribute(someData.getSecondAttribute())));
  }
  </code></pre>
  
  <p>Second network call:</p>
  
  <pre><code>public Observable&lt;FirstModelObject&gt; getSomeExtraData(FirstModelObject.Builder builder) {
      return mySecondApiResource.getSomeData(...)
          .flatMap(aString -&gt; builder.setSomeStringValue(aString)
                                     .build());
  }
  </code></pre>
  
  <p>The problem here is that I have to pass the builder object into the second network call's observable. This makes it very rigid and I'd rather not have my <code>SecondApiRepository</code> rely on and reference a data type which it shouldn't need to reference. It also makes this second method here "<code>.build()</code>" the object, which is not good. <strong>So, how can I use the <code>firstModelObject</code> and add data to it from the second network call in a clean way</strong>?</p>
  
  <p>If this is just bad design, please let me know. I'm still trying to learn more about RxJava best practices. :)</p>