4 ms·
There's competing incentives for API ergonimics and making mutations / ownership explicit. Kotlin's scope functions really get you the best of both worlds with
by kevinmgranger 5y ago
There's competing incentives for API ergonimics and making mutations / ownership explicit. Kotlin's scope functions really get you the best of both worlds with this.
Lambdas can have a "receiver", which acts as the (implicit or explicit) `this` for the lambda.
`apply` even returns the object itself, so the first example could be:
frame.add(FormPanel().apply {
setSize(300, 150)
add(usernameLabel)
add(usernameField)
add(passwordLabel)
add(passwordField)
})