c45fc1058e73904b36772b280324bfd00c04ef6f0228b4bb9ce2d002b529b25db2c5b1b738414d94dc98f767a3279819267579efe84cb4ffed6ef09632bd2a 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { 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. */
  59. export declare function sequenceEqual<T>(compareTo: ObservableInput<T>, comparator?: (a: T, b: T) => boolean): OperatorFunction<T, boolean>;
  60. //# sourceMappingURL=sequenceEqual.d.ts.map