UNPKG

2.35 kBTypeScriptView Raw
1import { MonoTypeOperatorFunction, ObservableInput } from '../types';
2/**
3 * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items.
4 *
5 * If a `keySelector` function is provided, then it will project each value from the source observable into a new value that it will
6 * check for equality with previously projected values. If the `keySelector` function is not provided, it will use each value from the
7 * source observable directly with an equality check against previous values.
8 *
9 * In JavaScript runtimes that support `Set`, this operator will use a `Set` to improve performance of the distinct value checking.
10 *
11 * In other runtimes, this operator will use a minimal implementation of `Set` that relies on an `Array` and `indexOf` under the
12 * hood, so performance will degrade as more values are checked for distinction. Even in newer browsers, a long-running `distinct`
13 * use might result in memory leaks. To help alleviate this in some scenarios, an optional `flushes` parameter is also provided so
14 * that the internal `Set` can be "flushed", basically clearing it of values.
15 *
16 * ## Examples
17 *
18 * A simple example with numbers
19 *
20 * ```ts
21 * import { of, distinct } from 'rxjs';
22 *
23 * of(1, 1, 2, 2, 2, 1, 2, 3, 4, 3, 2, 1)
24 * .pipe(distinct())
25 * .subscribe(x => console.log(x));
26 *
27 * // Outputs
28 * // 1
29 * // 2
30 * // 3
31 * // 4
32 * ```
33 *
34 * An example using the `keySelector` function
35 *
36 * ```ts
37 * import { of, distinct } from 'rxjs';
38 *
39 * of(
40 * { age: 4, name: 'Foo'},
41 * { age: 7, name: 'Bar'},
42 * { age: 5, name: 'Foo'}
43 * )
44 * .pipe(distinct(({ name }) => name))
45 * .subscribe(x => console.log(x));
46 *
47 * // Outputs
48 * // { age: 4, name: 'Foo' }
49 * // { age: 7, name: 'Bar' }
50 * ```
51 * @see {@link distinctUntilChanged}
52 * @see {@link distinctUntilKeyChanged}
53 *
54 * @param keySelector Optional `function` to select which value you want to check as distinct.
55 * @param flushes Optional `ObservableInput` for flushing the internal HashSet of the operator.
56 * @return A function that returns an Observable that emits items from the
57 * source Observable with distinct values.
58 */
59export declare function distinct<T, K>(keySelector?: (value: T) => K, flushes?: ObservableInput<any>): MonoTypeOperatorFunction<T>;
60//# sourceMappingURL=distinct.d.ts.map
\No newline at end of file