RosettaCodeData/Task/General-FizzBuzz/Haskell/general-fizzbuzz-2.hs

24 lines
587 B
Haskell
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
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