On this page:
Threading Macros
8.14

Threading Macros🔗

Alexis King <lexi.lambda@gmail.com>

 (require threading) package: threading-lib

Arguably, “pipeline macros” would be a much better name than “threading macros”, as the forms provided by this package have nothing to do with threads. The choice of the word “threading” comes from Clojure’s threading macros, which were the original inspiration for this package. The author apologizes for not having the prudence to borrow the idea under a different name.

This library provides a set of threading macros that help flatten nested expressions into a more readable form. In essence, they allow a sequence of transformations to be expressed as a “pipeline”, similar to Unix pipes. Alongside the core threading operator, ~>, threading provides a number of variants and helper macros useful for pipeline-oriented programming.

    1 Introduction: Reducing nesting with ~>

      1.1 How ~> works

      1.2 Controlling the threading position with _

      1.3 Functions that thread: lambda~> and lambda~>*

      1.4 Threading into non-function forms

    2 Pipeline Helpers

      2.1 Short-circuiting pipelines: and~>

      2.2 Conditional pipelines: when~>, unless~>, and cond~>

      2.3 Pipeline splitting: tee~>

    3 API Reference

      3.1 Conditional Operators

      3.2 Deprecated Forms