stupid-simple-result
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

ts-stupid-simple-result

Stupid-Simple Result Type in Typescript

Usage

const someAsyncFn = async (): Promise<string> => {
    if (Math.random() > 0.5) {
        throw new Error("Error Happend!!!")
    }
    return "OK"
}

// Somewhere else
import {toOk, toErr} from 'stupid-simple-result';

const doSomthing = async () => {
    const [ok, err] = await someAsyncFn().then(toOk).catch(toErr)
    if (err) { /* Do some error handling */ }
    console.log(ok) // OK
}

import {wrapPromise} from 'stupid-simple-result';
const doAnother = async () => {
    const [ok, err] = await wrapPromise(someAsyncFn())
    if (err) { /* Do some error handling */ }
    console.log(ok) // OK
}

Why?

"Result" in Rust or some other languages that have Functional Features is great.

But sometime, we like more simple solution if it looks like stupid.

Readme

Keywords

none

Package Sidebar

Install

npm i stupid-simple-result

Weekly Downloads

2

Version

1.2.3

License

MIT

Unpacked Size

8.46 kB

Total Files

8

Last publish

Collaborators

  • ppdx999