Bind

final case class Bind[F[_], S, +A](source: Resource[F, S], fs: S => Resource[F, A]) extends InvariantResource[F, A]

Resource data constructor that encodes the flatMap operation.

trait Serializable
trait Product
trait Equals
trait InvariantResource[F, A]
class Resource[F, A]
class ResourceLike[F, A]
class Object
trait Matchable
class Any

Type members

Inherited types

type F0[x] = F[x]
Inherited from
InvariantResource

Value members

Inherited methods

def allocated[G[x], B >: A](implicit F: BracketThrow[G]): G[(B, G[Unit])]

Given a Resource, possibly built by composing multiple Resources 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 Resources 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.

Inherited from
ResourceLike
def combineK[G[x], B >: A](that: Resource[G, B])(implicit F: Sync[G], K: SemigroupK[G]): Resource[G, B]

Combines two Resource instances by lifting the behaviour of a SemigroupK instance into the resource context

Combines two Resource instances by lifting the behaviour of a SemigroupK instance into the resource context

Inherited from
Resource
def evalMap[G[x], B](f: A => G[B])(implicit F: Applicative[G]): Resource[G, B]

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. Like a flatMap on F[A] while maintaining the resource context

Inherited from
ResourceLike
def evalTap[G[x], B](f: A => G[B])(implicit F: Applicative[G]): Resource[G, A]

Applies an effectful transformation to the allocated resource. Like a flatTap on F[A] while maintaining the resource context

Applies an effectful transformation to the allocated resource. Like a flatTap on F[A] while maintaining the resource context

Inherited from
ResourceLike
def flatMap[G[x], B](f: A => Resource[G, B]): Resource[G, B]

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.

Inherited from
ResourceLike
def map[G[x], B](f: A => B)(implicit F: Applicative[G]): Resource[G, B]

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.

Inherited from
ResourceLike
def mapK[G[x], H[_]](f: FunctionK[G, H])(implicit D: Defer[H], G: Applicative[H]): Resource[H, A]

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.

Inherited from
Resource
def onFinalize[G[x]](finalizer: G[Unit])(implicit F: Applicative[G]): Resource[G, A]

Runs finalizer when this resource is closed. Unlike the release action passed to Resource.make, this will run even if resource acquisition fails or is canceled.

Runs finalizer when this resource is closed. Unlike the release action passed to Resource.make, this will run even if resource acquisition fails or is canceled.

Inherited from
Resource
def onFinalizeCase[G[x]](f: ExitCase[Throwable] => G[Unit])(implicit F: Applicative[G]): Resource[G, A]

Like onFinalize, but the action performed depends on the exit case.

Like onFinalize, but the action performed depends on the exit case.

Inherited from
Resource
def parZip[G[x], B](that: Resource[G, B])(implicit evidence$1: Sync[G], evidence$2: Parallel[G]): Resource[G, (A, B)]

Allocates two resources concurrently, and combines their results in a tuple.

Allocates two resources concurrently, and combines their results in a tuple.

The finalizers for the two resources are also run concurrently with each other, but within each of the two resources, nested finalizers are run in the usual reverse order of acquisition.

Note that Resource also comes with a cats.Parallel instance that offers more convenient access to the same functionality as parZip, for example via parMapN:

 def mkResource(name: String) = {
   val acquire =
     IO(scala.util.Random.nextInt(1000).millis).flatMap(IO.sleep) *>
     IO(println(s"Acquiring $$name")).as(name)

   val release = IO(println(s"Releasing $$name"))
   Resource.make(acquire)(release)
 }

val r = (mkResource("one"), mkResource("two"))
           .parMapN((s1, s2) => s"I have $s1 and $s2")
           .use(msg => IO(println(msg)))
Inherited from
ResourceLike
def productElementNames: Iterator[String]
Inherited from
Product
def productIterator: Iterator[Any]
Inherited from
Product
def use[G[x], B](f: A => G[B])(implicit F: BracketThrow[G]): G[B]

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.

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.

Value Params
f

the function to apply to the allocated resource

Returns

the result of applying [F] to

Inherited from
ResourceLike