@soulwallet/result
v0.2.1
Published
A lib designed based on the philosophy of 'Errors are values'
Downloads
19
Readme
Table of Contents
Installing
Using npm:
$ npm install @soulwallet/result
Using yarn:
$ yarn add @soulwallet/result
Using pnpm:
$ pnpm add @soulwallet/result
Once the package is installed, you can import the library using import
approach:
import { Result, Ok, Err } from '@soulwallet/result'
Example
import { Result, Ok, Err } from '@soulwallet/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