diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-03-16 14:23:13 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-03-16 14:23:13 +0000 |
commit | 4a2e3d417557e38ccb09404e93701454f6e11e37 (patch) | |
tree | 86cc6d2161b4baa863cee6197bccc32b80053992 /src | |
parent | 3bcd23488e84ef1af0ba77653e8c0d74bac846e6 (diff) | |
download | scala-4a2e3d417557e38ccb09404e93701454f6e11e37.tar.gz scala-4a2e3d417557e38ccb09404e93701454f6e11e37.tar.bz2 scala-4a2e3d417557e38ccb09404e93701454f6e11e37.zip |
Fixes infinite streams in #3091. No review.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/immutable/Stream.scala | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala index 6c55131175..33e5b70f90 100644 --- a/src/library/scala/collection/immutable/Stream.scala +++ b/src/library/scala/collection/immutable/Stream.scala @@ -119,6 +119,16 @@ self => else new Stream.Cons(head, (tail ++ that).asInstanceOf[Stream[A]])).asInstanceOf[That] } + /** + * Create a new stream which contains all intermediate results of applying the operator + * to subsequent elements left to right. + * @note This works because the target type of the Builder That is a Stream. + */ + override final def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[Stream[A], B, That]): That = { + (if (this.isEmpty) Stream(z) + else new Stream.Cons(z, tail.scanLeft(op(z, head))(op).asInstanceOf[Stream[B]])).asInstanceOf[That] + } + /** Create a new stream which contains all elements of this stream * followed by all elements of Iterator `that' */ |