diff options
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' */ |