Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Err.from #21

Open
rjkz808 opened this issue Mar 28, 2021 · 1 comment
Open

Adding Err.from #21

rjkz808 opened this issue Mar 28, 2021 · 1 comment

Comments

@rjkz808
Copy link

rjkz808 commented Mar 28, 2021

In my opinion, typing new Err(new Error('...')) or even Err(new Error('...')) feels kinda wrong and self-repetitive. Maybe it'll be a good idea to add a simple static method like this:

export class ErrImpl<E> implements BaseResult<never, E> {
    // ...

    static from(message: string): ErrImpl<Error> {
        return new Err(new Error(message));
    }
}

This will help everyone to reduce the amount of boilerplate code

function run(): Result<void, Error> {
    return Err.from('...');
}
@Jack-Works
Copy link
Contributor

It's better named as Err.of

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants