Created
January 2, 2012 21:28
-
-
Save channingwalton/1552195 to your computer and use it in GitHub Desktop.
A little scalaz IO action
This file contains 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
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/