Is there a function in Scala to compose two maps or is flatMap a sensible approach?
scala> val caps: Map[String, Int] = Map(("A", 1), ("B", 2)) caps: Map[String,Int] = Map(A -> 1, B -> 2) scala> val lower: Map[Int, String] = Map((1, "a"), (2, "b")) lower: Map[Int,String] = Map(1 -> a, 2 -> b) scala> caps.flatMap { | case (cap, idx) => Map((cap, lower(idx))) | } res1: scala.collection.immutable.Map[String,String] = Map(A -> a, B -> b)
Some syntactic sugar would be great!