Created
April 1, 2015 16:09
-
-
Save frosforever/ec7b8b4ee6b59602fb22 to your computer and use it in GitHub Desktop.
Open, use, and clean up resource safely
This file contains 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
def cleanly[T, V](create: => T)(cleanup: T => Unit)(f: T => V): Try[V] = | |
Try { | |
val t = create | |
try { | |
f(t) | |
} finally { | |
cleanup(t) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment