scala / collection-strawman

Implementation of the new Scala 2.13 Collections
Apache License 2.0
200 stars 72 forks source link

LazyList.iterate Repeated compute head #529

Closed linqing closed 6 years ago

linqing commented 6 years ago

scala> def h() = { println("compute head"); 1} h: ()Int

scala> LazyList.iterate(h())(_ + 1).take(3).toList compute head compute head compute head res5: List[Int] = List(1, 2, 3) It's bug or not?

julienrf commented 6 years ago

It’s a bug, thanks for reporting!

SethTisue commented 6 years ago

I had noticed that some of my LazyList based Project Euler solutions were taking forever to run and had intended to investigate... this seems like a likely culprit! /cc @szeiger