Created
May 14, 2012 15:25
-
-
Save seratch/2694564 to your computer and use it in GitHub Desktop.
Yet another loan pattern
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
| import util.control.Exception._ | |
| object LoanPattern { | |
| def using[R <: { def close() }, A](resource: R)(f: R => A): A = ultimately { | |
| ignoring(classOf[Throwable]) apply resource.close() | |
| } apply f(resource) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment