title: How to return all positives and the first negative number in a list using functional programming?
body: <p>Imagine I have an unsorted list of positive &amp; negative ints. I want to return a list containing all the positive ints, and the first negative number, but then ignore all subsequent negative numbers from the list, while preserving the ordering.</p>
  
  <p>Imperatively I could do:</p>
  
  <pre><code>l = [1, 2, -4, 5, -6, -1, 3]
  out = []
  first = true
  for n in l:
      if n &gt;= 0:
          out.push(n)
      else if first:
          out.push(n)
          first = false
  
  // out = [1, 2, -4, 5, 3]
  </code></pre>
  
  <p>How could I do this with FP in Scala? I was thinking (probably won't compile...):</p>
  
  <pre><code>val l = List(1, 2, -4, 5, -6, -1, 3)
  val posl = l.map(_ &gt;= 0)
  val negl = l.zipWithIndex.map((n, i) =&gt; if (n &lt; 0) (i, n) else (None, None)).head
  // now split posl at negl._1, and create a new list of leftSlice :: negl._2 :: rightSlice?
  </code></pre>
  
  <p>Is this the right approach, or is there a more elegant, succinct way?</p>