Cats Effect IO (Scala)
SkillAI & modelsHelps agents write and review Scala Cats Effect IO code. Use for suspending side effects and non-determinism in IO or F[_], choosing Sync/Async/Temporal/Concurrent/Clock/Random, handling blocking I/O, testing with TestControl, and composing resources, fibers, races, and structured concurrency safely.
Available today. Use it from your connected AI after setup.
No other account needed.
Add ahel to your AI once: Claude, ChatGPT, Cursor, Claude Code or Codex. Then ask it to use this.
Then ask your AI: use the Cats Effect IO (Scala) skill
What this skill tells your AI
The instructions your AI receives, as published by alexandru/skills in skills/cats-effect-io/SKILL.md and read by ahel’s review.
Quick start
- Treat every side effect and source of non-determinism as an effect value: return
IO[A],SyncIO[A], orF[A]with the smallest needed Cats Effect capability. - Suspend each side-effectful call, not a precomputed result.
Instant.now(), random/UUID generation, environment reads, and mutable allocation such asnew Array[...]belong insideIO(...),Sync[F].delay,Clock,Random, or an effectful factory. - Initialize shared mutable state through
IO/F/Resourcefactories and pass the resulting reference or service around. Do not hide effects in constructors, top-level vals, or default arguments. - Wrap Java blocking use-phase calls with
IO.interruptibleby default (orSync[F].interruptible); useblockingfor acquisition, finalizers, and operations that must not be interrupted. - Use
Resourceto acquire/release resources andIOAppfor program entry points. - Prefer structured concurrency (
parTraverse,parMapN,background,Supervisor) over manual fiber management. - Do not use
unsafeRun*(unsafeRunSync,unsafeRunAndForget, etc.) in app code or tests; for interop with non-Cats-Effect callback APIs, useDispatcher. - Read
references/cats-effect-io.mdfor concepts, recipes, FAQ guidance, and verified samples. - For deeper
Resourceguidance, use thecats-effect-resourceskill (install:npx skills add https://github.com/alexandru/skills --skill cats-effect-resource).
Workflow
- Identify every side effect and non-deterministic value, including time, random values, mutable allocation, and shared-state reads/writes.
- Choose the effect type: concrete
IOor polymorphicF[_]with the smallest capability (Clock,Random,Sync,Async,Temporal,Concurrent, etc.). - Wrap side-effectful code using
IO(...),IO.interruptible,IO.blocking,IO.async, or the corresponding typeclass operation. - Move initialization of stateful services into
create/resourcefactories returningF[A]orResource[F, A]. - Compose effects with
flatMap/for-comprehensions and collection combinators (traverse,parTraverse). - Use concurrency primitives (
Ref,Deferred,Queue,Semaphore,Supervisor) and structured concurrency to avoid fiber leaks. - Keep effect execution at boundaries (
IOApp, framework runtime); for callback-style interop, bridge withDispatcher.
Side-effect rules (apply to IO, SyncIO, and to F[_]: Sync/Async)
- All side-effectful functions must return results wrapped in
IO(orF[_]with Cats Effect typeclasses/capabilities). - Side effects include all non-determinism (call sites are not referentially transparent):
- Any I/O (files, sockets, console, databases).
Instant.now(),System.currentTimeMillis(),Random.nextInt(),UUID.randomUUID().- Reads from environment variables, system properties, clocks, random sources, or shared mutable state.
- Allocating or returning mutable structures when identity or mutation can escape (
Array,mutable.Map, Java collections,AtomicReference, caches).
- Private local mutation is acceptable only when the whole mutable block is suspended and no mutable value escapes.
Blocking I/O rules
- Prefer
IO.interruptible/Sync[F].interruptiblefor blocking use-phase operations. This gives cancellation a chance to interrupt the underlying thread and is the right default for network/socket-style blocking APIs. - Do not require a proof that every Java API honors interruption before using
interruptible; some APIs still ignore interruption, so add a resource-specific cancellation protocol when cancellation responsiveness matters and testing shows interruption is not enough. - Use
IO.blocking/Sync[F].blockingfor acquisition, cleanup, and disposal (Closeable#close,AutoCloseable#close), where attempted interruption can leave lifecycle state ambiguous.
Output expectations
- Make side effects explicit in signatures (
IO/SyncIOorF[_]: Sync/Async); the guidance here applies equally to concreteIOand polymorphicF[_]. - Use the smallest typeclass constraint that supports the needed operations.
- Keep effects as values; do not execute effects in constructors or top-level vals.
- When adding or changing Scala examples, update and compile the bundled
scripts/verify-examples.scalascript.
Execution and test rules
unsafeRun*is forbidden in production and test code, includingimport cats.effect.unsafe.implicits.global.- If interop requires running effects from non-Cats-Effect callbacks, use
Dispatcher. - Prefer effect-native test styles (return
IO[Assertion]/F[Assertion]) instead of manually running effects. - Avoid
IO.sleep/Thread.sleepin unit tests unless using virtual time withTestControl.
References
- Load
references/cats-effect-io.mdfor documentation summary and patterns. - For concrete samples, read
references/cats-effect-io.md; the representative check isscripts/verify-examples.scala. - Use the
cats-effect-resourceskill for Resource-specific workflows and patterns (install:npx skills add https://github.com/alexandru/skills --skill cats-effect-resource).
Signals
- GitHub stars
- 53
- Forks
- 3
- Last commit
- Sep 2026
Advanced
- Item type
- skill
- Key
cats-effect-io- Source
- github.com/alexandru/skills