🆘
Require knowledge from all the Kotlin Gurus.
I was looking into a JavaScript code and found the following syntax
const {a , …remaining} = user
…
is called spread operator in JavaScript
Where
user = {a : "12", b : 2 , c: "Some random String"}
so the value of
user.a
was copied in variable
a
and all the remaining keys of user object
user.b
and
user.c
were copied in
remaining
variable.
This concept is called
Destructuring
and in kotlin world, the nearest possible syntax that I know, is
val (a,b,c) = user
But, can we write this anyway better without declaring 3 variables ???
So, that my final code should be
val (a,remaining) = user