distinctUntilChanged

signature: distinctUntilChanged(compare: function): Observable



Example 1: distinctUntilChanged with basic values
Example 2: distinctUntilChanged with objects
  1. import { from } from 'rxjs/observable/from';
  2. //Objects must be same reference
  3. const myArrayWithDuplicateObjects = from([
  4. sampleObject,
  5. sampleObject,
  6. sampleObject
  7. //only out distinct objects, based on last emitted value
  8. const nonDistinctObjects = myArrayWithDuplicateObjects
  9. .pipe(distinctUntilChanged())
  10. //output: 'DISTINCT OBJECTS: {name: 'Test'}
  11. .subscribe(val => console.log('DISTINCT OBJECTS:', val));

Additional Resources