Skip to content

Instantly share code, notes, and snippets.

@suhininalex
Created December 26, 2017 20:55
Show Gist options
  • Save suhininalex/5407221a0c2403ac9ae240237eb41210 to your computer and use it in GitHub Desktop.
Save suhininalex/5407221a0c2403ac9ae240237eb41210 to your computer and use it in GitHub Desktop.
fun main(args: Array<String>) {
Context().use {
println(5.trueVal())
}
}
fun Context.use(body: MyContext.() -> Unit){
MyContext(this).body()
}
class MyContext(val context: Context) {
fun Int.trueVal() = this + context.thruth
}
class Context(val thruth: Int = 42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment