1 | import { Operator } from '../Operator';
|
---|
2 | import { Observable } from '../Observable';
|
---|
3 | import { Subscriber } from '../Subscriber';
|
---|
4 | import { Observer, OperatorFunction } from '../types';
|
---|
5 | /**
|
---|
6 | * Compares all values of two observables in sequence using an optional comparator function
|
---|
7 | * and returns an observable of a single boolean value representing whether or not the two sequences
|
---|
8 | * are equal.
|
---|
9 | *
|
---|
10 | * <span class="informal">Checks to see of all values emitted by both observables are equal, in order.</span>
|
---|
11 | *
|
---|
12 | * ![](sequenceEqual.png)
|
---|
13 | *
|
---|
14 | * `sequenceEqual` subscribes to two observables and buffers incoming values from each observable. Whenever either
|
---|
15 | * observable emits a value, the value is buffered and the buffers are shifted and compared from the bottom
|
---|
16 | * up; If any value pair doesn't match, the returned observable will emit `false` and complete. If one of the
|
---|
17 | * observables completes, the operator will wait for the other observable to complete; If the other
|
---|
18 | * observable emits before completing, the returned observable will emit `false` and complete. If one observable never
|
---|
19 | * completes or emits after the other complets, the returned observable will never complete.
|
---|
20 | *
|
---|
21 | * ## Example
|
---|
22 | * figure out if the Konami code matches
|
---|
23 | * ```ts
|
---|
24 | * import { from, fromEvent } from 'rxjs';
|
---|
25 | * import { sequenceEqual, bufferCount, mergeMap, map } from 'rxjs/operators';
|
---|
26 | *
|
---|
27 | * const codes = from([
|
---|
28 | * 'ArrowUp',
|
---|
29 | * 'ArrowUp',
|
---|
30 | * 'ArrowDown',
|
---|
31 | * 'ArrowDown',
|
---|
32 | * 'ArrowLeft',
|
---|
33 | * 'ArrowRight',
|
---|
34 | * 'ArrowLeft',
|
---|
35 | * 'ArrowRight',
|
---|
36 | * 'KeyB',
|
---|
37 | * 'KeyA',
|
---|
38 | * 'Enter', // no start key, clearly.
|
---|
39 | * ]);
|
---|
40 | *
|
---|
41 | * const keys = fromEvent(document, 'keyup').pipe(map(e => e.code));
|
---|
42 | * const matches = keys.pipe(
|
---|
43 | * bufferCount(11, 1),
|
---|
44 | * mergeMap(
|
---|
45 | * last11 => from(last11).pipe(sequenceEqual(codes)),
|
---|
46 | * ),
|
---|
47 | * );
|
---|
48 | * matches.subscribe(matched => console.log('Successful cheat at Contra? ', matched));
|
---|
49 | * ```
|
---|
50 | *
|
---|
51 | * @see {@link combineLatest}
|
---|
52 | * @see {@link zip}
|
---|
53 | * @see {@link withLatestFrom}
|
---|
54 | *
|
---|
55 | * @param {Observable} compareTo The observable sequence to compare the source sequence to.
|
---|
56 | * @param {function} [comparator] An optional function to compare each value pair
|
---|
57 | * @return {Observable} An Observable of a single boolean value representing whether or not
|
---|
58 | * the values emitted by both observables were equal in sequence.
|
---|
59 | * @method sequenceEqual
|
---|
60 | * @owner Observable
|
---|
61 | */
|
---|
62 | export declare function sequenceEqual<T>(compareTo: Observable<T>, comparator?: (a: T, b: T) => boolean): OperatorFunction<T, boolean>;
|
---|
63 | export declare class SequenceEqualOperator<T> implements Operator<T, boolean> {
|
---|
64 | private compareTo;
|
---|
65 | private comparator;
|
---|
66 | constructor(compareTo: Observable<T>, comparator: (a: T, b: T) => boolean);
|
---|
67 | call(subscriber: Subscriber<boolean>, source: any): any;
|
---|
68 | }
|
---|
69 | /**
|
---|
70 | * We need this JSDoc comment for affecting ESDoc.
|
---|
71 | * @ignore
|
---|
72 | * @extends {Ignored}
|
---|
73 | */
|
---|
74 | export declare class SequenceEqualSubscriber<T, R> extends Subscriber<T> {
|
---|
75 | private compareTo;
|
---|
76 | private comparator;
|
---|
77 | private _a;
|
---|
78 | private _b;
|
---|
79 | private _oneComplete;
|
---|
80 | constructor(destination: Observer<R>, compareTo: Observable<T>, comparator: (a: T, b: T) => boolean);
|
---|
81 | protected _next(value: T): void;
|
---|
82 | _complete(): void;
|
---|
83 | checkValues(): void;
|
---|
84 | emit(value: boolean): void;
|
---|
85 | nextB(value: T): void;
|
---|
86 | completeB(): void;
|
---|
87 | }
|
---|