Skip to content

Instantly share code, notes, and snippets.

@seratch
Created May 14, 2012 15:25
Show Gist options
  • Save seratch/2694564 to your computer and use it in GitHub Desktop.
Save seratch/2694564 to your computer and use it in GitHub Desktop.
Yet another loan pattern
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