Ray Rahke
03/11/2024, 9:45 AMfun main() {
val grid: List<List<Boolean>> = List(size=10) { List(size=10) { false }}
}
However this does not seem supported for mutable lists
fun main() {
val grid: MutableList<MutableList<Boolean>> = MutableList(size=10) { MutableList(size=10) { false }}
}
Why?
And is there an analogous way to build this grid in 1 single readable expression?CLOVIS
03/11/2024, 9:55 AMJavier
03/11/2024, 9:55 AMRay Rahke
03/11/2024, 9:57 AMRay Rahke
03/11/2024, 9:57 AMRay Rahke
03/11/2024, 9:57 AMRay Rahke
03/11/2024, 9:57 AMCLOVIS
03/11/2024, 9:58 AMList<List<Cell>>
where Cell
is a mutable class, to avoid rows changing sizes.CLOVIS
03/11/2024, 9:59 AMList<List<Boolean>>
and copy the matrix each time, if you want time travel.Sam
03/11/2024, 9:59 AMHowever this does not seem supported for mutable listsWhat makes you say that? The code you posted in your question works fine for me...
CLOVIS
03/11/2024, 9:59 AMSam
03/11/2024, 10:02 AMList(10) { BooleanArray(10) }
Then you get mutable cells without being able to accidentally change the size 👍Ray Rahke
03/11/2024, 10:02 AMephemient
03/11/2024, 10:16 AM