Skip to content

Instantly share code, notes, and snippets.

@AKST
Last active December 20, 2015 17:59
Show Gist options
  • Save AKST/6172525 to your computer and use it in GitHub Desktop.
Save AKST/6172525 to your computer and use it in GitHub Desktop.
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