:sos: Require knowledge from all the Kotlin Gurus...
# announcements
r
ūüÜė Require knowledge from all the Kotlin Gurus. I was looking into a JavaScript code and found the following syntax
Copy code
const {a , …remaining} = user
…
 is called spread operator in JavaScript Where
Copy code
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
Copy code
val (a,b,c) = user
But, can we write this anyway better without declaring 3 variables ??? So, that my final code should be
Copy code
val (a,remaining) = user
t
Destructuring in JS and destruction in Kotlin work very differently. JS does this based on field names and has the possibility to put "the rest" into a separate object, which is no problem in JS because your types are dynamic and not strongly typed. In Kotlin, destruction works by calling the
componentN()
operator functions of the object you want to destruct (
component1()
for the first value,
component2()
for the second and so on). If there was a way to use something like the JS spread operator in Kotlin here, what would the type of
remaining
be? The only thing I could think of is a List, probably without a useful generic type.
ūüíĮ 4
r
Makes sense. This thought didn‚Äôt cross my mind that Kotlin is statically typed language and Javascript is loosely typed language. ūüí°
s
strongly typed is not equal to statically typed
t
@stephanmg you're right, I mean statically typed of course
K 2
s
@Tobias Berger hey, that’s fine, I guessed you wanted to refer to static typing.