module Formatter where import Data.List #if __GLASGOW_HASKELL__ <= 606 intercalate xs xss = concat (intersperse xs xss) #endif padWith :: a -> Int -> [a] -> [a] padWith _ 0 l = l padWith e n [] = replicate n e padWith e (n+1) (h:t) = h:(padWith e n t) formatTable :: [[String]] -> String formatTable cells = let columnWidths = map (\col -> maximum $ map length col) $ transpose cells in intercalate "\n" $ map (\row -> let rowCells = zipWith (padWith ' ') columnWidths row in intercalate " " rowCells ) cells