Created
May 2, 2014 12:56
-
-
Save orangy/11474248 to your computer and use it in GitHub Desktop.
DSL for C#-style using statement
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
trait Disposable { | |
fun dispose() | |
} | |
fun using(value : Disposable, body : ()->Unit) { | |
try { | |
body() | |
} finally { | |
value.dispose() | |
} | |
} | |
fun fn() { | |
val resource = object : Disposable { | |
override fun dispose() { | |
println("disposed!") | |
} | |
} | |
using(resource) { | |
println("using resource") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment