title: Scala - Flatmap a Seq of Options and Traversable
body: <p>Consider a flatMap written over some case matching. For example:</p>
  
  <pre><code>list.flatMap( v =&gt;
      v match {
          case Cond1 =&gt; if(something) Some(Int) else None
          //..Other conditions yielding Option[Int]
          case CondN =&gt; if(somethingelse) Seq(Int) else Seq()
      })
  </code></pre>
  
  <p>However this wont compile. If the seq is all of Option[Int] or all of Seq[Int] the flatMap works. But not if the Seq is a mix of Options and Seqs. Why is such a restriction in place? Does this solve a particular ambiguity that I cannot think of as of now.</p>
  
  <p><strong>EDIT1</strong>
  Adding code snippet from REPL</p>
  
  <pre><code>scala&gt; val a = Seq(Option(1), Seq(2,3))
  a: Seq[Equals] = List(Some(1), List(2, 3))
  
  scala&gt; val b = Seq(Seq(1), Seq(2,3))
  b: Seq[Seq[Int]] = List(List(1), List(2, 3))
  
  scala&gt; a.flatMap(x=&gt;x)
  &lt;console&gt;:9: error: type mismatch;
   found   : Equals
   required: scala.collection.GenTraversableOnce[?]
                a.flatMap(x=&gt;x)
                             ^
  
  scala&gt; b.flatMap(x=&gt;x)
  res24: Seq[Int] = List(1, 2, 3)
  </code></pre>
  
  <p><strong>EDIT2</strong>
  After Filippo's answer I tried the following piece of code in the REPL and it worked.</p>
  
  <pre><code>scala&gt; val options = Seq("opt1", "opt2")
  options: Seq[String] = List(opt1, opt2)
  
  scala&gt; options.flatMap( x =&gt; 
       |      x match {
       |      case "opt1" =&gt; Some(1)
       |      case "opt2" =&gt; Seq(2,3)
       |      case _ =&gt; None
       |      })
  res27: Seq[Int] = List(1, 2, 3)
  </code></pre>
  
  <p>How is the resolution different in each of the scenarios. 
  More importantly when I map instead of flatMap the result is the same as the <code>Seq</code> a that I had created.</p>
  
  <pre><code>scala&gt; options.map( x =&gt; 
   |      x match {
   |      case "opt1" =&gt; Some(1)
   |      case "opt2" =&gt; Seq(2,3)
   |      case _ =&gt; None
   |      })
  res28: Seq[Equals] = List(Some(1), List(2, 3))  
  </code></pre>