a zip code crypto-currency system good for red ONLY

sequenceEqual.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. var sequenceEqual_1 = require('../operators/sequenceEqual');
  3. /**
  4. * Compares all values of two observables in sequence using an optional comparor function
  5. * and returns an observable of a single boolean value representing whether or not the two sequences
  6. * are equal.
  7. *
  8. * <span class="informal">Checks to see of all values emitted by both observables are equal, in order.</span>
  9. *
  10. * <img src="./img/sequenceEqual.png" width="100%">
  11. *
  12. * `sequenceEqual` subscribes to two observables 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 complets, the returned observable will never complete.
  18. *
  19. * @example <caption>figure out if the Konami code matches</caption>
  20. * var code = Rx.Observable.from([
  21. * "ArrowUp",
  22. * "ArrowUp",
  23. * "ArrowDown",
  24. * "ArrowDown",
  25. * "ArrowLeft",
  26. * "ArrowRight",
  27. * "ArrowLeft",
  28. * "ArrowRight",
  29. * "KeyB",
  30. * "KeyA",
  31. * "Enter" // no start key, clearly.
  32. * ]);
  33. *
  34. * var keys = Rx.Observable.fromEvent(document, 'keyup')
  35. * .map(e => e.code);
  36. * var matches = keys.bufferCount(11, 1)
  37. * .mergeMap(
  38. * last11 =>
  39. * Rx.Observable.from(last11)
  40. * .sequenceEqual(code)
  41. * );
  42. * matches.subscribe(matched => console.log('Successful cheat at Contra? ', matched));
  43. *
  44. * @see {@link combineLatest}
  45. * @see {@link zip}
  46. * @see {@link withLatestFrom}
  47. *
  48. * @param {Observable} compareTo The observable sequence to compare the source sequence to.
  49. * @param {function} [comparor] An optional function to compare each value pair
  50. * @return {Observable} An Observable of a single boolean value representing whether or not
  51. * the values emitted by both observables were equal in sequence.
  52. * @method sequenceEqual
  53. * @owner Observable
  54. */
  55. function sequenceEqual(compareTo, comparor) {
  56. return sequenceEqual_1.sequenceEqual(compareTo, comparor)(this);
  57. }
  58. exports.sequenceEqual = sequenceEqual;
  59. //# sourceMappingURL=sequenceEqual.js.map