Skip to content

Instantly share code, notes, and snippets.

@sroccaserra
Last active November 25, 2020 07:50
Show Gist options
  • Save sroccaserra/6a535c65f142aab677f853d069565e25 to your computer and use it in GitHub Desktop.
Save sroccaserra/6a535c65f142aab677f853d069565e25 to your computer and use it in GitHub Desktop.
Read lines from file lazily in Haskell
$ echo -e '1 2 3\n4 5 6' | runhaskell Main.hs
[[1,2,3],[4,5,6]]
main = do
lines <- fmap lines getContents
print $ process lines
process :: [String] -> [[Int]]
process = map processLine
processLine :: String -> [Int]
processLine = map read . words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment