Closed linqing closed 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?
It’s a bug, thanks for reporting!
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
LazyList
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?