Are Context Parameters going to solve the "I want ...
# language-evolution
d
Are Context Parameters going to solve the "I want to create an extension that requires multiple receivers?" Example in 🧵
Copy code
open class FooAccess {
    fun createFoo() = Foo()
}

class Foo {
    companion object
}

class Bar : FooAccess() {
    val foo by Foo
}

// In the context of FooAccess
operator fun Foo.Companion.getValue(thisRef: Any?, property: KProperty<*>): Foo = createFoo()
In this example, one could put the getValue method within FooAccess, but there are situations where that doesn't make sense to do.
In my case, its more about correct package dependency graph.
Foo
is a low-level property,
FooAccess
is a bridge between low and high level,
Bar
is a high-level class, and
getValue
has logic that needs to be aware of high-level classes, so doesn't belong in the bridge package.
y
Yes that should work. In addition, you could already do some of this by specifying
thisRef
to be a
FooAccess
, but that would limit its use to only be inside that class
d
Ah, that makes sense. That's probably would want anyway for this case, though getValue is just one example, not all of my use-cases are property delegation.