Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Pipe

To chain multiple function calls and pipe data through Mond has |>.

(use std/io)

(let add_two {x y} (+ x y))

(let main {}
  (let [x (|> 10
              (add_two 1)
              (add_two 1)
              (add_two 1)
              (add_two 1)
              (add_two 1))]
    (io/debug x)))

Running this will print

15

Placeholder Pipe

By default, each pipe step receives the current value as its single argument:

(|> x f g)

This is equivalent to:

(g (f x))

If you need to place the piped value somewhere else in a step, use _ as a placeholder:

(|> 3
    (add 1 _)
    (mul _ 2))

This is equivalent to:

(mul (add 1 3) 2)

Rules:

  • If a step has no _, |> keeps normal behavior and passes the value as a single argument.
  • If a step has exactly one _, the piped value is inserted at _.
  • If a step has more than one _, compilation fails.