Skip to content

Instantly share code, notes, and snippets.

@s1monw1
Created September 8, 2022 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s1monw1/bc338d09e28614e800b5ca4ad04e31c8 to your computer and use it in GitHub Desktop.
Save s1monw1/bc338d09e28614e800b5ca4ad04e31c8 to your computer and use it in GitHub Desktop.
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