Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / src/public-api / merge

Function: merge() ​

merge<T>(...sources): Atom<T>

Defined in: projects/libraries/streamix/src/lib/factories/merge.ts:40

Merges multiple source streams into a single atom, emitting values as they arrive from any source.

This is useful for combining data from multiple independent sources into a single, unified stream of events. Unlike zip, it does not wait for a value from every stream before emitting; it emits values as they become available.

The merged atom completes only after all source streams have completed. If any source stream errors, the merged atom immediately errors.

Performance characteristics:

  • Synchronous sources with buffered values are drained immediately
  • Asynchronous sources are pulled concurrently

Ordering note: when several sources have values available at the same tick, they are interleaved round-robin (one value per source per pass) rather than drained first-to-last. merge(from([1,2]), from([3]), from([4])) emits 1, 3, 4, 2. RxJS drains synchronous sources in subscription order (1, 2, 3, 4); prefer concat when strict order matters.

Type Parameters ​

T ​

T = any

The type of the values in the streams.

Parameters ​

sources ​

...PipeInput<T>[]

Atoms, streams, or values (including promises) to merge.

Returns ​

Atom<T>

A new atom that emits values from all input streams.

Example ​

typescript
const fast = interval(10);
const slow = interval(100);
const instant = from([1, 2, 3]);

// Values emitted as they arrive
merge(fast, slow, instant).forEach(console.log);

Released under the MIT License.