- Companion
- class
Type members
Classlikes
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.
Types
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
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
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
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
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
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
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.
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
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
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
Deprecated methods
Inherited methods
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
- Inherited from
- ResourceInstances0
Implicits
Inherited implicits
- Inherited from
- ResourceInstances
- Inherited from
- ResourceInstances
- Inherited from
- ResourceInstances
- Inherited from
- ResourceInstances
- Inherited from
- ResourceInstances
- Inherited from
- ResourceInstances0
- Inherited from
- ResourceInstances0