Advertisement
Revolucent

Haskell FizzBuzz

Jan 1st, 2021
1,907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Main where
  2.  
  3. import Control.Applicative
  4. import Data.Maybe
  5.  
  6. f :: Integer -> String -> Integer -> Maybe String
  7. f k s i = if i `rem` k == 0 then Just s else Nothing
  8.  
  9. opts = [f 15 "FizzBuzz", f 3 "Fizz", f 5 "Buzz"]
  10.  
  11. fizzBuzz n = fromJust $ foldr1 (<|>) $ (opts <*> pure n) <> [Just $ show n]
  12.  
  13. main = mapM_ (putStrLn . fizzBuzz) [1..1000]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement