What is the purpose of trailing lambda syntax (Kotlin)?

This syntax gives Kotlin great DSL capabilities, it makes functions look like language constructions. For example:

with(car) {
   startUp()
   goToDestination()
}

Here with looks like it is language construction, whereas it is a simple function, receiving lambda as the last parameter.

And this leads to such elegant things like Kotlin HTML DSL

Leave a Comment

tech