title: How to emit distinct values from MutableLiveData?
body: <p>I observed that <code>MutableLiveData</code> triggers <code>onChanged</code> of an observer even if the same object instance is provided to its <code>setValue</code> method.</p>
  
  <pre><code>//Fragment#onCreateView - scenario1
  val newValue = "newValue"
  mutableLiveData.setValue(newValue) //triggers observer
  mutableLiveData.setValue(newValue) //triggers observer
  
  //Fragment#onCreateView - scenario2
  val newValue = "newValue"
  mutableLiveData.postValue(newValue) //triggers observer
  mutableLiveData.postValue(newValue) //does not trigger observer
  </code></pre>
  
  <p>Is there a way to avoid an observer be notified twice if the same or an equivalent instance is provided to <code>setValue()</code>/<code>postValue()</code></p>
  
  <p>I tried extending <code>MutableLiveData</code> but that did not work. I could be missing something here</p>
  
  <pre><code>class DistinctLiveData&lt;T&gt; : MutableLiveData&lt;T&gt;() {
  
      private var cached: T? = null
  
      @Synchronized override fun setValue(value: T) {
          if(value != cached) {
              cached = value
              super.setValue(value)
          }
      }
  
      @Synchronized override fun postValue(value: T) {
          if(value != cached) {
              cached = value
              super.postValue(value)
          }
      }
  }
  </code></pre>