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!
Chris Fillmore
07/20/2023, 2:53 PM
Or is this an impossible thing.
e
efemoney
07/20/2023, 3:19 PM
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
stantronic
07/21/2023, 4:43 PM
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
efemoney
07/26/2023, 11:45 PM
That assumes kotlin reflection for every project 😐
d
Derek Peirce
07/29/2023, 7:10 PM
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