The random instance generator and other improvements.
[match/match.git] / program / Formatter.hs
CommitLineData
967c39ef
MM
1module Formatter where
2import Data.List
3
4padWith :: a -> Int -> [a] -> [a]
5padWith _ 0 l = l
6padWith e n [] = replicate n e
7padWith e (n+1) (h:t) = h:(padWith e n t)
8
9formatTable :: [[String]] -> String
10formatTable cells =
11 let columnWidths = map (\col -> maximum $ map length col)
12 $ transpose cells in
13 intercalate "\n" $
14 map (\row ->
15 let rowCells = zipWith (padWith ' ') columnWidths row in
16 intercalate " " rowCells
17 ) cells