Resource

object Resource extends ResourceInstances with ResourcePlatform
Companion
class
trait ResourcePlatform
class ResourceInstances
class ResourceInstances0
class Object
trait Matchable
class Any

Type members

Classlikes

final case class Allocate[F[_], A](resource: F[(A, ExitCase[Throwable] => F[Unit])]) extends InvariantResource[F, A]

Resource data constructor that wraps an effect allocating a resource, along with its finalizers.

Resource data constructor that wraps an effect allocating a resource, along with its finalizers.

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.

Resource data constructor that encodes the flatMap operation.

object Par
final case class Suspend[F[_], A](resource: F[Resource[F, A]]) extends InvariantResource[F, A]

Resource data constructor that suspends the evaluation of another resource value.

Resource data constructor that suspends the evaluation of another resource value.

Types

type Par[+F[_], +A] = Type[F, A]

Newtype encoding for a Resource datatype that has a cats.Applicative capable of doing parallel processing in ap and map2, needed for implementing cats.Parallel.

Newtype encoding for a Resource datatype that has a cats.Applicative capable of doing parallel processing in ap and map2, needed for implementing cats.Parallel.

Helpers are provided for converting back and forth in Par.apply for wrapping any IO value and Par.unwrap for unwrapping.

The encoding is based on the "newtypes" project by Alexander Konovalov, chosen because it's devoid of boxing issues and a good choice until opaque types will land in Scala. alexknvl/newtypes.

Value members

Concrete methods

def apply[F[_], A](resource: F[(A, F[Unit])])(F: Functor[F]): Resource[F, A]

Creates a resource from an allocating effect.

Creates a resource from an allocating effect.

Type Params
A

the type of the resource

F

the effect type in which the resource is acquired and released

Value Params
resource

an effect that returns a tuple of a resource and an effect to release it

See also

make for a version that separates the needed resource with its finalizer tuple in two parameters

def applyCase[F[_], A](resource: F[(A, ExitCase[Throwable] => F[Unit])]): Resource[F, A]

Creates a resource from an allocating effect, with a finalizer that is able to distinguish between exit cases.

Creates a resource from an allocating effect, with a finalizer that is able to distinguish between exit cases.

Type Params
A

the type of the resource

F

the effect type in which the resource is acquired and released

Value Params
resource

an effect that returns a tuple of a resource and an effectful function to release it

See also

makeCase for a version that separates the needed resource with its finalizer tuple in two parameters

def eval[F[_], A](fa: F[A])(F: Applicative[F]): Resource[F, A]

Lifts an applicative into a resource. The resource has a no-op release. Preserves interruptibility of fa.

Lifts an applicative into a resource. The resource has a no-op release. Preserves interruptibility of fa.

Value Params
fa

the value to lift into a resource

def fromAutoCloseable[F[_], A <: AutoCloseable](acquire: F[A])(F: Sync[F]): Resource[F, A]

Creates a Resource by wrapping a Java AutoCloseable.

Creates a Resource by wrapping a Java AutoCloseable.

Example:

 import cats.effect._
 import scala.io.Source

 def reader[F[_]](data: String)(implicit F: Sync[F]): Resource[F, Source] =
   Resource.fromAutoCloseable(F.delay {
     Source.fromString(data)
   })
Type Params
A

the type of the autocloseable resource

F

the type of the effect

Value Params
F

the effect type in which the resource was acquired and will be released

acquire

The effect with the resource to acquire.

Returns

a Resource that will automatically close after use

def fromAutoCloseableBlocking[F[_], A <: AutoCloseable](blocker: Blocker)(acquire: F[A])(`evidence$3`: Sync[F], `evidence$4`: ContextShift[F]): Resource[F, A]

Creates a Resource by wrapping a Java AutoCloseable which is blocking in its adquire and close operations.

Creates a Resource by wrapping a Java AutoCloseable which is blocking in its adquire and close operations.

Example:

 import java.io._
 import cats.effect._

 def reader[F[_]](file: File, blocker: Blocker)(implicit F: Sync[F], cs: ContextShift[F]): Resource[F, BufferedReader] =
   Resource.fromAutoCloseableBlocking(blocker)(F.delay {
     new BufferedReader(new FileReader(file))
   })
Type Params
A

the type of the autocloseable resource

F

the type of the effect

Value Params
acquire

The effect with the resource to acquire

blocker

The blocking context that will be used to compute acquire and close

Returns

a Resource that will automatically close after use

def liftK[F[_]](F: Applicative[F]): FunctionK[F, [_] =>> Resource[F, _$29]]

Lifts an applicative into a resource as a FunctionK. The resource has a no-op release.

Lifts an applicative into a resource as a FunctionK. The resource has a no-op release.

def make[F[_], A](acquire: F[A])(release: A => F[Unit])(F: Functor[F]): Resource[F, A]

Creates a resource from an acquiring effect and a release function.

Creates a resource from an acquiring effect and a release function.

This builder mirrors the signature of Bracket.bracket.

Type Params
A

the type of the resource

F

the effect type in which the resource is acquired and released

Value Params
acquire

a function to effectfully acquire a resource

release

a function to effectfully release the resource returned by acquire

def makeCase[F[_], A](acquire: F[A])(release: (A, ExitCase[Throwable]) => F[Unit])(F: Functor[F]): Resource[F, A]

Creates a resource from an acquiring effect and a release function that can discriminate between different exit cases.

Creates a resource from an acquiring effect and a release function that can discriminate between different exit cases.

This builder mirrors the signature of Bracket.bracketCase.

Type Params
A

the type of the resource

F

the effect type in which the resource is acquired and released

Value Params
acquire

a function to effectfully acquire a resource

release

a function to effectfully release the resource returned by acquire

def pure[F[_], A](a: A)(F: Applicative[F]): Resource[F, A]

Lifts a pure value into a resource. The resource has a no-op release.

Lifts a pure value into a resource. The resource has a no-op release.

Value Params
a

the value to lift into a resource

def suspend[F[_], A](fr: F[Resource[F, A]]): Resource[F, A]

Given a Resource suspended in F[_], lifts it in the Resource context.

Given a Resource suspended in F[_], lifts it in the Resource context.

def tailRecM[F[_], A, B](a: A)(f: A => Resource[F, Either[A, B]])(F: Monad[F]): Resource[F, B]

Implementation for the tailRecM operation, as described via the cats.Monad type class.

Implementation for the tailRecM operation, as described via the cats.Monad type class.

Deprecated methods

@deprecated("please use `eval` instead.", since = "2.4.0")
def liftF[F[_], A](fa: F[A])(F: Applicative[F]): Resource[F, A]
Deprecated
[Since version 2.4.0]

Inherited methods

def fromDestroyable[F[_], A <: Destroyable](acquire: F[A])(F: Sync[F]): Resource[F, A]

Creates a Resource by wrapping a Java Destroyable.

Creates a Resource by wrapping a Java Destroyable.

Example:

 import java.security.KeyStore.PasswordProtection
 import cats.effect._
 import cats.syntax.all._

 def passwordProtection[F[_]](getPassword: F[Array[Char]])(implicit F: Sync[F]): Resource[F, PasswordProtection] =
   Resource.fromDestroyable(
     getPassword.map(new PasswordProtection(_))
   )
Type Params
A

the type of the destroyable resource

F

the type of the effect

Value Params
F

the effect type in which the resource was acquired and will be released

acquire

The effect with the resource to acquire.

Returns

a Resource that will automatically destroy after use

Inherited from
ResourcePlatform

Deprecated and Inherited methods

@deprecated("Use the new implementation, catsEffectSemigroupKForResource2, which behaves more like orElse", "2.2.0")
def catsEffectSemigroupKForResource[F[_], A](F0: Monad[F], K0: SemigroupK[F]): ResourceSemigroupK[F]
Deprecated
Inherited from
ResourceInstances0

Implicits

Inherited implicits

implicit def catsEffectCommutativeApplicativeForResourcePar[F[_]](F: Sync[F], P: Parallel[F]): CommutativeApplicative[[_] =>> Type[F, _$49]]
Inherited from
ResourceInstances
implicit def catsEffectLiftIOForResource[F[_]](F00: LiftIO[F], F10: Applicative[F]): LiftIO[[_] =>> Resource[F, _$47]]
Inherited from
ResourceInstances
implicit def catsEffectMonadErrorForResource[F[_], E](F0: MonadError[F, E]): MonadError[[_] =>> Resource[F, _$44], E]
Inherited from
ResourceInstances
implicit def catsEffectMonadForResource[F[_]](F0: Monad[F]): Monad[[_] =>> Resource[F, _$54]]
Inherited from
ResourceInstances0
implicit def catsEffectMonoidForResource[F[_], A](F0: Monad[F], A0: Monoid[A]): Monoid[Resource[F, A]]
Inherited from
ResourceInstances
implicit def catsEffectParallelForResource[F0[_]](`evidence$5`: Sync[F0], `evidence$6`: Parallel[F0]): Aux[[_] =>> Resource[F0, _$51], [_] =>> Type[F0, _$52]]
Inherited from
ResourceInstances
implicit def catsEffectSemigroupForResource[F[_], A](F0: Monad[F], A0: Semigroup[A]): ResourceSemigroup[F, A]
Inherited from
ResourceInstances0
implicit def catsEffectSemigroupKForResource2[F[_]](F0: Sync[F], K: SemigroupK[F]): SemigroupK[[_] =>> Resource[F, _$57]]
Inherited from
ResourceInstances0