Created
September 10, 2014 05:26
-
-
Save joachifm/81af30fe5122e91140a9 to your computer and use it in GitHub Desktop.
Fizz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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