operator + abstract method
Combines this pulse and other into a composite CollectivePulse.
This operator performs binary composition. It treats both operands
as distinct units, creating a new pulse whose payload contains exactly
two elements: this pulse and the other pulse.
When to use
- Pairing: Use this to link two signals where the relationship between them (the "left" and "right" sides) is semantically meaningful.
- Ad-hoc Bundling: Quickly grouping two pulses for simultaneous propagation without pre-allocating a list.
How it works
Unlike Pulse.batch, this operator does not flatten the resulting structure. If you add a CollectivePulse to a Pulse, the result is a new CollectivePulse where one of the two elements is itself a CollectivePulse.
Comparison: + vs Pulse.batch
| Feature | operator + |
Pulse.batch() |
|---|---|---|
| Logic | Binary Composition (Nesting) | Flattened Aggregation |
| Structure | Always creates a pair | Creates a flat list |
| Payload | [Pulse, Pulse] |
[Pulse, Pulse, Pulse, ...] |
Non‑obvious: Iteration and Nesting
If you chain this operator (e.g., p1 + p2 + p3), you create a nested
hierarchy. Iterating over the top-level payload will yield a length
of 2: the first element being the result of (p1 + p2) and the second
being p3.
Example
final p1 = Pulse('A');
final p2 = Pulse('B');
final p3 = Pulse('C');
// Binary composition creates a nested structure
final nested = p1 + p2 + p3;
print(nested.payload.length); // 2
print(nested.payload.first is CollectivePulse); // true
// Batching creates a flat structure
final flat = Pulse.batch([p1, p2, p3]);
print(flat.payload.length); // 3
See also:
- Pulse.batch for creating a flat collection of pulses.
- isComposite to determine if a pulse contains multiple signals.
Implementation
Pulse operator +(covariant Pulse other);