https://kotlinlang.org logo
Title
a

Aregev2

08/06/2018, 4:51 PM
Hi, I got this piece of code:
val nested = listOf(listOf(12), listOf(12))
    val (one, two) = nested
    println("$one, $two")
That throws IOFB exception, I do not understand why
r

Ruckus

08/06/2018, 4:56 PM
It works without a problem for me
s

Shawn

08/06/2018, 4:57 PM
same
is IOFB supposed to be
IndexOutOfBounds
exception? I’ve never seen anyone abbreviate it like that
a

Aregev2

08/06/2018, 5:01 PM
Oh wrong code sorry
val nested = listOf(listOf(12))
replace it
s

Shawn

08/06/2018, 5:02 PM
?
I feel like you just answered your own question
a

Aregev2

08/06/2018, 5:04 PM
@Shawn Well I kinda adopted calling exceptions in their abbreviation
r

Ruckus

08/06/2018, 5:04 PM
If
nested
has only one element, what do you expect to happen when you destructure it into two?
👆 2
a

Aregev2

08/06/2018, 5:04 PM
🤔 Welp
k

karelpeeters

08/06/2018, 5:12 PM
Coincidentally someone asked something very relevant in #general
k

kevin.cianfarini

08/06/2018, 6:52 PM
Related to that, can you only destructure 5 elements from a list or is it implemented differently than
componentN()
?
k

karelpeeters

08/06/2018, 6:55 PM
You can implement as many of them as you want but the stdlib happens to stop at 5.
I'll admit I've implemented the 6th one a couple of times, even though destructing really starts to look messy.