0.1.3 • Published 4 months ago

@soulwallet_test/result v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

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