Align columns: Difference between revisions

Content added Content deleted
Line 2,499: Line 2,499:
Or, using '''Text''' and its functions as an alternative to '''[Char]''' strings:
Or, using '''Text''' and its functions as an alternative to '''[Char]''' strings:


<lang haskell>import Data.List (transpose, zip, maximumBy)
<lang haskell>import Prelude as P
import Data.Text as T
import Data.Text as T
(Text, pack, unpack, splitOn, unlines, unwords, length,
(Text, pack, unpack, splitOn, unlines, unwords, length,
justifyLeft, justifyRight, center)
justifyLeft, justifyRight, center)
import Data.List (transpose, zip, maximumBy)
import Data.Ord (comparing)
import Data.Ord (comparing)

rows :: [[Text]]
rows :: [[Text]]
rows =
rows =
Line 2,515: Line 2,516:
, "justified,$right$justified,$or$center$justified$within$its$column."
, "justified,$right$justified,$or$center$justified$within$its$column."
]
]

cols :: [[Text]]
cols :: [[Text]]
cols =
cols =
transpose $
transpose $
((++) <*>
((++) <*>
(flip Prelude.replicate (pack []) .
(flip P.replicate (pack []) .
(-) (maximum (Prelude.length <$> rows)) . Prelude.length)) <$>
(-) (maximum (P.length <$> rows)) . P.length)) <$>
rows
rows

main :: IO ()
main :: IO ()
main =
main =