diff options
-rw-r--r-- | src/library/scala/collection/immutable/Stream.scala | 15 | ||||
-rw-r--r-- | test/files/run/t2255.check | 1 | ||||
-rw-r--r-- | test/files/run/t2255.scala | 3 |
3 files changed, 19 insertions, 0 deletions
diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala index 00bc959fe4..badeb31bbc 100644 --- a/src/library/scala/collection/immutable/Stream.scala +++ b/src/library/scala/collection/immutable/Stream.scala @@ -237,6 +237,8 @@ self => super.mkString } + override def toString = super.mkString(stringPrefix + "(", ", ", ")") + /** Returns the <code>n</code> first elements of this stream, or else the whole * stream, if it has less than <code>n</code> elements. * @@ -341,6 +343,19 @@ self => result } + override def flatten[B](implicit toTraversable: A => Traversable[B]): Stream[B] = { + def flatten1(t: Traversable[B]): Stream[B] = + if (!t.isEmpty) + new Stream.Cons(t.head, flatten1(t.tail)) + else + tail.flatten + + if (isEmpty) + Stream.empty + else + flatten1(toTraversable(head)) + } + /** Defines the prefix of this object's <code>toString</code> representation as ``Stream''. */ override def stringPrefix = "Stream" diff --git a/test/files/run/t2255.check b/test/files/run/t2255.check new file mode 100644 index 0000000000..dda391b36d --- /dev/null +++ b/test/files/run/t2255.check @@ -0,0 +1 @@ +List(1, 2, 3, 1, 2, 3) diff --git a/test/files/run/t2255.scala b/test/files/run/t2255.scala new file mode 100644 index 0000000000..be800adf5a --- /dev/null +++ b/test/files/run/t2255.scala @@ -0,0 +1,3 @@ +object Test extends Application { + println(Stream.continually(Stream(1, 2, 3)).flatten.take(6).toList) +} |