Skip to content

Instantly share code, notes, and snippets.

View KingKongCoderr's full-sized avatar

nandeesh KingKongCoderr

View GitHub Profile
@KingKongCoderr
KingKongCoderr / Kotlin DSL example 2
Created November 29, 2019 19:49
DSL by call block with context
class Robot {
val it = this
val left = "left"
infix fun turns(direction: String) {
print("${this.javaClass.simpleName} turned $direction")
}
}
fun operate(block: Robot.(Robot) -> Unit) {
Robot().block(Robot())
class Robot: MovingObject {
val it = this
val left = "left"
override fun turns(direction: String) {
print("${this.javaClass.simpleName} turned $direction")
}
}
class Car: MovingObject{
override fun turns(direction: String) {