Pattern Matching
Basic Match
wyn
fn describe(n: int) -> string {
return match n {
0 => "zero"
1 => "one"
_ => "other"
}
}Guards
wyn
fn classify(n: int) -> string {
return match n {
0 => "zero"
_ if n < 0 => "negative"
_ if n > 100 => "big"
_ => "normal"
}
}Match with Arrays
wyn
for i in [-1, 0, 1, 42, 200] {
println("${i}: ${classify(i)}")
}Output:
-1: negative
0: zero
1: normal
42: normal
200: bigTry It
Press Run or Ctrl+Enter