Skip to content

Stream concat (#:::) vs append (++) #10370

@manojo

Description

@manojo

The difference between concat (#:::) and append (++) on streams should be documented more clearly. The append method does say that ++ works in very subtle ways, but it breaks down in even simple cases. Consider fibs defined as below.

def fibs: Stream[Int] = Stream(0, 1) ++ (fibs.zip(fibs.tail).map { case (a, b) => a + b })

Calling fibs will result in a stack overflow, despite (as documentation says), the left hand side of ++ being a Stream. Using concat (#:::) however works as expected.

def fibs: Stream[Int] = Stream(0, 1) #::: (fibs.zip(fibs.tail).map { case (a, b) => a + b })

Since this is a subtle issue (not clear whether a bug), it might just be wise to add a warning about this behaviour higher up in the documentation, and in the official docs.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions