What is the best way to conditionally add to an immutable collection in Scala? I find myself frequently trying to build up Seq's based on some conditionals, but the code I end up with feels verbose and clunky. An example:

def generateSeq(foo: Option[String]) = {
  Map("bar" -&gt; "baz") ++ ( if (foo.isDefined) {
      Map("foo" -&gt; foo.get)
    } else {
      Nil
    } )
}


If it were Python, I would simply do:

def generateObject(foo):
    obj = {}
    obj["bar"] = "baz"
    if foo: obj["foo"] = foo
    return obj


Is there a cleaner way to write the Scala code (especially as I add more logic and conditionals involved in building the map)?
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; _)
}