Last active
August 29, 2015 14:19
-
-
Save quephird/41885ab10d38c1cbfb4b to your computer and use it in GitHub Desktop.
Using the supplied interactWith function, write another function that transposes the file contents of the input and writes it to another file.
This file contains hidden or 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
interactWith :: (String -> String) -> FilePath -> FilePath -> IO () | |
interactWith f inputFile outputFile = do | |
input <- readFile inputFile | |
writeFile outputFile (f input) | |
transpose = unlines . transpose' . lines where | |
transpose' ss | all ((==) "") ss = [] | |
transpose' ss = map head nonEmptySs : (transpose' $ map tail nonEmptySs) where | |
nonEmptySs = filter ((/=) "") ss | |
transposeFile inputFile outputFile = interactWith transpose inputFile outputFile where |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment