The random instance generator and other improvements.
[match/match.git] / program / Formatter.hs
diff --git a/program/Formatter.hs b/program/Formatter.hs
new file mode 100644 (file)
index 0000000..5ee5a00
--- /dev/null
@@ -0,0 +1,17 @@
+module Formatter where
+import Data.List
+
+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