2016-01-29 11 views
6

Sto indagando questo esempio Kotlin:Tipo di funzione con ricevitore a Scala

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 
} 

sto chiedo come scrivere questo codice in scala? Come dichiarare in scala tipo di funzione con il ricevitore?

risposta

6

Non c'è un equivalente in Scala. Dovresti semplicemente usare una funzione che prende come argomento HTML (probabilmente come argomento implicito, ma questo non si riflette nel tipo e improbabile in questo caso).