blob: 0734e1111f2900792b28fed9eae05ce345f14622 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala
/** Counted iterators keep track of the number of elements seen so far
*
* @author Martin Odersky
* @version 1.0, 16/07/2003
*/
trait CountedIterator[+A] extends Iterator[A] {
/** counts the elements in this iterator; counts start at 0
*/
def count: Int
override def counted : this.type = this
override def buffered: BufferedIterator[A] with CountedIterator[A] = new BufferedIterator.Default[A] with CountedIterator[A] {
protected def fill(sz : Int) = if (CountedIterator.this.hasNext) (CountedIterator.this.next) :: Nil else Nil
override def count = CountedIterator.this.count - peekList(0).length
override def counted : this.type = this
override def buffered : this.type = this
}
}
|