Let's say I have an array like this:
val grid = Array(10) { IntArray(10) { 1 } }
And now I want to set some of them to 2 instead. I could do this:
for (i in 0..5) {
for (j in 0..5) {
grid[i][j] = 2
}
}
But what I'd like to do is this:
grid[0..5][0..5] = 2
Is there some faster way to do it like this?
operator fun IntArray.set(indices: IntRange, value: Int)). However, I can't think of how to make this work for a two-dimensional array. Or, at least, I can't think of an intuitive way to do it (you can define the operator function for the two-dimensional array type, but then it looks like you're accessing a one-dimensional array at first glance).