I have an Int-> Queue card, and I add one entry to the queue at a time. At the end of the process, I need to iterate over the keys and values (because I want to convert the queues to arrays), but scala says there are no keys / values on the map. Some simplified codes are provided below for illustration. What's going on here? The result m (4) below is also puzzling.
import scala.collection.mutable.Queue
val m = Map[Int, Queue[Int]]().withDefaultValue(Queue[Int]())
m(1) += 10
res25: scala.collection.mutable.Queue[Int] = Queue(10)
m(1) += 10
res26: scala.collection.mutable.Queue[Int] = Queue(10, 10)
m(1)
res35: scala.collection.mutable.Queue[Int] = Queue(10, 10)
m(4)
res37: scala.collection.mutable.Queue[Int] = Queue(10, 10)
m.keys
res28: Iterable[Int] = Set()
m
res36: scala.collection.immutable.Map[Int,scala.collection.mutable.Queue[Int]] = Map()
Using scala 2.10.3.
source
share