Skip to content

Instantly share code, notes, and snippets.

@asheshambasta
Last active January 23, 2016 18:37
Show Gist options
  • Save asheshambasta/8a45b879b045d5ec2bbf to your computer and use it in GitHub Desktop.
Save asheshambasta/8a45b879b045d5ec2bbf to your computer and use it in GitHub Desktop.
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