From 8bfaab5d62b489bf273699924a1ee5efef1eb64d Mon Sep 17 00:00:00 2001 From: Yann Simon Date: Thu, 4 Jul 2024 17:26:09 +0200 Subject: [PATCH 1/2] Issue #4631: Make Later covariant Same as https://github.com/typelevel/cats/pull/937 --- core/src/main/scala/cats/Eval.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/cats/Eval.scala b/core/src/main/scala/cats/Eval.scala index 7834248b3c..ceb6b87fad 100644 --- a/core/src/main/scala/cats/Eval.scala +++ b/core/src/main/scala/cats/Eval.scala @@ -157,7 +157,7 @@ final case class Now[A](value: A) extends Eval.Leaf[A] { * by the closure) will not be retained, and will be available for * garbage collection. */ -final class Later[A](f: () => A) extends Eval.Leaf[A] { +final class Later[+A](f: () => A) extends Eval.Leaf[A] { private[this] var thunk: () => A = f // The idea here is that `f` may have captured very large @@ -206,7 +206,7 @@ object Eval extends EvalInstances { * so calling .value does not trigger * any flatMaps or defers */ - sealed abstract class Leaf[A] extends Eval[A] + sealed abstract class Leaf[+A] extends Eval[A] /** * Construct an eager Eval[A] value (i.e. Now[A]). From 94526a9ae802779ce5e27d7169a6d0d19ad3bad2 Mon Sep 17 00:00:00 2001 From: Yann Simon Date: Fri, 5 Jul 2024 09:20:00 +0200 Subject: [PATCH 2/2] covariant all leafs of eval --- core/src/main/scala/cats/Eval.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/cats/Eval.scala b/core/src/main/scala/cats/Eval.scala index ceb6b87fad..813537e2e0 100644 --- a/core/src/main/scala/cats/Eval.scala +++ b/core/src/main/scala/cats/Eval.scala @@ -139,7 +139,7 @@ sealed abstract class Eval[+A] extends Serializable { self => * This type should be used when an A value is already in hand, or * when the computation to produce an A value is pure and very fast. */ -final case class Now[A](value: A) extends Eval.Leaf[A] { +final case class Now[+A](value: A) extends Eval.Leaf[A] { def memoize: Eval[A] = this } @@ -190,7 +190,7 @@ object Later { * required. It should be avoided except when laziness is required and * caching must be avoided. Generally, prefer Later. */ -final class Always[A](f: () => A) extends Eval.Leaf[A] { +final class Always[+A](f: () => A) extends Eval.Leaf[A] { def value: A = f() def memoize: Eval[A] = new Later(f) }