module Utility.Table where
type Table = [[String]]
tableWithHeader :: [String] -> [[String]] -> Table
tableWithHeader header rows = header : map linesep header : rows
where
linesep = map (const '-')
formatTable :: Table -> [String]
formatTable table = map (\r -> unwords (map pad (zip r rowsizes))) table
where
pad (cell, size) = cell ++ take (size length cell) padding
padding = repeat ' '
rowsizes = sumrows (map (map length) table)
sumrows [] = repeat 0
sumrows [r] = r
sumrows (r1:r2:rs) = sumrows $ map (uncurry max) (zip r1 r2) : rs