merge<T> static method
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
- The first source pulse arms the instruction.
- Observers are started on all
sourcescells. - Pulses from all
sourcesare forwarded with stepMerge. - 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:
Implementation
static FlowHandle merge<T>(
Cell source, {
required List<Cell> sources,
}) {
return Merge<T>(sources).toHandle(source: source);
}