Last active
December 20, 2015 17:59
-
-
Save AKST/6172525 to your computer and use it in GitHub Desktop.
This file contains 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 Data.Monoid ((<>)) | |
import Data.Maybe (fromMaybe) | |
makeXzzer :: Int -> String -> (Int -> Maybe String) | |
makeXzzer deviser msg = | |
\x -> if x `mod` deviser == 0 | |
then Just msg | |
else Nothing | |
fizzer :: Int -> Maybe String | |
fizzer x = makeXzzer 3 "fizz" x | |
buzzer :: Int -> Maybe String | |
buzzer x = makeXzzer 5 "buzz" x | |
bazzer :: Int -> Maybe String | |
bazzer x = makeXzzer 7 "bazz" x | |
fizzBuzzBazz :: Int -> String | |
fizzBuzzBazz x = fromMaybe (show x) $ | |
fizzer x <> | |
buzzer x <> | |
bazzer x | |
-- IO | |
main = mapM_ (putStrLn . fizzBuzzBazz) [1..105] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment