Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Transpose a chunk of text in Haskell
-- transpose a chunk of text separated by '\n'
transposeText :: String -> String
transposeText text = unlines (transpose' (lines text))
transpose' :: [String] -> [String]
transpose' sentences
| not (all null sentences) = currentLine : (transpose' (map tail nonEmptySts))
| otherwise = []
where currentLine = [x | x:_ <- nonEmptySts]
nonEmptySts = filter (not.null) sentences
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment