Pipes
Inspired by Unix shell pipes (|), the pipe operator >> chains function calls left-to-right:
dbl x:n>n;*x 2 -- double a numberinc x:n>n;+x 1 -- add 1transform x:n>n;(x>>dbl>>inc) -- double, then add 1x>>dbl>>inc means: take x, pass to dbl, pass result to inc.
Without pipes
Section titled “Without pipes”transform x:n>n;inc(dbl x)With pipes
Section titled “With pipes”transform x:n>n;(x>>dbl>>inc)Pipes read left-to-right, matching the data flow direction.
Composition patterns
Section titled “Composition patterns”Pipes shine when you compose small, reusable functions into larger transforms.
Chaining numeric transforms
Section titled “Chaining numeric transforms”dbl x:n>n;*x 2 -- double a numberinc x:n>n;+x 1 -- add 1sq x:n>n;*x x -- square a number
transform x:n>n;(x>>dbl>>inc>>sq) -- double, add 1, then squareilo 'dbl x:n>n;*x 2 inc x:n>n;+x 1 sq x:n>n;*x x transform x:n>n;(x>>dbl>>inc>>sq)' transform 3# → 49 (3 → 6 → 7 → 49)Chaining list operations
Section titled “Chaining list operations”Pipes work naturally with list higher-order functions:
map fn listappliesfnto every elementflt fn listkeeps elements wherefnreturns true (filter)fld fn init listreduces a list to a single value (fold)
sq x:n>n;*x x -- square a numberpos x:n>b;>x 0 -- is positive?main xs:L n>L n;xs >> flt pos >> map sq -- filter positives, square eachRead it left to right: take xs, keep only positives, square each.
ilo 'sq x:n>n;*x x pos x:n>b;>x 0 main xs:L n>L n;xs >> flt pos >> map sq' main -3,-1,0,2,4# → [4, 16] (-3,-1,0 filtered out; 2→4, 4→16)Eliminating intermediate variables
Section titled “Eliminating intermediate variables”Without pipes, you need intermediate bindings:
transform x:n>n;a=dbl x;b=inc a;sq bWith pipes, the same logic is a single expression:
transform x:n>n;(x>>dbl>>inc>>sq)Pipes with auto-unwrap
Section titled “Pipes with auto-unwrap”Pipes combine with ! for functions that return R (Result) types:
f x:n>>g!>>hThis desugars to h(g!(f(x))) - if g returns an error, it propagates immediately.
Parentheses in multi-function files
Section titled “Parentheses in multi-function files”In a file with multiple functions, wrap pipe chains in parentheses for non-last functions. This prevents the parser from consuming the next function’s name:
dbl-inc x:n>n;(x>>dbl>>inc) -- parens needed (not the last function)inc-sq x:n>n;x>>inc>>sq -- last function, no parens needed