From 0e13ff9b79672f5e401249f7ae20f4c9234f04a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20G=C3=B3mez?= Date: Fri, 6 May 2016 16:43:01 +0200 Subject: [PATCH] Use Future#successful in pureEval when possible Since `Now` already has performed the work required to calculate the result value, we can lift the result into a Future using `Future#successful` instead of unwrapping the `Now` inside the block run by the `Future` (which potentially has to use another thread). --- core/src/main/scala/cats/std/future.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/cats/std/future.scala b/core/src/main/scala/cats/std/future.scala index 3c74ddc723..e1453870d6 100644 --- a/core/src/main/scala/cats/std/future.scala +++ b/core/src/main/scala/cats/std/future.scala @@ -13,7 +13,10 @@ trait FutureInstances extends FutureInstances1 { new FutureCoflatMap with MonadError[Future, Throwable]{ def pure[A](x: A): Future[A] = Future.successful(x) - override def pureEval[A](x: Eval[A]): Future[A] = Future(x.value) + override def pureEval[A](x: Eval[A]): Future[A] = x match { + case Now(x) => Future.successful(x) + case _ => Future(x.value) + } def flatMap[A, B](fa: Future[A])(f: A => Future[B]): Future[B] = fa.flatMap(f)