Given a Resource
, possibly built by composing multiple
Resource
s monadically, returns the acquired resource, as well
as an action that runs all the finalizers for releasing it.
Given a Resource
, possibly built by composing multiple
Resource
s monadically, returns the acquired resource, as well
as an action that runs all the finalizers for releasing it.
If the outer F
fails or is interrupted, allocated
guarantees
that the finalizers will be called. However, if the outer F
succeeds, it's up to the user to ensure the returned F[Unit]
is called once A
needs to be released. If the returned
F[Unit]
is not called, the finalizers will not be run.
For this reason, this is an advanced and potentially unsafe api
which can cause a resource leak if not used correctly, please
prefer use as the standard way of running a Resource
program.
Use cases include interacting with side-effectful apis that
expect separate acquire and release actions (like the before
and after
methods of many test frameworks), or complex library
code that needs to modify or move the finalizer for an existing
resource.
Applies an effectful transformation to the allocated resource.
Applies an effectful transformation to the allocated resource. Like a
flatMap
on F[A]
while maintaining the resource context
Applies an effectful transformation to the allocated resource.
Applies an effectful transformation to the allocated resource. Like a
flatTap
on F[A]
while maintaining the resource context
Implementation for the flatMap
operation, as described via the
cats.Monad
type class.
Implementation for the flatMap
operation, as described via the
cats.Monad
type class.
Given a mapping function, transforms the resource provided by this Resource.
Given a mapping function, transforms the resource provided by this Resource.
This is the standard Functor.map
.
Given a natural transformation from F
to G
, transforms this
Resource from effect F
to effect G
.
Given a natural transformation from F
to G
, transforms this
Resource from effect F
to effect G
.
Allocates a resource and supplies it to the given function.
Allocates a resource and supplies it to the given function. The
resource is released as soon as the resulting F[B]
is
completed, whether normally or as a raised error.
the function to apply to the allocated resource
the result of applying [F] to
Resource
data constructor that encodes theflatMap
operation.