From 2bda1797dc257cdd2c4ec5a1dfeec9c88b0efbe0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 4 Dec 2003 20:20:08 +0000 Subject: *** empty log message *** --- sources/scala/Iterator.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'sources') 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 = -- cgit v1.2.3