pipe is a left-to-right threading macro that passes an initial value through a sequence of unary functions.
Syntax
(pipe ⟨init-expr⟩ ⟨fn-expr⟩+)
Semantics
- Requires at least two subforms (
⟨init-expr⟩and at least one⟨fn-expr⟩). (pipe x f1 f2 ... fn)expands to(fn (... (f2 (f1 x))))(equivalent to(nest fn ... f2 f1 x)).- Each
⟨fn-expr⟩must be an expression of unary function type (such as a unary function name, anfnorƒlambda, or a unary conversion macro(as T)), applied to the result of the preceding step. - Because
pipeis a purely syntactic macro expansion into nested function calls, it introduces no intermediate closures or runtime overhead.
Examples
(coalton
(pipe (the (List Integer) [3 1 4 1 5])
reverse
(fn (xs) (map ƒx.(* x 2) xs))
sum))
; => 28