cats-effect-resource

Installation
SKILL.md

Cats Effect Resource (Scala)

Quick start

  • Model every owned disposable value with Resource.make, Resource.makeCase, or Resource.fromAutoCloseable.
  • Never return an acquired handle from .use; it is released when .use completes. Return only values computed inside the scope.
  • Classes must not allocate owned resources in constructors, fields, or top-level vals. Use companion/factory methods returning Resource[F, Service], then pass acquired private dependencies into constructors.
  • Wrap Java AutoCloseable values with Resource.fromAutoCloseable(Sync[F].blocking(...)) or IO.blocking(...).
  • Compose resources with flatMap, mapN, parMapN, or helper constructors; expose Resource[F, A] from lifecycle-owning APIs.
  • Read references/resource.md for patterns, best practices, and type-checked samples.

Workflow

  1. Identify every value that needs disposal or lifecycle shutdown.
  2. Move acquisition and release into a Resource[F, A]; suspend side effects in F (Sync[F].delay/blocking, IO.blocking, etc.).
  3. Build classes from already-acquired constructor parameters; put construction in resource/create factories that return Resource.
  4. Compose lower-level resources into higher-level resources before .use.
  5. Run with .use at the lifecycle boundary (IOApp, server startup, test fixture), and keep raw handles inside the use scope.
  6. Use allocated only for interop that truly needs separate acquire/release, and guarantee the finalizer is called exactly once.
Installs
56
GitHub Stars
49
First Seen
Feb 3, 2026
cats-effect-resource — alexandru/skills