I'm trying to build a mutable map from integers to a mutable set of integers in Scala.
For example, I would like to have the mappings of the form 1 -> (2,3) and be able to update them later using the key value. The code that I use is as follows:
import scala.collection.mutable._
val map = Map[Int, Set[Int]]()
map: scala.collection.mutable.Map[Int,scala.collection.mutable.Set[Int]] = Map()
map += (1 -> Set(2,3))
res15: map.type = Map(1 -> Set(2, 3))
So far good, but when I try to do something like
map.get(1) += 4
I get an assignment to val error. What is confusing to me is that map.get() should return a Set of type scala.collection.mutable.Set which can be updated. Can someone please shed some light what's going on here?