带有Scala接收器的函数类型

我正在调查这个Kotlin的例子:

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 } 

我很想知道如何编写这个代码在斯卡拉? 如何在接收器中声明scala函数类型?

在Scala中没有这个相同的东西。 你可以简单地使用一个把HTML作为参数的函数(可能是一个隐含的参数,但是这并不反映在这种类型中,在这种情况下不太可能)。