Skip to content

LazyList.fill and LazyList.tabulate aren't lazy in the head #11083

Closed
@SethTisue

Description

@SethTisue

for LazyList.fill, I would expect the same output in both cases here:

scala> LazyList.continually(println("hey!")).apply(4)
hey!

scala> LazyList.fill(5)(println("hey!")).apply(4)
hey!
hey!
hey!
hey!
hey!

and similarly for tabulate:

scala> import util.chaining._
import util.chaining._

scala> LazyList.from(0).map(_.tap(println)).apply(4)
4
res30: Int = 4

scala> LazyList.tabulate(5)(_.tap(println)).apply(4)
0
1
2
3
4
res32: Int = 4

perhaps there are other methods with this problem?

noticed in @paulp's gist: https://gist.github.com/paulp/fac614c6de23c10644a7af25f4ef96e4

tentatively assigning @NthPortal as this is a continuation of scala/scala#7000


methods to fix:

  • fill
  • tabulate

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions