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:34

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

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 GNU AGPL v3 or later.