UNPKG

2.51 kBTypeScriptView Raw
1import { OperatorFunction, ObservableInput } from '../types';
2/**
3 * Compares all values of two observables in sequence using an optional comparator function
4 * and returns an observable of a single boolean value representing whether or not the two sequences
5 * are equal.
6 *
7 * <span class="informal">Checks to see of all values emitted by both observables are equal, in order.</span>
8 *
9 * ![](sequenceEqual.png)
10 *
11 * `sequenceEqual` subscribes to source observable and `compareTo` `ObservableInput` (that internally
12 * gets converted to an observable) and buffers incoming values from each observable. Whenever either
13 * observable emits a value, the value is buffered and the buffers are shifted and compared from the bottom
14 * up; If any value pair doesn't match, the returned observable will emit `false` and complete. If one of the
15 * observables completes, the operator will wait for the other observable to complete; If the other
16 * observable emits before completing, the returned observable will emit `false` and complete. If one observable never
17 * completes or emits after the other completes, the returned observable will never complete.
18 *
19 * ## Example
20 *
21 * Figure out if the Konami code matches
22 *
23 * ```ts
24 * import { from, fromEvent, map, bufferCount, mergeMap, sequenceEqual } from 'rxjs';
25 *
26 * const codes = from([
27 * 'ArrowUp',
28 * 'ArrowUp',
29 * 'ArrowDown',
30 * 'ArrowDown',
31 * 'ArrowLeft',
32 * 'ArrowRight',
33 * 'ArrowLeft',
34 * 'ArrowRight',
35 * 'KeyB',
36 * 'KeyA',
37 * 'Enter', // no start key, clearly.
38 * ]);
39 *
40 * const keys = fromEvent<KeyboardEvent>(document, 'keyup').pipe(map(e => e.code));
41 * const matches = keys.pipe(
42 * bufferCount(11, 1),
43 * mergeMap(last11 => from(last11).pipe(sequenceEqual(codes)))
44 * );
45 * matches.subscribe(matched => console.log('Successful cheat at Contra? ', matched));
46 * ```
47 *
48 * @see {@link combineLatest}
49 * @see {@link zip}
50 * @see {@link withLatestFrom}
51 *
52 * @param compareTo The `ObservableInput` sequence to compare the source sequence to.
53 * @param comparator An optional function to compare each value pair.
54 *
55 * @return A function that returns an Observable that emits a single boolean
56 * value representing whether or not the values emitted by the source
57 * Observable and provided `ObservableInput` were equal in sequence.
58 */
59export declare function sequenceEqual<T>(compareTo: ObservableInput<T>, comparator?: (a: T, b: T) => boolean): OperatorFunction<T, boolean>;
60//# sourceMappingURL=sequenceEqual.d.ts.map
\No newline at end of file