What problem does it solve?
Many business operations fail for expected reasons such as validation errors, missing resources, or authorization checks and these failures are often represented as thrown exceptions that are hard to handle predictably across layers. The Result pattern makes those outcomes explicit by returning a value that encodes success or failure so callers must handle each path.
Core Features & Use Cases
- Explicit error returns: Service methods return a Result type instead of throwing for expected business errors, making error paths visible in the type system.
- Composable pipelines: map and flatMap allow chaining multiple fallible operations while propagating the first failure.
- Layer integration: Controllers map Result failures to appropriate HTTP status codes and frontend hooks consume typed error codes to drive UI states.
- Use Case: Validate request payloads in the service, return Result.fail for validation issues, and let the controller convert those failures into 400/404/409 responses.
Quick Start
Use the result-pattern skill to implement a Result<T> return type in a service, chain validations with flatMap, and map failures to HTTP responses in your controller.