Skip to content

Instantly share code, notes, and snippets.

@binq
Created November 19, 2021 18:21
Show Gist options
  • Save binq/f3db804c0e15fea813538483925c260a to your computer and use it in GitHub Desktop.
Save binq/f3db804c0e15fea813538483925c260a to your computer and use it in GitHub Desktop.
both :: Maybe a -> Maybe a -> Bool
both (Just _) (Just _) = True
both _ _ = False
f n =
let
f = bool Nothing (Just Fizz) (n % 3 == 0)
b = bool Nothing (Just Buzz) (n % 5 == 0)
u = bool Nothing (Just FizzBuzz) (all isJust [f, b])
g = bool Nothing (Just (Got n)) (all isNone [f, b])
in find isJust [g, u, b, f]
fizzBuzz = fmap f [1..]
main = show . take 5 $ fizzBuzz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment