loading...

re: What are your favorite programming language syntax features? VIEW POST

FULL DISCUSSION
 

Kotlin's function literals with receiver and infix functions are pretty cool.

Function literals with receivers:

class HTML {
    fun body() { ... }
}

fun html(init: HTML.() -> Unit): HTML {
    val html = HTML()
    html.init()
    return html
}

html {
    body()
}

Infix:

infix fun Int.shl(x: Int): Int { ... }

// calling the function using the infix notation
1 shl 2

// is the same as
1.shl(2)
Code of Conduct Report abuse