a zip code crypto-currency system good for red ONLY

pairwise.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /** PURE_IMPORTS_START .._operators_pairwise PURE_IMPORTS_END */
  2. import { pairwise as higherOrder } from '../operators/pairwise';
  3. /**
  4. * Groups pairs of consecutive emissions together and emits them as an array of
  5. * two values.
  6. *
  7. * <span class="informal">Puts the current value and previous value together as
  8. * an array, and emits that.</span>
  9. *
  10. * <img src="./img/pairwise.png" width="100%">
  11. *
  12. * The Nth emission from the source Observable will cause the output Observable
  13. * to emit an array [(N-1)th, Nth] of the previous and the current value, as a
  14. * pair. For this reason, `pairwise` emits on the second and subsequent
  15. * emissions from the source Observable, but not on the first emission, because
  16. * there is no previous value in that case.
  17. *
  18. * @example <caption>On every click (starting from the second), emit the relative distance to the previous click</caption>
  19. * var clicks = Rx.Observable.fromEvent(document, 'click');
  20. * var pairs = clicks.pairwise();
  21. * var distance = pairs.map(pair => {
  22. * var x0 = pair[0].clientX;
  23. * var y0 = pair[0].clientY;
  24. * var x1 = pair[1].clientX;
  25. * var y1 = pair[1].clientY;
  26. * return Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2));
  27. * });
  28. * distance.subscribe(x => console.log(x));
  29. *
  30. * @see {@link buffer}
  31. * @see {@link bufferCount}
  32. *
  33. * @return {Observable<Array<T>>} An Observable of pairs (as arrays) of
  34. * consecutive values from the source Observable.
  35. * @method pairwise
  36. * @owner Observable
  37. */
  38. export function pairwise() {
  39. return higherOrder()(this);
  40. }
  41. //# sourceMappingURL=pairwise.js.map