Created
March 27, 2020 13:56
-
-
Save priyanshus/513cca3f083c69eb5134348b96b3e61f to your computer and use it in GitHub Desktop.
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
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