@lucid-softworks/try-result
v0.1.0
Published
Capture a synchronous thrown value in a Result.
Downloads
160
Maintainers
Readme
@lucid-softworks/try-result
Adapt a synchronous throwing API to @lucid-softworks/result.
import { tryResult } from "@lucid-softworks/try-result";
const parsed = tryResult(
() => JSON.parse(input) as unknown,
(cause) => ({ type: "invalid-json" as const, cause }),
);Successful return values become Ok. Thrown values become Err unchanged,
unless an error mapper is supplied. Promises are intentionally out of scope;
use a separate asynchronous adapter so rejection semantics stay explicit.
