Scala中带接收器的函数类型

Sol*_*Sol 6 lambda scala kotlin

我正在调查这个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
}
Run Code Online (Sandbox Code Playgroud)

我想知道如何在scala中编写这段代码?如何用接收器声明scala函数类型?

Ale*_*nov 6

Scala中没有与此相同的内容.你只需使用一个HTML作为参数的函数(可能作为一个隐式参数,但这不会反映在类型中,在这种情况下不太可能).