Skip to content

Instantly share code, notes, and snippets.

@j5ik2o
Created December 16, 2011 12:59
Show Gist options
  • Save j5ik2o/1485960 to your computer and use it in GitHub Desktop.
Save j5ik2o/1485960 to your computer and use it in GitHub Desktop.
ベタなLoanパターン
object Loan {
def using[A <: { def close() }, B](resource: A)(func: A => B): B =
try {
func(resource)
} finally {
if (resource != null) resource.close()
}
}
using(new FileInputStream("hoge.txt")){ fis =>
fis.read(...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment