Skip to content

Instantly share code, notes, and snippets.

@gclaramunt
Created November 6, 2012 18:50
Show Gist options
  • Save gclaramunt/4026680 to your computer and use it in GitHub Desktop.
Save gclaramunt/4026680 to your computer and use it in GitHub Desktop.
import java.sql.Connection
trait Closeable[T]{
def close(t:T)
}
object Closeable{
implicit val connectionCloseable= new Closeable[Connection]{
override def close(c:Connection){ c.close() }
}
}
object Arm{
def withResource[T](resource: T)( f:T=>Unit ){
f(resource)
implicitly(Closeable[T]).close(resource)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment