https://kotlinlang.org logo
Title
m

Mark

05/02/2022, 1:28 AM
What should be considered when deciding whether to declare destructuring functions (e.g.
component1()
) directly on a class vs. extension functions? AFAIR, when using destructuring extension functions, you need to add the imports manually.
m

Matteo Mirk

05/02/2022, 2:55 PM
I don’t fully understand, sorry: do you mean declaring
componentN()
functions manually, like the compiler does for data classes?
p

Paul Griffith

05/02/2022, 3:16 PM
IMO positional destructuring is only very rarely a good idea. If you did decide to use it, I would definitely say to just make them member functions so you don’t have to import the extensions
m

Mark

05/05/2022, 1:34 PM
@Paul Griffith There are some useful cases. I like using them from
Pair
MatchResult.destructured
for example. Likewise, there are occasions when I like to declare my own.