Macros and helpers
This page catalogs pipescript’s built-in macros and helper utilities. Macros
take a bracketed body (macro[...]) or an equivalent brace body
(macro{...}; see Write brace blocks and statement blocks); helpers are plain functions you
drop into a pipeline. For the constructors that let you define your own
(macro[...], method[...]), see Define your own macros; for autodoc
signatures of the helper functions, see API reference.
Functional macros
map/filter/reduceThe familiar higher-order functions in bracketed macro form. The function to apply goes in the brackets, and
fmay be omitted:>>> range(1, 5) |> reduce[$ * $] # 1*2*3*4 24 >>> [1, 2, 3, 4] |> filter[$ % 2 == 0] |> list [2, 4]
fThe quick-lambda macro: turns a placeholder expression into a function.
f[$ + $]is a two-argument adder. See Build partials and quick lambdas.
Side-effect and flow helpers
doRuns a function for its side effect and forwards the original value unchanged (like toolz’s
do):>>> 2 |> $ + 2 |> do[print] |> $ + 2 4 6
peekShorthand for
do[print]– prints the value and returns it. Seepipescript.peek().nullSwallows its input and returns
None– useful as a final stage to suppress a notebook’s automatic rendering of the pipeline result. Seepipescript.null().collapseExtracts the single non-null value out of a tuple (as produced by
forkwithwhenbranches); raises if there is not exactly one. Seepipescript.collapse().
Branching macros
fork/parallelApply several functions to the same input and return their results as a tuple.
parallelruns the branches concurrently; otherwise it behaves likefork:>>> 5 |> fork[$ + 1, $ * 2] (6, 10)
when/unlesswhenforwards its input when a predicate holds and otherwise yields a null that later stages (e.g.collapse) drop;unlessis its negation.otherwiseUsed as the final branch of a
fork/parallel; runs only when every other branch produced a null.
Iteration macros
repeatRepeatedly applies its body until the body yields a null, then returns the last non-null value.
untilAn alias of
unless, read naturally as the stopping condition insiderepeat(repeat[until[$ == 1] .> step]).foreachA method macro that runs a block once per item of an iterable; see Use method macros.
Concurrency
futureSchedules its body on another thread and immediately returns a
concurrent.futures.Futurefor the eventual result:>>> 2 |> future[$ + 2] |> $.result() 4
Defining your own
macro/methodConstructors that build a new macro from a pipescript template (using
$$for the argument) or from a Python AST-transforming callable. Full treatment in Define your own macros.
Other helpers
pipescript’s public helper surface also includes small utilities such as
push / pop (a value stack), lshift / rshift / unnest (tuple
reshaping), replace, write / read (keyed memory), expect,
memoize, ntimes, once, and context. See API reference for their
autodoc signatures.