Created
September 8, 2022 09:32
-
-
Save s1monw1/bc338d09e28614e800b5ca4ad04e31c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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