title: MediatorLiveData or switchMap transformation with multiple parameters
body: <p>I am using <a href="https://developer.android.com/reference/android/arch/lifecycle/Transformations.html" rel="noreferrer"><code>Transformations.switchMap</code></a> in my ViewModel so my <code>LiveData</code> collection, observed in my fragment, reacts on changes of <code>code</code> parameter.</p>
  
  <p>This works perfectly :</p>
  
  <pre><code>public class MyViewModel extends AndroidViewModel {
  
      private final LiveData&lt;DayPrices&gt; dayPrices;
      private final MutableLiveData&lt;String&gt; code = new MutableLiveData&lt;&gt;();
      // private final MutableLiveData&lt;Integer&gt; nbDays = new MutableLiveData&lt;&gt;();
      private final DBManager dbManager;
  
      public MyViewModel(Application application) {
          super(application);
          dbManager = new DBManager(application.getApplicationContext());
          dayPrices = Transformations.switchMap(
              code,
              value -&gt; dbManager.getDayPriceData(value/*, nbDays*/)
          );
      }
  
      public LiveData&lt;DayPrices&gt; getDayPrices() {
          return dayPrices;
      }
  
      public void setCode(String code) {
          this.code.setValue(code);
      }
  
      /*public void setNbDays(int nbDays) {
          this.nbDays.setValue(nbDays);
      }*/
  
  }
  
  public class MyFragment extends Fragment {
  
      private MyViewModel myViewModel;
  
      myViewModel = ViewModelProviders.of(this).get(MyViewModel.class);
      myViewModel.setCode("SO");
      //myViewModel.setNbDays(30);
      myViewModel.getDayPrices().observe(MyFragment.this, dataList -&gt; {
          // update UI with data from dataList
      });
  }
  </code></pre>
  
  <p><strong>Problem</strong></p>
  
  <p>I now need another parameter (<code>nbDays</code> commented in the code above), so that my <code>LiveData</code> object reacts on both parameters change (<code>code</code> and <code>nbDays</code>).</p>
  
  <p>How can I chain transformations ?</p>
  
  <p>Some reading pointed me to <a href="https://developer.android.com/reference/android/arch/lifecycle/MediatorLiveData.html" rel="noreferrer">MediatorLiveData</a>, but it does not solve my problem (still need to call single DB function with 2 parameters, I don't need to merge 2 liveDatas).</p>
  
  <p>So I tried this instead of <code>switchMap</code> but <code>code</code> and <code>nbDays</code> are always null.</p>
  
  <pre><code>dayPrices.addSource(
      dbManager.getDayPriceData(code.getValue(), nbDays.getValue),
      apiResponse -&gt; dayPrices.setValue(apiResponse)
  );
  </code></pre>
  
  <p>One solution would be to pass an object as single parameter by I'm pretty sure there is a simple solution to this.</p>