RosettaCodeData/Task/General-FizzBuzz/Haskell/general-fizzbuzz-2.hs
2023-07-01 13:44:08 -04:00

23 lines
587 B
Haskell

type Rule = (Int, String)
----------------- FIZZETC (USING RULE SET) ---------------
fizzEtc :: [(Int, String)] -> [String]
fizzEtc rules = foldr nextLine [] [1 ..]
where
nextLine x a
| null noise = show x : a
| otherwise = noise : a
where
noise = foldl reWrite [] rules
reWrite s (m, k)
| 0 == rem x m = s <> k
| otherwise = s
------------------- TEST OF SAMPLE RULES -----------------
fizzTest :: [String]
fizzTest = fizzEtc [(3, "Fizz"), (5, "Buzz"), (7, "Baxx")]
main :: IO ()
main = mapM_ putStrLn $ take 20 fizzTest