fizzbuzz
FizzBuzz: match guards, string interpolation and a `for` over a range.
examples/basics/fizzbuzz.dawn
# FizzBuzz: match guards, string interpolation and a `for` over a range.
#
# Run: dawn run examples/basics/fizzbuzz.dawn
fn shout(n: Int) -> String =
match n {
x if x % 15 == 0 -> "FizzBuzz"
x if x % 3 == 0 -> "Fizz"
x if x % 5 == 0 -> "Buzz"
x -> "$x"
}
pub fn main() -> Unit !io = {
for i in 1..21 {
println(shout(i))
}
}
test "the divisible-by-fifteen arm has to come first" {
assert shout(15) == "FizzBuzz"
assert shout(9) == "Fizz"
assert shout(10) == "Buzz"
assert shout(7) == "7"
}