diff options
-rw-r--r-- | sources/scala/Iterator.scala | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/sources/scala/Iterator.scala b/sources/scala/Iterator.scala index 1f7a437b5f..6209d82980 100644 --- a/sources/scala/Iterator.scala +++ b/sources/scala/Iterator.scala @@ -94,6 +94,14 @@ trait Iterator[+a] with Iterable[a] { def next = f(Iterator.this.next) } + def foldLeft[b] ( z:b ) ( f: (b,a)=>b ): b = { + var acc = z; + while( hasNext ) { + acc = f( acc, next) + } + acc + } + def flatMap[b](f: a => Iterator[b]): Iterator[b] = new Iterator[b] { private var cur: Iterator[b] = Iterator.empty; def hasNext: Boolean = |