Skip to content

Instantly share code, notes, and snippets.

@priyanshus
Created March 27, 2020 13:56
Show Gist options
  • Save priyanshus/513cca3f083c69eb5134348b96b3e61f to your computer and use it in GitHub Desktop.
Save priyanshus/513cca3f083c69eb5134348b96b3e61f to your computer and use it in GitHub Desktop.
class Calculator {
private var a = 0
private var b = 0
fun printResult() {
println(a + b)
}
fun firstNumber(a: Int) {
this.a = a
}
infix fun secondNumber(b:Int) {
this.b = b
}
}
fun calculator(block: Calculator.() -> Unit):Unit {
var c = Calculator()
c.block()
}
fun main() {
calculator {
firstNumber(2)
secondNumber(3)
printResult()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment