ReferencedistinctUntilChanged
Reference · 19
distinctUntilChanged
distinctUntilChanged
Ignores the same value repeated back-to-back.
Signature
distinctUntilChanged(comparator?: (a: T, b: T) => boolean, keySelector?: (v: T) => K): MonoTypeOperatorFunction
Marble diagram
in: 1-1-2-2-3-1-|
result: 1---2---3-1-|
What it does
Remembers the last emitted value and compares each new one to it (=== by default), passing it on only if it differs. An optional keySelector compares by a chosen object field only.
When to use
Typeahead search (the input matched the previous one — no request needed). Shielding subscribers from redundant updates. Cutting re-renders in Angular.
Gotcha
It compares only with the previous value, not the whole history. For global uniqueness, use the distinct operator.
See also
distinct, filter, debounceTime
script.ts
CONSOLE · Console output
Hit Run to see the result...