Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream is "off by one" when using sliding #8475

Closed
scabug opened this issue Apr 4, 2014 · 4 comments
Closed

Stream is "off by one" when using sliding #8475

scabug opened this issue Apr 4, 2014 · 4 comments

Comments

@scabug
Copy link

scabug commented Apr 4, 2014

The following code does not behave as expected:

val input = scala.io.Source.stdin.getLines.toStream
input.sliding(2).foreach(println)

It should start printing out values as soon as the user has supplied 2 values, but it only starts after the third. To generalize, it only starts after n + 1, so for instance, if using sliding(1), it will only start printing out values after the second element, when it should be printing the first one right away.

@scabug
Copy link
Author

scabug commented Apr 4, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8475?orig=1
Reporter: @jedesah
Affected Versions: 2.11.0

@scabug
Copy link
Author

scabug commented May 3, 2014

@jedesah said:
I just noticed that the following somewhat further reduced example produces the same unexpected behaviour:

val input = scala.io.Source.stdin.getLines
input.sliding(2).foreach(println)

Which leads me to think it's not something related to Streams so I should probably update the title.

@scabug
Copy link
Author

scabug commented May 4, 2014

@jedesah said:
I have a fix for this on my machine. Just need to make sure I didn't break anything else and figure out if I can write a test case for this.

@scabug scabug closed this as completed May 27, 2014
@scabug
Copy link
Author

scabug commented Jun 3, 2014

@adriaanm said:
See also scala/scala#3795

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants