From 1e8a1470473f1fe81f35a1edcf8829792f066867 Mon Sep 17 00:00:00 2001 From: jbwheatley Date: Mon, 11 Apr 2022 16:28:02 +0100 Subject: [PATCH 1/2] add Stream.resourceK method --- core/shared/src/main/scala/fs2/Stream.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/shared/src/main/scala/fs2/Stream.scala b/core/shared/src/main/scala/fs2/Stream.scala index f03099a8f5..82d6e409e0 100644 --- a/core/shared/src/main/scala/fs2/Stream.scala +++ b/core/shared/src/main/scala/fs2/Stream.scala @@ -3614,6 +3614,12 @@ object Stream extends StreamLowPriority { def resource[F[_], O](r: Resource[F, O])(implicit F: MonadCancel[F, _]): Stream[F, O] = resourceWeak(r).scope + /** Same as [[resource]], but expressed as a FunctionK. */ + def resourceK[F[_]](implicit F: MonadCancel[F, _]): Resource[F, *] ~> Stream[F, *] = + new (Resource[F, *] ~> Stream[F, *]) { + override def apply[A](fa: Resource[F, A]): Stream[F, A] = resource[F, A](fa) + } + /** Like [[resource]] but does not introduce a scope, allowing finalization to occur after * subsequent appends or other scope-preserving transformations. * From 371cc74c48d56008ef2067ecfa7c98f24ad2a7ce Mon Sep 17 00:00:00 2001 From: jbwheatley Date: Mon, 11 Apr 2022 17:22:45 +0100 Subject: [PATCH 2/2] add Stream.resourceWeakK method --- core/shared/src/main/scala/fs2/Stream.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/shared/src/main/scala/fs2/Stream.scala b/core/shared/src/main/scala/fs2/Stream.scala index 82d6e409e0..a5ab6ec76d 100644 --- a/core/shared/src/main/scala/fs2/Stream.scala +++ b/core/shared/src/main/scala/fs2/Stream.scala @@ -3639,6 +3639,12 @@ object Stream extends StreamLowPriority { case Resource.Pure(o) => Stream.emit(o) } + /** Same as [[resourceWeak]], but expressed as a FunctionK. */ + def resourceWeakK[F[_]](implicit F: MonadCancel[F, _]): Resource[F, *] ~> Stream[F, *] = + new (Resource[F, *] ~> Stream[F, *]) { + override def apply[A](fa: Resource[F, A]): Stream[F, A] = resourceWeak[F, A](fa) + } + /** Converts the supplied [[java.lang.Autoclosable]] into a singleton stream. */ def fromAutoCloseable[F[_]: Sync, O <: AutoCloseable](fo: F[O]): Stream[F, O] = Stream.resource(Resource.fromAutoCloseable(fo))