I just came across array destructuring in Typescri...
# language-proposals
f
I just came across array destructuring in Typescript is there something like that in kotlin?
Copy code
const numbers = [1,2,3,4,5];
const [numOne,numTwo,...remainingNumbers] = numbers;
k
Not only arrays, but in fact any class that defines
component1()
,
component2()
etc. can be destructured. The Kotlin equivalent to your example is:
Copy code
val numbers = arrayOf(1, 2, 3, 4, 5)
val (numOne, numTwo) = numbers
val remainingNumbers = numbers.slice(2..numbers.size)
r
Works for
List
also
f
Oooh Nice, Thanks. I am aware of the Pair and Triple example but didn’t think of it as destructuring.
Thanks