Resource

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

Type members

Classlikes

final case class Allocate[F <: ([_$39] =>> Any), A](resource: Poll[F] => F[(A, ExitCase => F[Unit])]) extends Resource[F, A]
Resource data constructor that wraps an effect allocating a resource,
along with its finalizers.
final case class Bind[F <: ([_$40] =>> Any), S, +A](source: Resource[F, S], fs: S => Resource[F, A]) extends Resource[F, A]
Resource data constructor that encodes the flatMap operation.
final case class Pure[F <: ([_$41] =>> Any), +A](a: A) extends Resource[F, A]
final case class Eval[F <: ([_$42] =>> Any), A](fa: F[A]) extends Resource[F, A]
sealed trait ExitCase extends Product with Serializable
Type for signaling the exit condition of an effectful
computation, that may either succeed, fail with an error or
get canceled.
The types of exit signals are:
Companion
object
object ExitCase
Companion
class
object Par

Types

type Par[F <: ([_$48] =>> Any), +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.
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.

Inherited types

type MirroredElemLabels <: Tuple
The names of the product elements
Inhertied from
Mirror
type MirroredLabel <: String
The name of the type
Inhertied from
Mirror

Value members

Methods

def apply[F <: ([_$18] =>> Any), A](resource: F[(A, F[Unit])])(F: Functor[F]): Resource[F, A]
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 <: ([_$20] =>> Any), A](resource: F[(A, ExitCase => F[Unit])]): Resource[F, A]
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 applyFull[F <: ([_$22] =>> Any), A](resource: Poll[F] => F[(A, ExitCase => F[Unit])]): Resource[F, A]
Creates a resource from an allocating effect, with a finalizer
that is able to distinguish between exit cases.
The action takes a Poll[F] to allow for interruptible acquires,
which is most often useful when acquiring lock-like structure: it
should be possible to interrupt a fiber waiting on a lock, but if
it does get acquired, release need to be guaranteed.
Note that in this case the acquire action should know how to cleanup
after itself in case it gets canceled, since Resource will only
guarantee release when acquire succeeds and fails (and when the
actions in use or flatMap fail, succeed, or get canceled)
TODO make sure this api, which is more general than makeFull, doesn't allow
for interruptible releases
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, where acquisition can
potentially be interrupted
See also
makeFull for a version that separates the needed resource
with its finalizer tuple in two parameters
def suspend[F <: ([_$23] =>> Any), A](fr: F[Resource[F, A]]): Resource[F, A]
Given a Resource suspended in F[_], lifts it in the Resource context.
def make[F <: ([_$24] =>> Any), 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.
Type Params
A
the type of the resource
F
the effect type in which the resource is acquired and released
Value Params
acquire
an effect to acquire a resource
release
a function to effectfully release the resource returned by acquire
def makeCase[F <: ([_$25] =>> Any), A](acquire: F[A])(release: (A, ExitCase) => 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.
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 makeFull[F <: ([_$26] =>> Any), A](acquire: Poll[F] => F[A])(release: A => 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.
The acquiring effect takes a Poll[F] to allow for interruptible
acquires, which is most often useful when acquiring lock-like
structures: it should be possible to interrupt a fiber waiting on
a lock, but if it does get acquired, release need to be
guaranteed.
Note that in this case the acquire action should know how to cleanup
after itself in case it gets canceled, since Resource will only
guarantee release when acquire succeeds and fails (and when the
actions in use or flatMap fail, succeed, or get canceled)
Type Params
A
the type of the resource
F
the effect type in which the resource is acquired and released
Value Params
acquire
an effect to acquire a resource, possibly interruptibly
release
a function to effectfully release the resource returned by acquire
def makeCaseFull[F <: ([_$28] =>> Any), A](acquire: Poll[F] => F[A])(release: (A, ExitCase) => 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.
The acquiring effect takes a Poll[F] to allow for interruptible
acquires, which is most often useful when acquiring lock-like
structures: it should be possible to interrupt a fiber waiting on
a lock, but if it does get acquired, release need to be
guaranteed.
Note that in this case the acquire action should know how to cleanup
after itself in case it gets canceled, since Resource will only
guarantee release when acquire succeeds and fails (and when the
actions in use or flatMap fail, succeed, or get canceled)
Type Params
A
the type of the resource
F
the effect type in which the resource is acquired and released
Value Params
acquire
an effect to acquire a resource, possibly interruptibly
release
a function to effectfully release the resource returned by acquire
def pure[F <: ([_$29] =>> Any), A](a: A): Resource[F, A]
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 unit[F <: ([_$30] =>> Any)]: Resource[F, Unit]
A resource with a no-op allocation and a no-op release.
@deprecated("please use `eval` instead.", since = "3.0")
def liftF[F <: ([_$31] =>> Any), A](fa: F[A]): Resource[F, A]
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 eval[F <: ([_$32] =>> Any), A](fa: F[A]): Resource[F, A]
def onFinalize[F <: ([_$33] =>> Any)](release: F[Unit])(evidence$1: Applicative[F]): Resource[F, Unit]
Lifts a finalizer into a resource. The resource has a no-op allocation.
def onFinalizeCase[F <: ([_$34] =>> Any)](release: ExitCase => F[Unit])(evidence$2: Applicative[F]): Resource[F, Unit]
Creates a resource that allocates immediately without any effects,
but calls release when closing, providing the the usage completed with.
def liftK[F <: ([_$35] =>> Any)]: FunctionK[F, [_$36] =>> Resource[F, _$36]]
Lifts an applicative into a resource as a FunctionK. The resource has a no-op release.
def fromAutoCloseable[F <: ([_$38] =>> Any), A <: AutoCloseable](acquire: F[A])(F: Sync[F]): Resource[F, A]
Creates a Resource by wrapping a Java
AutoCloseable.
In most real world cases, implementors of AutoCloseable are
blocking as well, so the close action runs in the blocking
context.
Example:
{{{
import cats.effect._
import scala.io.Source
def reader[F[_] ](data: String)(implicit F: Sync[F] ): Resource[F, Source] =
Resource.fromAutoCloseable(F.blocking {
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

Inherited methods

def fromDestroyable[F <: ([_$1] =>> Any), A <: Destroyable](acquire: F[A])(F: Sync[F]): Resource[F, A]
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
Inhertied from
ResourcePlatform

Implicits

Inherited implicits

implicit def catsEffectCommutativeApplicativeForResourcePar[F <: ([_$55] =>> Any)](F: Concurrent[F]): CommutativeApplicative[[_$56] =>> Type[F, _$56]]
Inhertied from
ResourceInstances
implicit def catsEffectParallelForResource[F0 <: ([_$57] =>> Any)](evidence$3: Concurrent[F0]): Aux[[_$58] =>> Resource[F0, _$58], [_$59] =>> Type[F0, _$59]]
Inhertied from
ResourceInstances
implicit def catsEffectMonadForResource[F <: ([_$60] =>> Any)](F0: Monad[F]): Monad[[_$61] =>> Resource[F, _$61]]
Inhertied from
ResourceInstances0
implicit def catsEffectMonoidForResource[F <: ([_$54] =>> Any), A](F0: Monad[F], A0: Monoid[A]): Monoid[Resource[F, A]]
Inhertied from
ResourceInstances
implicit def catsEffectSemigroupForResource[F <: ([_$62] =>> Any), A](F0: Monad[F], A0: Semigroup[A]): ResourceSemigroup[F, A]
Inhertied from
ResourceInstances0
implicit def catsEffectSemigroupKForResource[F <: ([_$63] =>> Any), A](F0: MonadCancel[F, Throwable], K0: SemigroupK[F], G0: Make[F]): ResourceSemigroupK[F]
Inhertied from
ResourceInstances0
implicit def catsEffectMonadErrorForResource[F <: ([_$52] =>> Any), E](F0: MonadError[F, E]): MonadError[[_$53] =>> Resource[F, _$53], E]
Inhertied from
ResourceInstances