Created
June 17, 2015 20:46
-
-
Save colinbes/a7038e037ecc71315b53 to your computer and use it in GitHub Desktop.
Scala loan pattern
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
//Loaner pattern to ensure closing of bufferedsource | |
... | |
def using[T](r: BufferedSource)(handler: BufferedSource => T): T = { | |
try { | |
handler(r) | |
} finally { | |
r.close() | |
} | |
} | |
lazy val versioning:... = { | |
Option(getClass.getResourceAsStream("/archives.json")) match { | |
case Some(is) => | |
val resource = Source.fromInputStream(is) | |
using(resource) { input => | |
... | |
} | |
case _ => ... | |
} | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment