```object A { fun Server.wire() { TODO() } } ...
# getting-started
j
Copy code
object A {
    fun Server.wire() { TODO() }
}

object B {
    fun Server.wire() { TODO() }
}
how do I call wire from both object A and B considering they're both extension functions?
Copy code
Server().apply {
    wire() // wire A
    wire() // wire B
}
is it possible to do something like
A::wire()
and
B::wire()
?
e
Copy code
with(A) { wire() }
with(B) { wire() }
j
mmm, that's even more verbose than what I was going for, but I guess that works. thanks!
context receivers to the rescue:
Copy code
object A {
    context(Server)    
    fun wire() { TODO() }
}

object B {
    context(Server)
    fun wire() { TODO() }
}
now I can just do
Copy code
with (Server())) {
    A.wire()
    B.wire()
}
j
You can also import them with an alias:
Copy code
import some.package.A.wire as wireA
import some.package.B.wire as wireB

Server().apply {
    wireA()
    wireB()
}
j
that's a nice elegant solution !
👍 1
e
if they're always
object
, yes that works. need to use the other methods for context if they're not, though