title: Multiple yields in sequence comprehension?
body: <p>I'm trying to learn Scala and tried to write a sequence comprehension that extracts unigrams, bigrams and trigrams from a sequence. E.g., [1,2,3,4] should be transformed to (not Scala syntax)</p>
  
  <pre><code>[1; _,1; _,_,1; 2; 1,2; _,1,2; 3; 2,3; 1,2,3; 4; 3,4; 2,3,4]
  </code></pre>
  
  <p>In Scala 2.8, I tried the following:</p>
  
  <pre><code>def trigrams(tokens : Seq[T]) = {
    var t1 : Option[T] = None
    var t2 : Option[T] = None
    for (t3 &lt;- tokens) {
      yield t3
      yield (t2,t3)
      yield (t1,t2,Some(t3))
      t1 = t2
      t2 = t3
    }
  }
  </code></pre>
  
  <p>But this doesn't compile as, <a href="http://www.scala-lang.org/node/111" rel="nofollow noreferrer">apparently</a>, only one <code>yield</code> is allowed in a <code>for</code>-comprehension (no block statements either). Is there any other elegant way to get the same behavior, with only one pass over the data?</p>