Created
November 6, 2012 18:50
-
-
Save gclaramunt/4026680 to your computer and use it in GitHub Desktop.
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 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