Slide 11 of 37
Result<T, E>
func half(n: Int): Result<Int, Str> {
if n % 2 == 0 { return Result.Ok(n / 2) }
return Result.Error("not even")
}
proc main(): void {
if half(4) is Result.Ok(v) { echo v }
else if half(4) is Result.Error(why) { echo why }
}
Result is the language's one built-in generic union, and it is how every fallible operation reports itself: Result.Ok(value) or Result.Error(payload). Matching both variants with `is` is exhaustive, which lets a function written over a Result skip a dead else branch entirely.