mergeMapTo

function stable

Projects each source value to the same Observable which is merged multiple times in the output Observable.

mergeMapTo<T, R, O extends ObservableInput<unknown>>(innerObservable: O, resultSelector?: number | ((outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R), concurrent: number = Infinity): OperatorFunction<T, ObservedValueOf<O> | R>

Parameters

innerObservable

An Observable to replace each value from the source Observable.

resultSelector

Optional. Default is undefined.

Type: number | ((outerValue: T, innerValue: ObservedValueOf, outerIndex: number, innerIndex: number) => R).

concurrent

Optional. Default is Infinity.

Maximum number of input Observables being subscribed to concurrently.

Returns

OperatorFunction<T, ObservedValueOf<O> | R>: A function that returns an Observable that emits items from the given innerObservable.

Description

It's like mergeMap, but maps each value always to the same inner Observable.

mergeMapTo marble diagram

Maps each source value to the given Observable innerObservable regardless of the source value, and then merges those resulting Observables into one single Observable, which is the output Observable.

Example

For each click event, start an interval Observable ticking every 1 second

import { fromEvent, interval } from 'rxjs';
import { mergeMapTo } from 'rxjs/operators';

const clicks = fromEvent(document, 'click');
const result = clicks.pipe(mergeMapTo(interval(1000)));
result.subscribe(x => console.log(x));

See Also

© 2015–2021 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/operators/mergeMapTo