Is there anything proposed that would allow me to ...
# language-proposals
c
Is there anything proposed that would allow me to destructure a delegate? Like this
Copy code
val (a, b) by myDelegate {
  "a" to "b"
}
Currently this errors with
Initializer required for destructuring declaration
. Thanks!
Or is this an impossible thing.
e
Certainly feels impossible. The destructuring means that you need to call componentN method and for that you need an instance but delegation is, by default, lazy so no instance. How would it work?
s
looks like it ought to be possible, basically as syntactic sugar for
Copy code
val lazilyInstantiatedPair: Pair<String, String> by myDelegate { "a" to "b" }
val a by lazilyInstatiatedPair::first
val b by lazilyInstantiatedPair::second
1
1
e
That assumes kotlin reflection for every project 😐
d
I don't think it would require reflection at all, perhaps restated as:
Copy code
val lazilyInstantiatedPair: Pair<String, String> by myDelegate { "a" to "b" }
val a get() = lazilyInstatiatedPair.first
val b get() = lazilyInstantiatedPair.second
👍 2