merge<T> static method

FlowHandle merge<T>(
  1. Cell source, {
  2. required List<Cell> sources,
})

Merge extra sources; source only arms future.

merge acts as a Multi-Source Merger. The bound source is only used to arm the instruction.

When to use

Use merge when:

  • You want to merge multiple cells into one stream
  • The arming pulse should not be forwarded
  • You're using a dedicated gate to start the merge
  • You're combining events from multiple sources

How it works

  1. The first source pulse arms the instruction.
  2. Observers are started on all sources cells.
  3. Pulses from all sources are forwarded with step Merge.
  4. The arming pulse is not forwarded (by default).

Parameters:

  • source: The Source Cell. The cell providing the trigger.
  • sources: The Cells to Merge. Cells whose pulses will be forwarded.

Type Parameters:

  • T: The type of the input payload.

Returns:

A FlowHandle that can be used to observe the merged values.

Example

final gate = Cell.ingress<void>();
final left = Cell.ingress<int>();
final right = Cell.ingress<int>();

final handle = Flow.merge<int>(
  gate.cell,
  sources: [left.cell, right.cell],
);

gate.emit(null); // arms only
left.emit(10); // emitted
right.emit(20); // emitted
// Result: `[10, 20]`

See Also:

  • mergeWith: For merging source with others.
  • mergeAll: For flattening inner sequences.

Implementation

static FlowHandle merge<T>(
  Cell source, {
  required List<Cell> sources,
}) {
  return Merge<T>(sources).toHandle(source: source);
}