Skip to content

Instantly share code, notes, and snippets.

@s1monw1
Created Sep 8, 2022
Embed
What would you like to do?
class HTML {
fun body() { ... }
}
fun html(init: HTML.() -> Unit): HTML {
val html = HTML() // create the receiver object
html.init() // pass the receiver object to the lambda
return html
}
// Call `html` and pass lambda to it. Inside the lambda we can call `body` directly thanks to the usage of a receiver.
html { // lambda with receiver begins here
body() // calling a method on the receiver object
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment