Skip to content

Pipes

Ferret’s pipe operator (|>) passes the left-hand value into a function call on the right-hand side.

By default, the value is appended as the first argument:

import "std/io";
fn add(x: i32, y: i32) -> i32 { return x + y; }
let result := 5 |> add(10); // add(5, 10)
io::Println(result);

Use _ to control where the piped value goes:

import "std/io";
fn add(x: i32, y: i32) -> i32 { return x + y; }
let result := 5 |> add(10, _); // add(10, 5)
io::Println(result);

Only one placeholder is allowed in a pipe stage.

Pipes compose cleanly:

fn add(x: i32, y: i32) -> i32 { return x + y; }
fn mul(x: i32, y: i32) -> i32 { return x * y; }
let result := 5 |> add(10) |> mul(2); // mul(add(10, 5), 2)

If you are not passing any extra arguments, the function call can omit parentheses:

fn incr(v: i32) -> i32 { return v + 1; }
let x := 0
|> incr
|> incr
|> incr;

Once you pass additional arguments, you must use parentheses:

let value := 5 |> add(10); // ok
let other := 5 |> add(_, 10); // ok
// let bad := 5 |> add 10; // invalid
  • The right-hand side must be a callable (function or function value).
  • The piped value must type-check against the target parameter (or placeholder position).
  • Only one placeholder (_) is allowed per pipe stage.
  • You cannot pipe a void value into the next stage.