3 ms·
I agree. But you're also not supposed to have separate booleans for each special print, because when you have many special prints it gets annoying to extend. I
by kqr 1y ago
I agree. But you're also not supposed to have separate booleans for each special print, because when you have many special prints it gets annoying to extend.
I've always liked this solutiin, which avoids that: https://archive.is/KJ39B https://archive.is/KJ39B
fizzbuzz i =
fromMaybe (show i) . mconcat $
[ "fizz" <$ guard (i `rem` 3 == 0)
, "buzz" <$ guard (i `rem` 5 == 0)
]
main =
for_ [1..100] $
putStrLn . fizzbuzz
This allows you to add special prints by adding just the one line of code, changing nothing else.