diff options
author | Martin Odersky <odersky@gmail.com> | 2003-12-04 20:20:08 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2003-12-04 20:20:08 +0000 |
commit | 2bda1797dc257cdd2c4ec5a1dfeec9c88b0efbe0 (patch) | |
tree | e26e227c4b301ce0e08c1b571ee6d23952f139b3 /sources | |
parent | d56b51f38d22125de915e1286bcec8cb896143ec (diff) | |
download | scala-2bda1797dc257cdd2c4ec5a1dfeec9c88b0efbe0.tar.gz scala-2bda1797dc257cdd2c4ec5a1dfeec9c88b0efbe0.tar.bz2 scala-2bda1797dc257cdd2c4ec5a1dfeec9c88b0efbe0.zip |
*** empty log message ***
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/Iterator.scala | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/sources/scala/Iterator.scala b/sources/scala/Iterator.scala index 7e11fa3a01..301abf9f17 100644 --- a/sources/scala/Iterator.scala +++ b/sources/scala/Iterator.scala @@ -34,13 +34,16 @@ object Iterator { else error("next on empty iterator"); } - def range(lo: Int, end: Int) = new Iterator[Int] { + def range(lo: Int, end: Int) = new BufferedIterator[Int] { private var i = lo; def hasNext: Boolean = i < end; def next: Int = if (i < end) { i = i + 1 ; i - 1 } else error("next on empty iterator"); + def head: Int = + if (i < end) i + else error("head on empty iterator"); } def from(lo: Int) = new Iterator[Int] { @@ -102,6 +105,13 @@ trait Iterator[+a] with Iterable[a] { acc } + def /:[b](z: b)(f: (b, a) => b): b = foldLeft(z)(f); + + def append[b >: a](that: Iterator[b]) = new Iterator[b] { + def hasNext = Iterator.this.hasNext || that.hasNext; + def next = if (Iterator.this.hasNext) Iterator.this.next else that.next; + } + def flatMap[b](f: a => Iterator[b]): Iterator[b] = new Iterator[b] { private var cur: Iterator[b] = Iterator.empty; def hasNext: Boolean = |