mergeMap.d.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { Observable, ObservableInput } from 'rxjs';
  2. /**
  3. * Projects each source value to an Observable which is merged in the output
  4. * Observable.
  5. *
  6. * <span class="informal">Maps each value to an Observable, then flattens all of
  7. * these inner Observables using {@link mergeAll}.</span>
  8. *
  9. * <img src="./img/mergeMap.png" width="100%">
  10. *
  11. * Returns an Observable that emits items based on applying a function that you
  12. * supply to each item emitted by the source Observable, where that function
  13. * returns an Observable, and then merging those resulting Observables and
  14. * emitting the results of this merger.
  15. *
  16. * @example <caption>Map and flatten each letter to an Observable ticking every 1 second</caption>
  17. * var letters = Rx.Observable.of('a', 'b', 'c');
  18. * var result = letters.mergeMap(x =>
  19. * Rx.Observable.interval(1000).map(i => x+i)
  20. * );
  21. * result.subscribe(x => console.log(x));
  22. *
  23. * // Results in the following:
  24. * // a0
  25. * // b0
  26. * // c0
  27. * // a1
  28. * // b1
  29. * // c1
  30. * // continues to list a,b,c with respective ascending integers
  31. *
  32. * @see {@link concatMap}
  33. * @see {@link exhaustMap}
  34. * @see {@link merge}
  35. * @see {@link mergeAll}
  36. * @see {@link mergeMapTo}
  37. * @see {@link mergeScan}
  38. * @see {@link switchMap}
  39. *
  40. * @param {function(value: T, ?index: number): ObservableInput} project A function
  41. * that, when applied to an item emitted by the source Observable, returns an
  42. * Observable.
  43. * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
  44. * Observables being subscribed to concurrently.
  45. * @return {Observable} An Observable that emits the result of applying the
  46. * projection function (and the optional `resultSelector`) to each item emitted
  47. * by the source Observable and merging the results of the Observables obtained
  48. * from this transformation.
  49. * @method mergeMap
  50. * @owner Observable
  51. */
  52. export declare function mergeMap<T, R>(this: Observable<T>, project: (value: T, index: number) => ObservableInput<R>, concurrent?: number): Observable<R>;