Skip to content

LazyList's last method (and perhaps others?) should be lazier #11089

Closed
@SethTisue

Description

@SethTisue
scala> def ll() = { var counter = 0 ; LazyList.continually{println(counter); counter += 1; counter} }
ll: ()scala.collection.immutable.LazyList[Int]

scala> ll()(5)
0
res9: Int = 1

scala> ll().take(5).last
0
1
2
3
4
res10: Int = 5

reported by @paulp at https://twitter.com/contrarivariant/status/1030065587559362561

are there other methods that may have this problem?

related: #11083

/cc @NthPortal @szeiger @julienrf


methods to fix:

  • last
  • dropRight
  • takeRight
  • slice

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions