What is the proper way to remove elements from a scala mutable map using a predicate

Posted by Oleg on Stack Overflow See other posts from Stack Overflow or by Oleg
Published on 2010-03-23T14:12:06Z Indexed on 2010/03/23 16:13 UTC
Read the original article Hit count: 556

Filed under:
|
|
|
|

How to do that without creating any new collections? Is there something better than this?

val m = scala.collection.mutable.Map[String, Long]("1" -> 1, "2" -> 2, "3" -> 3, "4" -> 4)
m.foreach(t => if (t._2 % 2 == 0) m.remove(t._1))
println(m)

© Stack Overflow or respective owner

Related posts about scala

Related posts about mutable