Suppose you have a method which returns an observable in RxJS and you only want to emit values that differ from the previous values. RxJS has an operator called distinctUntilChanged
that can accomplish this. distinctUntilChanged
prevents the same information from being outputted to the user.
Example
import {from} from 'rxjs';
import {distinctUntilChanged} from 'rxjs/operators';
//from turns an iterable, promise or array into an observable
const cities$ = from([
{city: "Los Angeles"},
{city: "Toronto"},
{city: "London"},
{city: "London"},
{city: "Brussels"},
]);
const data$ = cities$.pipe(distinctUntilChanged((prev, curr) => prev.city === curr.city))
.subscribe(console.log);
/* {city: "Los Angeles"}
*{city: "Toronto"}
* {city: "London"}
*/ {city: "Brussels"}