What is idiomatic way to iterate through a mutable map and remove key with zero values?
I came up with this
// Prepare
import scala.collection.mutable.HashMap
val register = HashMap.empty[String, Int]
register += "A" ->1
register += "B" ->0
//Remove if value is zero
register.foreach(i => if (i._2==0) register -= i._1)
but it still looks awkward and not functional enough to me. I feel that in really functional approach we should mention register
only once. Compare with Mathematica
code
register = {{"A", 1}, {"B", 0}};
DeleteCases[register, {_, 0}]