@elytro/result
v1.0.0
Published
A lib designed based on the philosophy of 'Errors are values'
Downloads
16
Readme
Table of Contents
Installing
Using npm:
$ npm install @elytro/result
Using yarn:
$ yarn add @elytro/result
Using pnpm:
$ pnpm add @elytro/result
Once the package is installed, you can import the library using import
approach:
import { Result, Ok, Err } from '@elytro/result'
Example
import { Result, Ok, Err } from '@elytro/result'
async function div(a: number, b: number): Promise<Result<number, Error>> {
if (b === 0) {
return new Err(new Error('Division by zero'));
}
return new Ok(a / b);
}
async function test() {
const result = await div(10, 2);
if (result.isErr()) {
console.log(`error: ${result.ERR.message}`);
} else {
console.log(`result: ${result.OK}`);
}
}
License
ISC