fxPipe
Typed left-to-right composition. The last .then is the function — no .build().
Lecture
pipe threads a value through a list of functions, but the
list is dynamic. fxPipe is the typed form that
returns a function:
final f = fxPipe3(parse, normalise, score);
f(line);
fx(lines).map(f);
Each .then returns the chain so far, so there is nothing
to "finish." Call it, or pass it to map /
parallel.
fxPipe(parse) is just parse — the name marks
the start. parse.then(normalise) works too.
Two .parallel calls copy every result back to this isolate
and out again. One composed worker pays the hop once:
await fx(lines)
.parallel(4, fxPipe3(parse, normalise, score), chunked: true)
.toList();
Stages must be sendable when the result is a
parallel worker. juxt is the other
direction: several functions, one input, a list of results.
fxPipe2..fxPipe5 fuse the same stages into
one closure, so a hot map or
parallel worker does not pay a nested call per
.then. Arity stops at 5, like
zipOrAccumulate2..5. Longer than that, keep chaining
.then or write the fused function yourself.
parallel is VM-only, so the playgrounds below run the
same composed function through map.
Demo 1 · parse, normalise, score
Three stages, one function. On the VM you would pass this to
parallel; here it runs in the playground.
Demo 2 · Same numbers as three maps
fxPipe is composition, not a new operator. Three
maps and one composed function print the same list.
Try it yourself
Exercise: compose parse → normalise →
score and keep only rows that score at least 4.