Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pairwise.d.ts 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. * On every click (starting from the second), emit the relative distance to the previous click
  19. * ```ts
  20. * import { fromEvent } from 'rxjs';
  21. * import { pairwise, map } from 'rxjs/operators';
  22. *
  23. * const clicks = fromEvent(document, 'click');
  24. * const pairs = clicks.pipe(pairwise());
  25. * const distance = pairs.pipe(
  26. * map(pair => {
  27. * const x0 = pair[0].clientX;
  28. * const y0 = pair[0].clientY;
  29. * const x1 = pair[1].clientX;
  30. * const y1 = pair[1].clientY;
  31. * return Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2));
  32. * }),
  33. * );
  34. * distance.subscribe(x => console.log(x));
  35. * ```
  36. *
  37. * @see {@link buffer}
  38. * @see {@link bufferCount}
  39. *
  40. * @return {Observable<Array<T>>} An Observable of pairs (as arrays) of
  41. * consecutive values from the source Observable.
  42. * @method pairwise
  43. * @owner Observable
  44. */
  45. export declare function pairwise<T>(): OperatorFunction<T, [T, T]>;