Filter Redundant Observable Emissions with RxJS distinct

InstructorAndré Staltz

Share this video with your friends

Send Tweet

Operator distinct() and its variants are an important type of Filtering operator. This lessons shows how they work and in what cases are they useful.

🚨 Since we are importing interval from RxJS, we don't need to preface our Observables with Rx.Observable. You can no longer .{operator}, you need to .pipe({operator}) instead.

Jon
~ 8 years ago

For people using TypeScript, you have have to import 'rxjs/add/operator/distinct'; Distinct was not included when importing 'rxjs/Rx'; and my build was erroring out.

Mike
~ 7 years ago
var result = foo.distinct((x,y) => x.toLowerCase() === y.toLowerCase());

gives: "error: TypeError: y is undefined"

Should be:

var result = foo.distinct((x) => x.toLowerCase());
André Staltzinstructor
~ 7 years ago

Hi Mike. That's correct. We should update the lesson to use a 'keySelector' function, not a 'compare' function.