a zip code crypto-currency system good for red ONLY

concatMapTo.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { concatMap } from './concatMap';
  2. /* tslint:enable:max-line-length */
  3. /**
  4. * Projects each source value to the same Observable which is merged multiple
  5. * times in a serialized fashion on the output Observable.
  6. *
  7. * <span class="informal">It's like {@link concatMap}, but maps each value
  8. * always to the same inner Observable.</span>
  9. *
  10. * <img src="./img/concatMapTo.png" width="100%">
  11. *
  12. * Maps each source value to the given Observable `innerObservable` regardless
  13. * of the source value, and then flattens those resulting Observables into one
  14. * single Observable, which is the output Observable. Each new `innerObservable`
  15. * instance emitted on the output Observable is concatenated with the previous
  16. * `innerObservable` instance.
  17. *
  18. * __Warning:__ if source values arrive endlessly and faster than their
  19. * corresponding inner Observables can complete, it will result in memory issues
  20. * as inner Observables amass in an unbounded buffer waiting for their turn to
  21. * be subscribed to.
  22. *
  23. * Note: `concatMapTo` is equivalent to `mergeMapTo` with concurrency parameter
  24. * set to `1`.
  25. *
  26. * @example <caption>For each click event, tick every second from 0 to 3, with no concurrency</caption>
  27. * var clicks = Rx.Observable.fromEvent(document, 'click');
  28. * var result = clicks.concatMapTo(Rx.Observable.interval(1000).take(4));
  29. * result.subscribe(x => console.log(x));
  30. *
  31. * // Results in the following:
  32. * // (results are not concurrent)
  33. * // For every click on the "document" it will emit values 0 to 3 spaced
  34. * // on a 1000ms interval
  35. * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
  36. *
  37. * @see {@link concat}
  38. * @see {@link concatAll}
  39. * @see {@link concatMap}
  40. * @see {@link mergeMapTo}
  41. * @see {@link switchMapTo}
  42. *
  43. * @param {ObservableInput} innerObservable An Observable to replace each value from
  44. * the source Observable.
  45. * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
  46. * A function to produce the value on the output Observable based on the values
  47. * and the indices of the source (outer) emission and the inner Observable
  48. * emission. The arguments passed to this function are:
  49. * - `outerValue`: the value that came from the source
  50. * - `innerValue`: the value that came from the projected Observable
  51. * - `outerIndex`: the "index" of the value that came from the source
  52. * - `innerIndex`: the "index" of the value from the projected Observable
  53. * @return {Observable} An observable of values merged together by joining the
  54. * passed observable with itself, one after the other, for each value emitted
  55. * from the source.
  56. * @method concatMapTo
  57. * @owner Observable
  58. */
  59. export function concatMapTo(innerObservable, resultSelector) {
  60. return concatMap(() => innerObservable, resultSelector);
  61. }
  62. //# sourceMappingURL=concatMapTo.js.map