source: trip-planner-front/node_modules/rxjs/src/internal/operators/concatMap.ts@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.4 KB
Line 
1import { mergeMap } from './mergeMap';
2import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';
3
4/* tslint:disable:max-line-length */
5export function concatMap<T, O extends ObservableInput<any>>(project: (value: T, index: number) => O): OperatorFunction<T, ObservedValueOf<O>>;
6/** @deprecated resultSelector no longer supported, use inner map instead */
7export function concatMap<T, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: undefined): OperatorFunction<T, ObservedValueOf<O>>;
8/** @deprecated resultSelector no longer supported, use inner map instead */
9export function concatMap<T, R, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>;
10/* tslint:enable:max-line-length */
11
12/**
13 * Projects each source value to an Observable which is merged in the output
14 * Observable, in a serialized fashion waiting for each one to complete before
15 * merging the next.
16 *
17 * <span class="informal">Maps each value to an Observable, then flattens all of
18 * these inner Observables using {@link concatAll}.</span>
19 *
20 * ![](concatMap.png)
21 *
22 * Returns an Observable that emits items based on applying a function that you
23 * supply to each item emitted by the source Observable, where that function
24 * returns an (so-called "inner") Observable. Each new inner Observable is
25 * concatenated with the previous inner Observable.
26 *
27 * __Warning:__ if source values arrive endlessly and faster than their
28 * corresponding inner Observables can complete, it will result in memory issues
29 * as inner Observables amass in an unbounded buffer waiting for their turn to
30 * be subscribed to.
31 *
32 * Note: `concatMap` is equivalent to `mergeMap` with concurrency parameter set
33 * to `1`.
34 *
35 * ## Example
36 * For each click event, tick every second from 0 to 3, with no concurrency
37 *
38 * ```ts
39 * import { fromEvent, interval } from 'rxjs';
40 * import { concatMap, take } from 'rxjs/operators';
41 *
42 * const clicks = fromEvent(document, 'click');
43 * const result = clicks.pipe(
44 * concatMap(ev => interval(1000).pipe(take(4)))
45 * );
46 * result.subscribe(x => console.log(x));
47 *
48 * // Results in the following:
49 * // (results are not concurrent)
50 * // For every click on the "document" it will emit values 0 to 3 spaced
51 * // on a 1000ms interval
52 * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
53 * ```
54 *
55 * @see {@link concat}
56 * @see {@link concatAll}
57 * @see {@link concatMapTo}
58 * @see {@link exhaustMap}
59 * @see {@link mergeMap}
60 * @see {@link switchMap}
61 *
62 * @param {function(value: T, ?index: number): ObservableInput} project A function
63 * that, when applied to an item emitted by the source Observable, returns an
64 * Observable.
65 * @return {Observable} An Observable that emits the result of applying the
66 * projection function (and the optional deprecated `resultSelector`) to each item emitted
67 * by the source Observable and taking values from each projected inner
68 * Observable sequentially.
69 * @method concatMap
70 * @owner Observable
71 */
72export function concatMap<T, R, O extends ObservableInput<any>>(
73 project: (value: T, index: number) => O,
74 resultSelector?: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R
75): OperatorFunction<T, ObservedValueOf<O>|R> {
76 return mergeMap(project, resultSelector, 1);
77}
Note: See TracBrowser for help on using the repository browser.