Hi Is it possible to compose extension functions ?...
# codingconventions
t
Hi Is it possible to compose extension functions ? Let's say I have an extension function :
Copy code
val myFunc: A.() -> Unit = { // this: A
    customField = "value" 
}
val otherFunc: A.() -> Unit = { // this: A
    otherField = "other"
}
I want to have a function that is the combination of both above I don't know how to write this.
s
You can have the function return
this
and call one after the other, or
.apply
both:
Copy code
A().apply {
    myFunc()
    otherFunc()   
}
g
Do you mean this?
Copy code
fun A.combined() {
   myFunc()
   otherFunc()  
}
A().combined()