1 import { Observable } from '../Observable';
2 import { Subscriber } from '../Subscriber';
3 import { MonoTypeOperatorFunction } from '../types';
4 import { SimpleOuterSubscriber } from '../innerSubscribe';
6 * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items.
8 * If a keySelector function is provided, then it will project each value from the source observable into a new value that it will
9 * check for equality with previously projected values. If a keySelector function is not provided, it will use each value from the
10 * source observable directly with an equality check against previous values.
12 * In JavaScript runtimes that support `Set`, this operator will use a `Set` to improve performance of the distinct value checking.
14 * In other runtimes, this operator will use a minimal implementation of `Set` that relies on an `Array` and `indexOf` under the
15 * hood, so performance will degrade as more values are checked for distinction. Even in newer browsers, a long-running `distinct`
16 * use might result in memory leaks. To help alleviate this in some scenarios, an optional `flushes` parameter is also provided so
17 * that the internal `Set` can be "flushed", basically clearing it of values.
20 * A simple example with numbers
22 * import { of } from 'rxjs';
23 * import { distinct } from 'rxjs/operators';
25 * of(1, 1, 2, 2, 2, 1, 2, 3, 4, 3, 2, 1).pipe(
28 * .subscribe(x => console.log(x)); // 1, 2, 3, 4
31 * An example using a keySelector function
33 * import { of } from 'rxjs';
34 * import { distinct } from 'rxjs/operators';
42 * { age: 4, name: 'Foo'},
43 * { age: 7, name: 'Bar'},
44 * { age: 5, name: 'Foo'},
46 * distinct((p: Person) => p.name),
48 * .subscribe(x => console.log(x));
51 * // { age: 4, name: 'Foo' }
52 * // { age: 7, name: 'Bar' }
54 * @see {@link distinctUntilChanged}
55 * @see {@link distinctUntilKeyChanged}
57 * @param {function} [keySelector] Optional function to select which value you want to check as distinct.
58 * @param {Observable} [flushes] Optional Observable for flushing the internal HashSet of the operator.
59 * @return {Observable} An Observable that emits items from the source Observable with distinct values.
63 export declare function distinct<T, K>(keySelector?: (value: T) => K, flushes?: Observable<any>): MonoTypeOperatorFunction<T>;
65 * We need this JSDoc comment for affecting ESDoc.
69 export declare class DistinctSubscriber<T, K> extends SimpleOuterSubscriber<T, T> {
72 constructor(destination: Subscriber<T>, keySelector?: (value: T) => K, flushes?: Observable<any>);
74 notifyError(error: any): void;
75 protected _next(value: T): void;
76 private _useKeySelector;
77 private _finalizeNext;