Skip to content

Instantly share code, notes, and snippets.

@LSLeary
Last active January 24, 2019 10:19
Show Gist options
  • Save LSLeary/7df9c04829ba3aa69d7099ce2e00eb7d to your computer and use it in GitHub Desktop.
Save LSLeary/7df9c04829ba3aa69d7099ce2e00eb7d to your computer and use it in GitHub Desktop.
{-# LANGUAGE TypeApplications #-}
import Control.Applicative (ZipList(..))
import Data.Monoid (Ap(..))
import Data.Maybe (fromMaybe)
import Data.Foldable (traverse_)
every :: Int -> String -> Ap ZipList (Maybe String)
every m s = (Ap . ZipList) (cycle $ Just s : replicate (m - 1) Nothing)
fizzbuzzjazz :: [String]
fizzbuzzjazz
= drop 1 . getZipList . getAp
$ fromMaybe . show @Int
<$> (Ap . ZipList) [0..]
<*> every 3 "fizz" <> every 5 "buzz" <> every 7 "jazz"
main :: IO ()
main = traverse_ putStrLn (take (3 * 5 * 7) fizzbuzzjazz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment