aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/rxjs/src/internal/operators/mergeMap.ts
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-06-28 17:26:46 -0700
committerPinapelz <yukais@pinapelz.com>2025-06-28 17:43:56 -0700
commite4fa1e69e7ebfb627c7198fd1a9881e9327ec4d4 (patch)
tree06284a538a6008eca75051399e47db4e5d50301c /node_modules/rxjs/src/internal/operators/mergeMap.ts
initial commit: scaffolding
Diffstat (limited to 'node_modules/rxjs/src/internal/operators/mergeMap.ts')
-rw-r--r--node_modules/rxjs/src/internal/operators/mergeMap.ts94
1 files changed, 94 insertions, 0 deletions
diff --git a/node_modules/rxjs/src/internal/operators/mergeMap.ts b/node_modules/rxjs/src/internal/operators/mergeMap.ts
new file mode 100644
index 0000000..5b698ea
--- /dev/null
+++ b/node_modules/rxjs/src/internal/operators/mergeMap.ts
@@ -0,0 +1,94 @@
+import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';
+import { map } from './map';
+import { innerFrom } from '../observable/innerFrom';
+import { operate } from '../util/lift';
+import { mergeInternals } from './mergeInternals';
+import { isFunction } from '../util/isFunction';
+
+/* tslint:disable:max-line-length */
+export function mergeMap<T, O extends ObservableInput<any>>(
+ project: (value: T, index: number) => O,
+ concurrent?: number
+): OperatorFunction<T, ObservedValueOf<O>>;
+/** @deprecated The `resultSelector` parameter will be removed in v8. Use an inner `map` instead. Details: https://rxjs.dev/deprecations/resultSelector */
+export function mergeMap<T, O extends ObservableInput<any>>(
+ project: (value: T, index: number) => O,
+ resultSelector: undefined,
+ concurrent?: number
+): OperatorFunction<T, ObservedValueOf<O>>;
+/** @deprecated The `resultSelector` parameter will be removed in v8. Use an inner `map` instead. Details: https://rxjs.dev/deprecations/resultSelector */
+export function mergeMap<T, R, O extends ObservableInput<any>>(
+ project: (value: T, index: number) => O,
+ resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R,
+ concurrent?: number
+): OperatorFunction<T, R>;
+/* tslint:enable:max-line-length */
+
+/**
+ * Projects each source value to an Observable which is merged in the output
+ * Observable.
+ *
+ * <span class="informal">Maps each value to an Observable, then flattens all of
+ * these inner Observables using {@link mergeAll}.</span>
+ *
+ * ![](mergeMap.png)
+ *
+ * Returns an Observable that emits items based on applying a function that you
+ * supply to each item emitted by the source Observable, where that function
+ * returns an Observable, and then merging those resulting Observables and
+ * emitting the results of this merger.
+ *
+ * ## Example
+ *
+ * Map and flatten each letter to an Observable ticking every 1 second
+ *
+ * ```ts
+ * import { of, mergeMap, interval, map } from 'rxjs';
+ *
+ * const letters = of('a', 'b', 'c');
+ * const result = letters.pipe(
+ * mergeMap(x => interval(1000).pipe(map(i => x + i)))
+ * );
+ *
+ * result.subscribe(x => console.log(x));
+ *
+ * // Results in the following:
+ * // a0
+ * // b0
+ * // c0
+ * // a1
+ * // b1
+ * // c1
+ * // continues to list a, b, c every second with respective ascending integers
+ * ```
+ *
+ * @see {@link concatMap}
+ * @see {@link exhaustMap}
+ * @see {@link merge}
+ * @see {@link mergeAll}
+ * @see {@link mergeMapTo}
+ * @see {@link mergeScan}
+ * @see {@link switchMap}
+ *
+ * @param project A function that, when applied to an item emitted by the source
+ * Observable, returns an Observable.
+ * @param concurrent Maximum number of `ObservableInput`s being subscribed to concurrently.
+ * @return A function that returns an Observable that emits the result of
+ * applying the projection function (and the optional deprecated
+ * `resultSelector`) to each item emitted by the source Observable and merging
+ * the results of the Observables obtained from this transformation.
+ */
+export function mergeMap<T, R, O extends ObservableInput<any>>(
+ project: (value: T, index: number) => O,
+ resultSelector?: ((outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R) | number,
+ concurrent: number = Infinity
+): OperatorFunction<T, ObservedValueOf<O> | R> {
+ if (isFunction(resultSelector)) {
+ // DEPRECATED PATH
+ return mergeMap((a, i) => map((b: any, ii: number) => resultSelector(a, b, i, ii))(innerFrom(project(a, i))), concurrent);
+ } else if (typeof resultSelector === 'number') {
+ concurrent = resultSelector;
+ }
+
+ return operate((source, subscriber) => mergeInternals(source, subscriber, project, concurrent));
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage