title: Scala: Remove none elements from map and flatten
body: <p>I have a map:</p>
  
  <pre><code>Map("key1" -&gt; Some("value1"), "key2" -&gt; None, "key3" -&gt; Some("value3"))
  </code></pre>
  
  <p>I want to remove all <code>None</code> elements and flatten the map. What is the easiest way to accomplish that? I only found this way:</p>
  
  <pre><code>Map("key1" -&gt; Some("value1"), "key2" -&gt; None, "key3" -&gt; Some("value3")).filter(_._2.nonEmpty).map(item =&gt; (item._1 -&gt; item._2.getOrElse(Nil)))
  </code></pre>
  
  <p>The result is:</p>
  
  <pre><code>Map(key1 -&gt; value1, key3 -&gt; value3)
  </code></pre>
  
  <p>Do you know a better way?</p>