5 ms·
Another way to do it would be newtype Words = Words { getWords :: String } instance Semigroup Words where Words a <> Words b = Words (a <> " " <
by kqr 1y ago
Another way to do it would be
newtype Words = Words { getWords :: String }
instance Semigroup Words where
Words a <> Words b = Words (a <> " " <> b)
instance Monoid Words where
mempty = Words mempty
fizzbuzz i =
maybe (show i) (<> "!") . fmap getWords . mconcat $
[ Words "fizz" <$ guard (rem i 3 == 0)
, Words "buzz" <$ guard (rem i 5 == 0)
]
but at this point I agree lists might be more clear.