lang_2023/tests/match.lang

16 lines
381 B
Text
Raw Normal View History

2023-03-31 12:10:12 +03:00
def fruit_cost : fruit = {
2023-04-25 21:21:36 +03:00
return (match fruit with
| $Banana -> 11
| $Apple | $Orange -> 7)
2023-03-31 12:10:12 +03:00
}
def amount_to_string : x is_zero_separated = {
2023-04-25 21:21:36 +03:00
const ans = match x with
| 0 ? is_zero_separated () -> "Zero"
| 0 | 1 | 2 | 3 | 4 -> "Few"
| x ? (5..9).contains x -> "Several"
| x ? (10..19).contains x -> "Pack"
| _ -> "Lots"
2023-03-31 12:10:12 +03:00
return ans
}