Ad
Code
Diff
  • module Solution (fizzbuzz) where
    
    make_mod_repr d repr n | n `mod` d == 0 = Just repr
                           | otherwise      = Nothing
                           
    mod_3_repr = make_mod_repr 3 "fizz"
    mod_5_repr = make_mod_repr 5 "buzz"
    
    fizzbuzz :: [String] -> Int -> Int -> [String]
    fizzbuzz _ i n = map fizzbuzz' [i .. n]
      where
        fizzbuzz' x | repr == Nothing = show x
                    | otherwise       = (\(Just x) -> x) repr
            where 
                repr = foldl (\acc f -> acc <> f x) Nothing [mod_3_repr, mod_5_repr]
    
    -- we don't need the empty accumulator
    -- could be fizzbuzz :: Int -> Int -> [String]
    • module Solution where
    • module Solution (fizzbuzz) where
    • make_mod_repr d repr n | n `mod` d == 0 = Just repr
    • | otherwise = Nothing
    • mod_3_repr = make_mod_repr 3 "fizz"
    • mod_5_repr = make_mod_repr 5 "buzz"
    • fizzbuzz :: [String] -> Int -> Int -> [String]
    • fizzbuzz _ i n = map fizzbuzz' [i .. n]
    • where
    • fizzbuzz' x | repr == Nothing = show x
    • | otherwise = (\(Just x) -> x) repr
    • where
    • repr = foldl (\acc f -> acc <> f x) Nothing [mod_3_repr, mod_5_repr]
    • -- we don't need the empty accumulator
    • -- could be fizzbuzz :: Int -> Int -> [String]