title: Better way of converting a Map[K, Option[V]] to a Map[K,V]
body: <p>I have some code that is producing a <code>Map</code> where the values are <code>Option</code> types, and I really of course want a map containing only the real values.</p>
  
  <p>So I need to convert this, and what I've come up with in code is</p>
  
  <pre><code>  def toMap[K,V](input: Map[K, Option[V]]): Map[K, V] = {
      var result: Map[K, V] = Map()
      input.foreach({
        s: Tuple2[K, Option[V]] =&gt; {
          s match {
            case (key, Some(value)) =&gt; {
              result += ((key, value))
            }
            case _ =&gt; {
              // Don't add the None values
            }
          }
        }
      })
      result
    }
  </code></pre>
  
  <p>which works, but seems inelegant.  I suspect there's something for this built into the collections library that I'm missing.</p>
  
  <p>Is there something built in, or a more idiomatic way to accomplish this?</p>