Implementation for the flatMap
operation, as described via the
cats.Monad
type class.
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
The
Resource
is a data structure that captures the effectful allocation of a resource, along with its finalizer.This can be used to wrap expensive resources. Example:
Usage is done via use and note that resource usage nests, because its implementation is specified in terms of Bracket:
Resource
forms aMonadError
on the resource type when the effect type has acats.MonadError
instance. Nested resources are released in reverse order of acquisition. Outer resources are released even if an inner use or release fails.On evaluation the above prints:
A
Resource
is nothing more than a data structure, an ADT, described by the following node types and that can be interpretted if needed:Normally users don't need to care about these node types, unless conversions from
Resource
into something else is needed (e.g. conversion fromResource
into a streaming data type).the effect type in which the resource is allocated and released
the type of resource