Last active
January 23, 2016 18:37
-
-
Save asheshambasta/8a45b879b045d5ec2bbf to your computer and use it in GitHub Desktop.
Transpose a chunk of text in Haskell
This file contains 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
-- 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