monad-result
Installation
SKILL.md
Result Monad
Installation: If not already installed, add the package with pnpm add @efesto-cloud/result.
Use this skill to keep Result<T, E> usage consistent across the project.
Core Rules
- Create success with
Result.ok(value). - Create failure with
Result.err(error). - Check outcome with
result.isFailure()orresult.isSuccess(). - Throw only when explicitly desired with
result.unwrapOrThrow(). - For fallback values, use
result.else(() => fallback). - Execute side effects with
result.run(fn)— runsfnon success data, no-op on failure. - Serialize to plain object with
result.toObject()— returnsISuccess<T> | IFailure<E>. - Deserialize with
Result.fromObject(obj)— reconstructs from a plainIResult<T, E>object. - Integrate Zod validation with
Result.fromZod(zodParseResult)— convertsSafeParseReturnTypetoResult.