2e808cf0dc799dde39a4694e453cb91b0918e02f68277ce8d2d266178da6f11935ce1414a0250ec288f951be2168b7a776594fbf7bca2a4dac13d548a2221d 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { OperatorFunction } from '../types';
  2. /**
  3. * Groups pairs of consecutive emissions together and emits them as an array of
  4. * two values.
  5. *
  6. * <span class="informal">Puts the current value and previous value together as
  7. * an array, and emits that.</span>
  8. *
  9. * ![](pairwise.png)
  10. *
  11. * The Nth emission from the source Observable will cause the output Observable
  12. * to emit an array [(N-1)th, Nth] of the previous and the current value, as a
  13. * pair. For this reason, `pairwise` emits on the second and subsequent
  14. * emissions from the source Observable, but not on the first emission, because
  15. * there is no previous value in that case.
  16. *
  17. * ## Example
  18. *
  19. * On every click (starting from the second), emit the relative distance to the previous click
  20. *
  21. * ```ts
  22. * import { fromEvent, pairwise, map } from 'rxjs';
  23. *
  24. * const clicks = fromEvent<PointerEvent>(document, 'click');
  25. * const pairs = clicks.pipe(pairwise());
  26. * const distance = pairs.pipe(
  27. * map(([first, second]) => {
  28. * const x0 = first.clientX;
  29. * const y0 = first.clientY;
  30. * const x1 = second.clientX;
  31. * const y1 = second.clientY;
  32. * return Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2));
  33. * })
  34. * );
  35. *
  36. * distance.subscribe(x => console.log(x));
  37. * ```
  38. *
  39. * @see {@link buffer}
  40. * @see {@link bufferCount}
  41. *
  42. * @return A function that returns an Observable of pairs (as arrays) of
  43. * consecutive values from the source Observable.
  44. */
  45. export declare function pairwise<T>(): OperatorFunction<T, [T, T]>;
  46. //# sourceMappingURL=pairwise.d.ts.map