title: Scala - head of empty list - removing all None's from a list of Options
body: <p>Been trying to solve this for a while now. I need a recursive function that removes all None's from a list of Option[Int]'s, without using if-statements or using other functions.</p>
  <pre><code>def RemoveNone2(input: List[Option[Int]]) : List[Int] = {
    input.head match {
      case None =&gt; RemoveNone2(input.tail)
      case _ =&gt; (input.head.get::RemoveNone2(input.tail))
    }
  }
  
  val optional: List[Option[Int]] = List(Some(13), None, Some(32), None, Some(51), None, Some(17), None)
  RemoveNone2(optional)
  </code></pre>
  <p>But when trying to execute the code, I get the following error:</p>
  <pre><code>java.util.NoSuchElementException: head of empty list
  </code></pre>
  <p>I suck at Scala, could anyone offer some insight?</p>