Skip to content

Instantly share code, notes, and snippets.

@izhangzhihao
Created January 28, 2018 08:29
Show Gist options
  • Save izhangzhihao/0744426121a5227bbcf050619cb24119 to your computer and use it in GitHub Desktop.
Save izhangzhihao/0744426121a5227bbcf050619cb24119 to your computer and use it in GitHub Desktop.
Using.scala
def using[C, T](resource: C)(handle: C => T)(implicit env: C => ({def close(): Unit})): T = {
try {
handle(resource)
} finally {
resource.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment