summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2003-11-17 10:03:16 +0000
committerburaq <buraq@epfl.ch>2003-11-17 10:03:16 +0000
commit8e28c8583d74c4f356b7ea4a7cb55e164b3a1c0b (patch)
tree997f9ebf80bfb866dd85c479c1bf9031a890316e /sources
parent859704d7d6a84559715335c74698bb361fbc0fe2 (diff)
downloadscala-8e28c8583d74c4f356b7ea4a7cb55e164b3a1c0b.tar.gz
scala-8e28c8583d74c4f356b7ea4a7cb55e164b3a1c0b.tar.bz2
scala-8e28c8583d74c4f356b7ea4a7cb55e164b3a1c0b.zip
added foldLeft method
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/Iterator.scala8
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 =