Arrow Resource (Kotlin)
Quick start
- Use
resourceScope { ... }at lifecycle boundaries. - Define each resource with
resource { install(acquire) { a, exitCase -> release } }. - Compose with
.bind(); useparZipfor independent parallel acquisition. - Read
references/resource.mdfor patterns and concrete examples.
Workflow
- Identify the acquire step and the release step.
- Implement a
Resource<A>usinginstall. - Create reusable constructors on
ResourceScopewhen needed. - Compose resources into higher-level resources with
.bind(). - Execute in
resourceScopeand keep finalizers idempotent.
Usage guidance
- Prefer Resource over
use/try/finallywhen you need suspend finalizers or MPP support. - Use
ExitCaseto handle rollback/cleanup differences. - When mixing with typed errors, pick nesting order deliberately to control
ExitCaseseen by finalizers.
References
- Load
references/resource.mdfor API details and end-to-end examples.