mergeScan.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /**
  5. * Applies an accumulator function over the source Observable where the
  6. * accumulator function itself returns an Observable, then each intermediate
  7. * Observable returned is merged into the output Observable.
  8. *
  9. * <span class="informal">It's like {@link scan}, but the Observables returned
  10. * by the accumulator are merged into the outer Observable.</span>
  11. *
  12. * @example <caption>Count the number of click events</caption>
  13. * const click$ = Rx.Observable.fromEvent(document, 'click');
  14. * const one$ = click$.mapTo(1);
  15. * const seed = 0;
  16. * const count$ = one$.mergeScan((acc, one) => Rx.Observable.of(acc + one), seed);
  17. * count$.subscribe(x => console.log(x));
  18. *
  19. * // Results:
  20. * 1
  21. * 2
  22. * 3
  23. * 4
  24. * // ...and so on for each click
  25. *
  26. * @param {function(acc: R, value: T): Observable<R>} accumulator
  27. * The accumulator function called on each source value.
  28. * @param seed The initial accumulation value.
  29. * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of
  30. * input Observables being subscribed to concurrently.
  31. * @return {Observable<R>} An observable of the accumulated values.
  32. * @method mergeScan
  33. * @owner Observable
  34. */
  35. function mergeScan(accumulator, seed, concurrent) {
  36. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  37. return operators_1.mergeScan(accumulator, seed, concurrent)(this);
  38. }
  39. exports.mergeScan = mergeScan;
  40. //# sourceMappingURL=mergeScan.js.map