Skip to content

Commit

Permalink
fixup! fixup! Redesign NonEmptyLazyList to be maximally lazy
Browse files Browse the repository at this point in the history
no more private var
  • Loading branch information
NthPortal committed Sep 3, 2023
1 parent 3a2df1c commit 3869250
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,10 @@ object NonEmptyLazyList extends NonEmptyLazyListInstances {
// allows the creation of fully lazy `NonEmptyLazyList`s by prepending to this
def maybe[A](ll: => LazyList[A]): Maybe[A] = new Maybe(() => ll)

final class Maybe[A] private[NonEmptyLazyList] (private[this] var mkLL: () => LazyList[A]) {
final class Maybe[A] private[NonEmptyLazyList] (mkLL: () => LazyList[A]) {
// because instances of this class are created explicitly, they might be
// reused, and we don't want to re-evaluate `mkLL`
private[this] lazy val ll = {
val res = mkLL()
mkLL = null // allow GC
res
}
private[this] lazy val ll = mkLL()

def #::[B >: A](elem: => B): NonEmptyLazyList[B] =
create(elem #:: ll)
Expand Down

0 comments on commit 3869250

Please sign in to comment.