distinct
operator only returns the emits value with compared values is distinct from previous.
distinct(keySelector?)
keySelector?
: is a function to select which value you want to check
import { interval, of } from 'rxjs';
import { distinct, concatMap, delay } from 'rxjs/operators';
const values = [0, 0, 1, 1, 2, 3, 1, 1]
const source$ = of(...values).pipe(
concatMap( i => of(i).pipe(delay(1000)))
)
const result$ = source$.pipe(distinct());
import { of } from 'rxjs';
import { distinct, concatMap, delay, map } from 'rxjs/operators';
const values = [
{name: 'Foo'},
{name: 'Foo'},
{name: 'Bar'},
{name: 'Fiz'},
];
const source$ = of(...values).pipe(concatMap( i => of(i).pipe(delay(1000))))
const result$ = source$.pipe(
distinct((v) => v.name),
map(value => value.name),
);
Official Doc: rxjs.distinct