cats-effect-resource
Cats Effect Resource (Scala)
Quick start
- Model each resource with
Resource.makeorResource.fromAutoCloseableand keep release idempotent. - Compose resources with
flatMap,mapN,parMapN, or helper constructors; exposeResource[F, A]from APIs. - Use
Resourceat lifecycle boundaries and call.useonly at the program edges. - Read
references/resource.mdfor patterns, best practices, and API notes.
Workflow
- Identify acquisition, use, and release steps; decide if acquisition is blocking.
- Implement a
Resource[F, A]constructor using the smallest needed typeclass. - Compose resources into higher-level resources and keep finalizers minimal.
- Decide how cancelation and errors should influence release logic.
- Run with
.useat the boundary (IOApp, service startup) and avoid leaking rawA.
Usage guidance
- Prefer
Resourceovertry/finallyorbracketwhen composition and cancelation safety matter. - Use
IO.blocking(orSync[F].blocking) for acquisition and release when calling blocking JVM APIs. - For background fibers, use
ResourceorSupervisorto ensure cleanup on cancelation.
References
- Load
references/resource.mdfor API details, patterns, and examples. - For Kotlin/Arrow parallels, see the
arrow-resourceskill. - Install this skill with
npx skills add https://github.com/alexandru/skills --skill cats-effect-resource.
More from alexandru/skills
cats-effect-io
Scala functional programming with Cats Effect IO and typeclasses. Use for wrapping side effects, modeling purity, choosing Sync/Async/Temporal/Concurrent, handling blocking I/O, and composing resources, fibers, and concurrency safely.
39cats-mtl-typed-errors
Scala typed errors with Cats MTL Raise/Handle and allow/rescue. Use for designing custom domain error types without EitherT, while keeping Cats Effect and ecosystem composition. Covers Scala 2/3 syntax and IO-only or F[_] usage.
23akka-streams
Scala reactive streaming with Akka Streams and Pekko Streams. Use for dataflow and reactive programming patterns, testing stream components, and understanding when NOT to use streams (prefer plain functions for transformations and I/O).
20arrow-typed-errors
Kotlin + Arrow typed error handling using Raise DSL and wrapper types (Either/Option/Ior/Result/nullable), including validation with accumulation, interop with exceptions, and custom error wrappers. Use for designing or refactoring error modeling, converting exception-based flows, building smart constructors, accumulating validation errors, or integrating Outcome/Progress-style wrappers with Arrow.
16kotlin-java-library
Kotlin design for Java libraries and Java consumers. Use when building Kotlin code intended for Java callers, aligning with Java interop, JVM annotations, records, and backward/binary compatibility rules.
14jspecify-nullness
JSpecify nullness annotations for Java APIs and tooling. Use when adopting or migrating JSpecify annotations, designing null-safe Java signatures and generics, or interpreting tool conformance and Kotlin interop.
13