Get the latest tech news
FizzBuzz Through Monoids
Some decade ago I read a good implementation of fizzbuzz. What set it apart was its excellent modularity.
Whatever we get out of mconcat, we pass it to fromMaybe (show i) which replaces any Nothing values with the string representation of the number coming into the function, but passes through any actual values it receives intact. This is the full fizzbuzz function that converts a number to the correct textual representation. To make it an actual program, we loop through all numbers[1..100], convert them with fizzbuzz, and print the result.
Or read this on Hacker News