Skip to content

Instantly share code, notes, and snippets.

@joachifm
Created September 10, 2014 05:26
Show Gist options
  • Save joachifm/81af30fe5122e91140a9 to your computer and use it in GitHub Desktop.
Save joachifm/81af30fe5122e91140a9 to your computer and use it in GitHub Desktop.
Fizz
import Control.Monad (guard)
import Control.Applicative ((<|>), (*>), pure)
import Data.Maybe (mapMaybe)
import Data.Monoid ((<>))
fizzBuzz :: [Integer] -> [String]
fizzBuzz = mapMaybe (\x -> g 3 "Fizz" x <> g 5 "Buzz" x <|> pure (show x))
where g d s x = guard ((x `rem` d) == 0) *> pure s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment