diff options
author | buraq <buraq@epfl.ch> | 2003-11-17 10:03:16 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2003-11-17 10:03:16 +0000 |
commit | 8e28c8583d74c4f356b7ea4a7cb55e164b3a1c0b (patch) | |
tree | 997f9ebf80bfb866dd85c479c1bf9031a890316e | |
parent | 859704d7d6a84559715335c74698bb361fbc0fe2 (diff) | |
download | scala-8e28c8583d74c4f356b7ea4a7cb55e164b3a1c0b.tar.gz scala-8e28c8583d74c4f356b7ea4a7cb55e164b3a1c0b.tar.bz2 scala-8e28c8583d74c4f356b7ea4a7cb55e164b3a1c0b.zip |
added foldLeft method
-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 = |