title: Type mismatch when using iterators
body: <p>I'm getting this error when i run the below code -
  type mismatch, found : scala.collection.immutable.IndexedSeq[Int] required: Range </p>
  
  <p>Where I'm going wrong ?</p>
  
  <p>Functions -   </p>
  
  <pre><code>def calcRange(i: Int, r: List[Range]):List[Range] = r match {
     case List() =&gt; List(new Range(i,i+1,1))
  
     case r1::rs =&gt;
          if (r1.start-1==i) {new Range(i,r1.end,1):: rs; }
  
          else if(r1.end==i){new Range(r1.start,r1.end+1,1)::rs}
  
          else {r1::calcRange(i,rs)}
  }
  
  def recurseForRanges(l: Iterator[Int]):List[Range] = {
     var ans=List[Range]()
     while(l.hasNext){
         val cur=l.next;
         ans=calcRange(cur,ans)
      }
     ans
  }
  
  def rangify(l: Iterator[Int]):Iterator[Range] = recurseForRanges(l).toIterator
  </code></pre>
  
  <p>Driver code</p>
  
  <pre><code>def main(args: Array[String]) {
  
      val x=rangify( List(1,2,3,6,7,8).toIterator ).reduce( (x,y) =&gt; x ++ y)      
  /** This line gives the error -type mismatch, 
  found : scala.collection.immutable.IndexedSeq[Int] required: Range */
  }
  </code></pre>