Skip to content

Instantly share code, notes, and snippets.

@quephird
Last active August 29, 2015 14:19
Show Gist options
  • Save quephird/41885ab10d38c1cbfb4b to your computer and use it in GitHub Desktop.
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.
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