Skip to content

Operators Reference

OperatorDescriptionExample
+Additiona + b
-Subtraction / negationa - b, -x
*Multiplicationa * b
/Divisiona / b
%Moduloa % b

Equality operators compile to strict equality (===, !==). Structural equality is used for == between same types.

OperatorDescriptionCompiles to
==Equal===
!=Not equal!==
<Less than<
>Greater than>
<=Less or equal<=
>=Greater or equal>=
OperatorDescriptionExample
&&Logical ANDa && b
||Logical ORa || b
!Logical NOT!a
OperatorDescriptionExample
|>Pipex |> f
|>?Pipe-unwrapx |>? f

The pipe operator passes the left side as the first argument to the right side. Use _ as a placeholder for non-first-argument positions.

let a = x |> f // f(x)
let b = x |> f(a, _) // f(a, x)
let c = x |> f |> g // g(f(x))
let d = x |> match {
Ok(v) -> v,
Err(_) -> 0,
}

The pipe-unwrap operator |>? pipes the value and then unwraps the result — equivalent to (x |> f)?.

x |>? f // (x |> f)? — unwraps Result/Option, returns early on Err/None
OperatorDescriptionExample
?Unwrap Result/Optionexpr?

The ? operator unwraps Ok(value) or Some(value), and returns early with Err(e) or None on failure. Only valid inside functions that return Result or Option.

OperatorContextExample
..Record spread in brace construction (must be last)User { name: "New", ..existing }
..Array rest in match patterns[first, ..rest]
...Type spread in record definitionstype B = { ...A, extra: string }
1..10Range pattern in matchmatch n { 1..10 -> "small" }
OperatorContextMeaning
->Closures, match arms, return types, function types(x) -> x + 1, Ok(x) -> x, let add(a, b) -> number, (string) -> number
.fieldDot shorthand.name (implicit field-access closure)
|>Pipesdata |> transform
  1. Unary: !, -
  2. Multiplicative: *, /, %
  3. Additive: +, -
  4. Comparison: <, >, <=, >=
  5. Equality: ==, !=
  6. Logical AND: &&
  7. Logical OR: ||
  8. Pipe: |>
  9. Unwrap: ?