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

0.1.7 • Public • Published

Simple Result

npm npm (tag) npm docs

Yet another Result type, inspired by Rust. This type allows you to encode a logical success or failure when it still may be useful to return a value.

For example, in some string parsing situations, it is useful to be able to parse from a list of options. In this case, a success would mean that the parsed string was one of the options, whereas a failure would imply that it wasn't. In this case, the parsed string could still be returned, such as to construct a more specific error message.

This package is part of the mcfunction-langserver project. It is published automatically - see the publishing strategy.

Example

import { Ok, Err, Result } from "simple-result";
import * as assert from "assert";
 
const value = Ok("Hello");
assert(isOk(value));
assert(!isErr(value));
 
function parse_from_option(
    parser: Parser,
    options: string[]
): Result<string, string | undefined>;

/simple-result/

    Package Sidebar

    Install

    npm i simple-result

    Weekly Downloads

    1

    Version

    0.1.7

    License

    MIT

    Unpacked Size

    7.55 kB

    Total Files

    6

    Last publish

    Collaborators

    • levertion