diff options
author | michelou <michelou@epfl.ch> | 2007-10-05 16:48:02 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2007-10-05 16:48:02 +0000 |
commit | 41865ed00183a049d6fbaebc97897eebd2956d68 (patch) | |
tree | 4d88344154774c1a95046f8f22771d6f7a5f0e72 /src/library | |
parent | 6761dc14b707667b453455aa6cecb0c82babeed3 (diff) | |
download | scala-41865ed00183a049d6fbaebc97897eebd2956d68.tar.gz scala-41865ed00183a049d6fbaebc97897eebd2956d68.tar.bz2 scala-41865ed00183a049d6fbaebc97897eebd2956d68.zip |
fixed ticket #153
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/Stream.scala | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/library/scala/Stream.scala b/src/library/scala/Stream.scala index 5a4a705a61..034c9aa70f 100644 --- a/src/library/scala/Stream.scala +++ b/src/library/scala/Stream.scala @@ -414,13 +414,19 @@ trait Stream[+A] extends Seq.Projection[A] { * @return <code>f(a<sub>0</sub>) ::: ... ::: f(a<sub>n</sub>)</code> if * this stream is <code>[a<sub>0</sub>, ..., a<sub>n</sub>]</code>. */ - override def flatMap[B](f: A => Iterable[B]): Stream[B] = - if (isEmpty) Stream.empty - else (f(head)).toStream append tail.flatMap(f) + override def flatMap[B](f: A => Iterable[B]): Stream[B] = { + var acc: Stream[B] = Stream.empty + var these = this + while (!these.isEmpty) { + val those = f(these.head) + if (!those.isEmpty) acc = acc append those.toStream + these = these.tail + } + acc + } override def toStream = this - /** A stream consisting of all elements of this stream in reverse order. */ override def reverse: Stream[A] = |