I am learning immutable types in Scala and am struggling to get this elementary task done. I simply need to append to an array of doubles that is within a map. I do not want to use ArrayBuffer.
My ultimate goal is to make an adjacency matrix. When I append a new item to the map (an (Int, double) tuple) I want to increase the size of each array within the map--essentially increasing the dimension of the matrix.
var map = Map[Int, Array[Double]]()
map += (0 -> new Array[Double](5))
// HOW TO DO THIS
map(0) = map(0) :+ 0.01
for ((i, a) <- map) {
print(i + ": ")
for (d <- a) print(d + ", ")
}
What I have written above does not compile. However map(0) :+ 0.01 alone will but it does not achieve my goal of appending to an immutable array within a map.