component0 isn't useful :P
they have 1-based index
s
Saurabh
05/18/2020, 9:56 AM
I don't really see a use-case of having to define
componentN
operators. Maybe I am wrong.
s
streetsofboston
05/18/2020, 12:17 PM
@Saurabh it'll allow the users of your type that has
componentN
operator(s) to destructure its instances.
val (name, age) = somePerson
s
Saurabh
05/18/2020, 12:21 PM
@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
streetsofboston
05/18/2020, 12:24 PM
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
Ruckus
05/18/2020, 1:07 PM
You can also use them as extension functions to add destructuring to existing classes