I am studying this Kotlin example:
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 } html { // lambda with receiver begins here body() // calling a method on the receiver object }
I am wondering how to write this code in scala? How to declare function type with receiver in scala?
Scala has no equivalent to this. You simply use a function that takes HTML as an argument (perhaps as an implicit argument, but this is not reflected in the type and is unlikely in this case).
HTML