OxL Reference

5.5 Pattern matching

oxl
match result {
  Receipt r if r.amount > LIMIT => review(r)
  Receipt r                     => ok(r)
  Declined(reason)              => warn(reason)
  Timeout | Unavailable         => retryLater()
  _                             => fail Unknown
}
PatternExample
literal, range0, "x", 1..=9
placeholder_
bindingx, mutable binding: var x
typeReceipt, with a binding Receipt r
enum variantCircle(r), .Circle(r), Rect(w: w, ..)
dataUser{ name, role: .Admin, .. }
tuple(a, _, c)
list/slice[], [x], [first, ..rest]
alternativeA | B (the bindings are the same in all branches)
guardpattern if condition

A match MUST be exhaustive. Branches are separated by a line break or a comma; the body of a branch is an expression or a block.

An additional pattern: x? — matches any value except none and binds it to x (while let d? = queue.pop() { … }).

non-exhaustive, pattern-bindings, unreachable-arm

See also

Source: docs/spec/oxl-standard.en.md