^^ One thing where JavaScript is better than :kotl...
# language-proposals
j
^^ One thing where JavaScript is better than K is that it has object destructuring by name. Kotlin has only destructuring by component order … which is ok-ish in some cases but especially not good if all your properties are String. … or at least this is what I thought and then I realized we can do this in Kotlin too! The pattern is to use
val (my, destructuring, declaration) = with(object) { Tuple(my, destructuring, declaration)
It’s stil position based obviously since this is what Kotlin support. But in this case it doesn’t matter because the order of arguments is declared in line, not in another class. It’s also much more general, it works with much more than “the properties of data classes”. We can put whatever we like in the lambda and transform it to a tuple. Update: https://youtrack.jetbrains.com/issue/KT-19627
👍 3
r
Arrow provides support to get tupleN projected over any product types like data classes https://arrow-kt.io/docs/generic/product/. We are moving this to compiler plugins with Arrow meta and hocking it up to the typeclass resolution phase to get automatic type class instances for generic product types provided there is an instance for their tupled version.
🔥 4
m
That's super cool, like most everything coming up in Arrow! But in this particular case I think just using
tupled
would have same positional problems as regular destructuring. Really hoping that named destructuring will make it's way to a future version of Kotlin 🤞
🤞 1