From 3869250635083790e9b1e588f74282a7a636fa7b Mon Sep 17 00:00:00 2001 From: Marissa Date: Sun, 3 Sep 2023 19:59:19 -0400 Subject: [PATCH] fixup! fixup! Redesign `NonEmptyLazyList` to be maximally lazy no more private var --- .../src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala b/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala index ca4eb25bc35..79eb61e0bdc 100644 --- a/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala +++ b/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala @@ -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)