a zip code crypto-currency system good for red ONLY

scan.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { scan as higherOrderScan } from '../operators/scan';
  2. /* tslint:enable:max-line-length */
  3. /**
  4. * Applies an accumulator function over the source Observable, and returns each
  5. * intermediate result, with an optional seed value.
  6. *
  7. * <span class="informal">It's like {@link reduce}, but emits the current
  8. * accumulation whenever the source emits a value.</span>
  9. *
  10. * <img src="./img/scan.png" width="100%">
  11. *
  12. * Combines together all values emitted on the source, using an accumulator
  13. * function that knows how to join a new source value into the accumulation from
  14. * the past. Is similar to {@link reduce}, but emits the intermediate
  15. * accumulations.
  16. *
  17. * Returns an Observable that applies a specified `accumulator` function to each
  18. * item emitted by the source Observable. If a `seed` value is specified, then
  19. * that value will be used as the initial value for the accumulator. If no seed
  20. * value is specified, the first item of the source is used as the seed.
  21. *
  22. * @example <caption>Count the number of click events</caption>
  23. * var clicks = Rx.Observable.fromEvent(document, 'click');
  24. * var ones = clicks.mapTo(1);
  25. * var seed = 0;
  26. * var count = ones.scan((acc, one) => acc + one, seed);
  27. * count.subscribe(x => console.log(x));
  28. *
  29. * @see {@link expand}
  30. * @see {@link mergeScan}
  31. * @see {@link reduce}
  32. *
  33. * @param {function(acc: R, value: T, index: number): R} accumulator
  34. * The accumulator function called on each source value.
  35. * @param {T|R} [seed] The initial accumulation value.
  36. * @return {Observable<R>} An observable of the accumulated values.
  37. * @method scan
  38. * @owner Observable
  39. */
  40. export function scan(accumulator, seed) {
  41. if (arguments.length >= 2) {
  42. return higherOrderScan(accumulator, seed)(this);
  43. }
  44. return higherOrderScan(accumulator)(this);
  45. }
  46. //# sourceMappingURL=scan.js.map