Skip to content

Instantly share code, notes, and snippets.

@channingwalton
Created January 2, 2012 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save channingwalton/1552195 to your computer and use it in GitHub Desktop.
Save channingwalton/1552195 to your computer and use it in GitHub Desktop.
A little scalaz IO action
import scalaz._
import Scalaz._
import scalaz.effects._
import java.io._
/**
* Background reading:
* http://www.stackmob.com/2011/12/scalaz-post-part-2/
* http://blog.sigfpe.com/2007/11/io-monad-for-people-who-simply-dont.html
* http://apocalisp.wordpress.com/2011/12/19/towards-an-effect-system-in-scala-part-2-io-monad/
*/
object TheIO extends App {
val dirInIO = io { new File(System.getProperty("user.dir")) }
def filesInIO = for (dir <- dirInIO) yield dir.listFiles()
def namesInIO = for (theFiles ← filesInIO) yield theFiles.map(_.getName())
def printNamesInIO = for (all ← namesInIO) yield all.map(println(_))
val result = printNamesInIO
println("Nothings happened yet, lets go!")
result.unsafePerformIO
}
@channingwalton
Copy link
Author

I should say that I decided to tinker with scalaz IO after reading this article: http://www.stackmob.com/2011/12/scalaz-post-part-2/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment