Synthesizes a Composite Logic Blueprint—a specialized instruction wrapper designed for fluent orchestration and pipeline assembly.
FlowInstruction serves as the primary unit of transformation within the Cell-Flow ecosystem. It extends the foundational Instruction interface to provide ergonomic "Composition-First" mechanics, allowing developers to build complex reactive topologies through simple operator overloading and method chaining.
Unlike a Cell, which is a live, stateful node in a graph, a
FlowInstruction is a reusable blueprint describing how a pulse
should be evolved, filtered, or routed. Blueprints may be stateful:
operators that need timers, queues, or accumulators allocate their state
from a per-activation factory, so each toHandle call materializes
fresh state — two handles from one blueprint never share state, and
stateless blueprints are shared as-is.
When to use
- Pipeline Assembly: Defining a sequence of transformations (e.g., Filter -> Map -> Scan) as a single unit.
- Reusable Logic: Creating domain-specific processing blocks that can be shared across different graph branches without being bound to a source.
- DSL Authoring: Building fluent interfaces for custom reactive operators where readability and composition are paramount.
Core Mechanics
- Blueprint Logic: Describes the evolution of a pulse without holding the pulse data itself. Stateful operators allocate their mutable state per activation (see the class docs).
- Composition: Instructions are chainable using the
+operator.MapValue(...) + Filter(...)creates a new instruction link that applies both transformations serially. - Materialization: To activate an instruction, it must be bound to a source cell using toHandle. This materializes the blueprint into a live FlowHandle.
- Flyweight Receptors: Internally, these instructions are compiled into highly efficient Receptor objects to minimize memory overhead.
Type Parameters
C: Anchor Cell Type. The type of cell hosting the instruction.I: Input Pulse Type. The stimulus type entering the gate.O: Output Pulse Type. The evolved stimulus type exiting the gate.
Example: Reusable Logic Gate
// Define a reusable validation gate
const validateEmail = FlowInstruction<Cell, Pulse<String>, Pulse<String>>(
(pulse, {cell, user}) => pulse.payload.contains('@') ? pulse : null
);
// Apply the blueprint to different live sources
final loginHandle = validateEmail.toHandle(source: loginField);
final signupHandle = validateEmail.toHandle(source: signupField);
See Also
- FlowHandle: The live instance of an instruction bound to a source.
- FlowInstructionBase: The standard base implementation for custom logic.
- Instruction: The underlying core interface from
package:cell.
AI Agent Guide
Layer: Flow — the instruction interface. Not a Cell factory, not a Tissue book.
When to use: type the chain (FlowInstruction<Cell, Pulse, Pulse>), compose with +, or write a small stateless gate closure.
When NOT to use: clause-ordered policy with a resettable latch — subclass FlowInstructionBase instead (a bare closure cannot reset()).
Live signature: FlowInstruction<C, I, O>(O? Function(I pulse, {C? cell, dynamic user}) instruction, {dynamic user}) — pinned at cell_flow: 1.2.0
Do NOT confuse with: FlowInstructionBase (the base class you extend for stateful policy).
Guide: HowTo-Mitose-Flow.md §4 "When the BRD requires a custom FlowInstruction" (#flow-custom-instruction)
Example: example/cell_flow_example.dart
Cross-layer: entry is Cell.ingress; books are cell_tissue; this only decides.
Minimal compilable example
final gate = FlowInstruction<Cell, Pulse, Pulse>((p, {cell, user}) => p);
final h = gate.toHandle(source: Cell.ingress<String>().cell);
h.emit('x');
- Implemented types
-
- Instruction<
C, I, O>
- Instruction<
Constructors
- FlowInstruction(O? instruction(I pulse, {C? cell, dynamic user}), {dynamic user})
-
Synthesizes a synchronous Logic Gate—the primary mechanism for
defining pulse evolution within the reactive topography.
constfactory
-
FlowInstruction.chain(Iterable<
Instruction< instructions, {dynamic user, O? strategy(I pulse, {C? cell, dynamic user})?})Cell, Pulse, Pulse> > -
Creates a composite instruction by chaining multiple
instructionsserially.factory - FlowInstruction.future(O? instruction(I pulse, {C? cell, void future({required Pulse? result, required dynamic token})?, dynamic token, dynamic user}), {dynamic user})
-
Creates an asynchronous FlowInstruction.
constfactory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- user → dynamic
-
Custom metadata associated with this instruction for auditing, logging, or tracing.
no setter
Methods
-
call(
I pulse, {C? cell, void future({required Pulse? result, required dynamic token})?, dynamic token}) → O? -
Executes the transformation logic of this instruction synchronously.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toHandle(
{Cell? source, TestCell< Cell> testRule = TestCell.allowAll, Synapses<Pulse, Cell> synapses = Synapses.enabled}) → FlowHandle -
Materializes this instruction into a live FlowHandle bound to a
sourcecell. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator +(
covariant FlowInstruction< Cell, Pulse, Pulse> other) → FlowInstruction<C, I, O> -
Chains this instruction with
otherto create a new serial composition.override -
operator ==(
Object other) → bool -
The equality operator.
inherited