Operator `component0` compiled successfully. How i...
# announcements
t
Operator
component0
compiled successfully. How it can be used as operator on practice? On playground
e
component0 isn't useful :P they have 1-based index
s
I don't really see a use-case of having to define
componentN
operators. Maybe I am wrong.
s
@Saurabh it'll allow the users of your type that has
componentN
operator(s) to destructure its instances.
val (name, age) = somePerson
s
@streetsofboston Thank you for your explanation. I know that it's used for destructuring. But I can have the compiler generate it for me, just by declaring a data class. I don't see the use case of manually defining it for my class.
s
Data classes can't be inherited from, for example. If you still like to destructure, adding your own component functions makes it possible. Collections, for example. Other type of containers may need it. Interfaces that may act like a value object/entity may need it.
👍 1
r
You can also use them as extension functions to add destructuring to existing classes
s
Got it. Thanks guys for the explanations 😃