I am looking for an idiomatic solution to this problem.
I am building a val Scala (immutable) Map and would like to optionally add one or more items:
val
You can add directly to the map:
scala> val map = Map(1 -> 2, 3 -> 4) scala> val some = Some(5 -> 6) scala> val none = None scala> val combinedMap = map ++ some ++ none combinedMap: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2, 3 -> 4, 5 -> 6)