I have a lot of fluent builder functions that are implemented in a companion object (to avoid polluting namespaces) I would like to provide a nice builder api, so I need to be able to call these functions, by chaining tem, without specifying the companion object each time I use one At the moment, the best I managed to do is to code it like this :
Is there a way to code the following function
{code}
fun A.myFunction(b: B.Companion.() -> A.() -> Unit): Unit = with (this) { B.Companion.b() }()
{code}
But with this syntax, I need to use 2 pairs of brackets like this :
{code}
a.myFunction {{
doSomething()
}}
{code}
I would like to achieve the same effect than this
{code}
with (a) {
with(B.Companion) {
doSomething
}
}
{code}
But with a single pair of brackets
{code}
a.myFunction {
doSomething()
}
{code}
Is there a way to achieve this ?