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.collect isn't lazy #4294

Closed
scabug opened this issue Feb 24, 2011 · 5 comments
Closed

Stream.collect isn't lazy #4294

scabug opened this issue Feb 24, 2011 · 5 comments
Assignees

Comments

@scabug
Copy link

scabug commented Feb 24, 2011

in both Scala 2.8.1 and Scala 2.9 (latest nightly), this loops until you run out of heap:

Stream.from(1).collect{case x => x}.head
@scabug
Copy link
Author

scabug commented Feb 24, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4294?orig=1
Reporter: @SethTisue

@scabug
Copy link
Author

scabug commented Feb 28, 2011

@axel22 said:
(In r24351) Fixes and closes #4294.

No review.

@scabug
Copy link
Author

scabug commented Mar 2, 2011

Atsuhiko Yamanaka (ymnk) said:

$$ scala
Welcome to Scala version 2.9.0.r24358-b20110301020104 (Java HotSpot(TM) Client VM, Java 1.6.0_16).
Type in expressions to have them evaluated.
Type :help for more information.

scala> Stream.from(0, 1).collect{case x => x+1}
res0: scala.collection.immutable.Stream[Int] = Stream(0, ?)

scala> res0.take(10).toList
res1: List[Int] = List(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

IMHO, a fix for collectedTail method in r24351 is not correct; I mean pf has not been applied. It should be ...

private[immutable] def collectedTail[A, B, That](stream: Stream[A], pf: PartialFunction[A, B], bf: CanBuildFrom[Stream[A], B, That]) = { 
  new Stream.Cons(pf(stream.head), stream.tail.collect(pf)(bf).asInstanceOf[Stream[B]]) 
} 

@scabug
Copy link
Author

scabug commented Mar 2, 2011

@paulp said:
(In r24366) Made Stream.collect collect instead of filter. Closes #4294.
Glad to see there was a test case; but we have to push harder
when writing tests to include the key characteristics of the
function being tested. No review.

@scabug
Copy link
Author

scabug commented Mar 2, 2011

@axel22 said:
Thanks for fixing that.

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

No branches or pull requests

2 participants