Created
March 30, 2012 19:16
-
-
Save alexy/2254199 to your computer and use it in GitHub Desktop.
how do we move val w declaration inside try?
This file contains hidden or 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
def printFileWriter(name: String): PrintWriter = { | |
new PrintWriter(new FileWriter(name)) | |
} | |
def writing[B](fileName: String)(f: PrintWriter => B): B = { | |
lazy val w = printFileWriter(fileName) // so throws only in try, if ever | |
try { f(w) } | |
finally { w.close() } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment