What is the best way to conditionally add to an immutable collection in Scala?
You can use the fact that Map() ++ None == Map() along with Map() ++ Some((k,v)) == Map((k,v)) and Option.map to get the following pattern: 

def generateObject(foo: Option[String]) = {
  Map("bar" -&gt; "baz") ++ foo.map("foo" -&gt; _)
}