Skip to content

Instantly share code, notes, and snippets.

@3noch
Last active January 3, 2016 11:48
Show Gist options
  • Save 3noch/8458200 to your computer and use it in GitHub Desktop.
Save 3noch/8458200 to your computer and use it in GitHub Desktop.
Aligns a "|" delimited file
module Main where
import Data.Functor ((<$>))
import Data.List (intercalate, transpose)
import Data.List.Split (splitOn)
(<$$>) = fmap . fmap
main = interact $ unlines . (intercalate "|" <$>) . go . (splitOn "|" <$>) . lines
where
go xss = [(uncurry align <$> zip (init maxWidths) xs) ++ [last xs] | xs <- xss]
where
align m x = x ++ replicate (m - length x) ' '
maxWidths = maximum <$> (length <$$> transpose xss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment