diff --git a/core/shared/src/main/scala/cats/effect/Resource.scala b/core/shared/src/main/scala/cats/effect/Resource.scala index 5ba81c9692..86a4e43b0d 100644 --- a/core/shared/src/main/scala/cats/effect/Resource.scala +++ b/core/shared/src/main/scala/cats/effect/Resource.scala @@ -325,6 +325,12 @@ object Resource extends ResourceInstances with ResourcePlatform { def liftF[F[_], A](fa: F[A])(implicit F: Applicative[F]): Resource[F, A] = Resource.suspend(fa.map(a => Resource.pure(a))) + /** + * Lifts an applicative into a resource as a `FunctionK`. The resource has a no-op release. + */ + def liftK[F[_]](implicit F: Applicative[F]): F ~> Resource[F, ?] = + λ[F ~> Resource[F, ?]](Resource.liftF(_)) + /** * Creates a [[Resource]] by wrapping a Java * [[https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html AutoCloseable]]. diff --git a/laws/shared/src/test/scala/cats/effect/ResourceTests.scala b/laws/shared/src/test/scala/cats/effect/ResourceTests.scala index 7f5248d349..6d3a588e3b 100644 --- a/laws/shared/src/test/scala/cats/effect/ResourceTests.scala +++ b/laws/shared/src/test/scala/cats/effect/ResourceTests.scala @@ -115,6 +115,12 @@ class ResourceTests extends BaseTestsSuite { res.value shouldBe Some(Success(ExitCase.Canceled)) } + testAsync("liftF(fa) <-> liftK.apply(fa)") { implicit ec => + check { (fa: IO[String], f: String => IO[Int]) => + Resource.liftF(fa).use(f) <-> Resource.liftK[IO].apply(fa).use(f) + } + } + testAsync("evalMap") { implicit ec => check { (f: Int => IO[Int]) => Resource.liftF(IO(0)).evalMap(f).use(IO.pure) <-> f(0)