That depends on the type of Scala.collection Map you are using. Scala comes with both mutable
and immutable
Maps. Checks these links:
http://www.scala-lang.org/api/2.10.2/index.html#scala.collection.immutable.Map
and
http://www.scala-lang.org/api/2.10.2/index.html#scala.collection.mutable.Map
In both types of maps, -
is usually the operation to remove a key. The details depend on the type of map. A mutable
map can be modified in place by using -=
. Something like
if (m.contains("privacy") && m.getOrElse("privacy", 1) == 0) {
m -= "play"
}
On the other hand, an immutable map can not be modified in place and has to return a new map after removing an element.
if (m.contains("privacy") && m.getOrElse("privacy", 1) == 0) {
val newM = m - "play"
}
Notice that you are creating a new immutable map.