One of the confusion I guess raised from the fact that I try to use destructuring declaration in class definition. This is why I mentioned properties in destructuring and need to use lazy delegation. Apparently desctructuring declaration only allowed for local variables/values. I added a bit in the original text to emphasize that fact.
Actually I have another example (just to show it might be not as narrow as @darksnake think).
The Result in Fuel I am using is actually a class with component1() and component2() functions, so it can be used with destructuring declaration. However because the value is not available at construction time I need to use laze {...} delegation here too.
How should I destruct the value of type Triple<Request, Response, Result<T, FuelError>> into 4 values of types Request, Response, T and FuelError?
May be support “deep” destruction like:
val (request, response, (body, exception)) by lazy {
toRequest.responseObject(jacksonDeserializerOf<Map<String, Any?>>())
}
It may be 2 separate features. Seams conversion compiler should do is not very difficult.
It may be not only for lazy delegation, but also for getters and setters (as I mentioned in the title). If we need to do the same work while changing any of few properties. Instead of copying the same code or write a separate function to be called from each property getter/setter we could use destructuring declaration with single getter (and if needed setter) to be called in all cases.
For example:
class Fraction {
private var _value
val value: Long
get() = _value
var (nominator, denominator)
get() = Pair(nominator, denominator)
set() {
_value = nominator / denominator
}
}
The question is what type to use to return from getter. The setter would take any type which can be used in regular destructuring declaration.