Whole-Pattern Aliases
This example uses as to inspect a result while keeping the whole value available. The positive function checks the number inside Ok, returns the original result if it is positive, and passes existing errors through unchanged.
positive : Try(I64, [BadNumber, NotPositive]) -> Try(I64, [BadNumber, NotPositive]) positive = |input| match input { Ok(n) as result => if n > 0 { result } else { Err(NotPositive) } Err(_) as result => result } expect positive(Ok(3)) == Ok(3) expect positive(Ok(0)) == Err(NotPositive) expect positive(Err(BadNumber)) == Err(BadNumber)
In Ok(n) as result, n is the number and result is the complete Ok(n) value. This lets us examine part of a value without having to reconstruct the whole thing when returning it.
Output
Run this from the directory that has main.roc in it:
$ roc test main.roc All (3) tests passed in 9.2 ms.
Validated with Roc nightly-2026-10-29-a0a9fc2.