@lucid-softworks/result
v0.1.0
Published
A small, dependency-free Result type for explicit success and failure.
Downloads
329
Maintainers
Readme
@lucid-softworks/result
A small discriminated-union Result for APIs where failure should be explicit.
There are no classes and no dependencies.
import { andThen, err, map, ok, unwrapOr } from "@lucid-softworks/result";
const parsePort = (input: string) => {
const value = Number(input);
return Number.isInteger(value) ? ok(value) : err("Invalid port");
};
const result = map(parsePort("3000"), (port) => port + 1);
unwrapOr(result, 8080); // 3001API
- Constructors and guards:
ok,err,isOk,isErr - Transformations:
map,mapError,andThen - Consumption:
match,unwrap,unwrapOr
