is their a possible way to have an object deconstr...
# announcements
w
is their a possible way to have an object deconstruct into a variable amount?
c
Yes, you can write
operator fun componentN
functions to customize exactly what gets destructured. Lists do this to unpack values, such as
Copy code
val (one, two) = listOf("value1", "value2")
println(one) // "value1"
println(two) // "value2"
w
oh i knew that component1 and component2 existed but didn’t know componentN existed thanks!
c
Oh, sorry, i was just referring to the componet1, component2, etc.
That’s typically how they are referred to, collectively, in the docs
w
so i will need to write out component(1-N) if the object has a variable length?
c
Yes, that’s correct. I don’t think there’s a limit to how many you can write, but I believe the List component(1-N) functions go 1-10. But I don’t think there’s a generic way to indicate “any number of components”
w
ah ok thnx time to write out all the functions
a
this is why you can only destructure 5 elements from a List, afaict
(because only component1..component5 are declared on List)