Last active
November 7, 2016 20:59
-
-
Save ox/df9828aafc644d804d290fb0cb72265e to your computer and use it in GitHub Desktop.
Formats input separated by tabs into columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Data.List (transpose, words, lines, unwords, unlines) | |
import Data.Text (justifyLeft, unpack, pack) | |
prettyText :: [[String]] -> [[String]] | |
prettyText inputRows = | |
let colWidths = map (maximum . map length) (transpose inputRows) | |
indentFn = map (\x -> unpack . justifyLeft (x+2) ' ' . pack) colWidths -- right-pad each elem by col width + 2 | |
in map (zipWith ($) indentFn) inputRows -- apply each column's padding to each element | |
main = do | |
input <- getContents | |
putStr $ unlines $ map unwords $ prettyText $ map words $ lines input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment