title: LiveData - Observe objects in list
body: <p>I have a list of<code>Functions</code> that is retrieved from a local SQLite database using Room and I want to observe every function in that list. At the moment I'm doing the following:</p>
  
  <pre><code>public List&lt;MutableLiveData&lt;Function&gt;&gt; getLiveFunctions() {
      if (liveFunctions == null) {
          liveFunctions = new ArrayList&lt;&gt;();
          for (Function function : functions) {
              //Livedata with a default value on background thread (postValue)
              liveFunctions.add(new DefaultLiveData&lt;&gt;(function, true));
          }
      }
      return liveFunctions;
  }
  </code></pre>
  
  <p>After a local fetch from the database, I can request the status of a given function using an RPC to my server. When I receive a response, I can set the new value for that function and I want my UI to observe the changes in that function.</p>
  
  <p>Just some clarifications:</p>
  
  <ol>
  <li><p>The difference between <code>LiveData&lt;List&lt;Function&gt;&gt;&gt;</code> and <code>List&lt;LiveData&lt;Function&gt;&gt;</code> is that the first will only observe whether an object was added, updated or removed in the list, correct? It's not that <code>LiveData&lt;List&lt;Function&gt;&gt;&gt;</code> also listens to changes on their items?</p></li>
  <li><p>I'm using a <code>MediatorLiveData</code> to combine my observers to a "FunctionObserver". Is this the correct approach to handle all my function callbacks?</p></li>
  </ol>
  
  <p>[code]</p>
  
  <pre><code>MediatorLiveData&lt;LiveData&lt;Function&gt;&gt; mediator = new MediatorLiveData&lt;&gt;();
  List&lt;MutableLiveData&lt;Function&gt;&gt; functions = //functions
  for (LiveData&lt;Function&gt; function : functions) {
      mediator.addSource(function, functionObserver);
  }
  
  mediator.observe(MainActivity.this, new Observer&lt;LiveData&lt;Function&gt;&gt;() {
      @Override
      public void onChanged(@Nullable LiveData&lt;Function&gt; functionLiveData) {
          Log.i(TAG, "Live data change: ");
      }
  });
  </code></pre>
  
  <ol start="3">
  <li>Can my code logic be improved? I know that I can request a <code>LiveData&lt;List&lt;Function&gt;&gt;&gt;</code> from Room but I'm having trouble with my parent class having a <code>@Relation</code> annotation which needs the type to be a <code>List</code> or <code>Set</code> (and not LiveData)</li>
  </ol>