star/test/corpus/pattern_match.star

18 lines
328 B
Plaintext

// Test: Pattern matching
type Option<'a> =
| Some of 'a
| None
let unwrap_or = fn default opt =>
match opt with
| Some(x) => x
| None => default
end
let main = fn () =>
let x = Some(42) in
let y = None in
let result1 = unwrap_or(0, x) in
let result2 = unwrap_or(0, y) in
print(result1)