Skip to content

Instantly share code, notes, and snippets.

@bmjames
Created January 3, 2012 23:39
Show Gist options
  • Save bmjames/1557596 to your computer and use it in GitHub Desktop.
Save bmjames/1557596 to your computer and use it in GitHub Desktop.
totally non-complex way to list files in a directory
val openFile: String => IO[File]
= path => io { new File(path) }
val fileName: File => String
= _.toString
val putStrLn: String => IO[Unit]
= s => io { println(s) }
val listFiles: File => IO[Seq[File]]
= f => io { f.listFiles }
val result = openFile(".") >>= listFiles >>= (_ traverse_ (fileName map putStrLn))
result.unsafePerformIO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment