sreich
06/22/2022, 9:16 PMephemient
06/22/2022, 9:17 PMoperator fun component1()
sreich
06/22/2022, 9:25 PMAndreyVanDenHaag
06/23/2022, 5:17 AMcomponent1()
or not ? Do you suggest to add it to every class ?andylamax
06/23/2022, 7:07 AMAndreyVanDenHaag
06/23/2022, 8:24 AMJoffrey
06/23/2022, 12:31 PMcomponentN
functions on very simple classes for which the properties' positions are obvious. For instance, a key-value Pair
, a triple, a 2D point, etc.
In those cases, very often data class
makes sense.
i do see that there are some assumptions they can make if it is a data class (e.g. it cannot be open if it's data)Exactly. Extending a class with new properties would make the order in the destructuring declarations even less obvious to the user
yeah but you'd have to make a definition for it, yeah? that's a shame. seems like they should add that. not everything can be a data classDo you think
operator fun component1() = myProp1
is really too long? I believe it's not worth complicating the language for this, especially when we know positional destructuring has pitfalls already and should be used with caresreich
06/23/2022, 1:05 PMJoffrey
06/23/2022, 1:10 PMnot everything can be a data classBy the way, if what blocks you here is some limitation on
data class
like inheritance, you might also consider extracting the set of properties that you want to destructure as a separate data class
and use that in your original class instead of the set of properties. Not sure if that makes sense in your specific case, though