@qlever-llc/trellis-result
v0.5.1
Published
Class-based Result and AsyncResult types for Trellis TypeScript applications.
Downloads
263
Readme
@qlever-llc/trellis-result
Class-based Result<T, E> and AsyncResult<T, E> types for TypeScript, inspired by Rust.
Provides explicit error handling with method chaining and the take() pattern for early returns, without relying on exceptions.
import { Result, AsyncResult } from "@qlever-llc/trellis-result";
const user = await fetchUser(id).take();
if (Result.isErr(user)) return user;Key surface area:
Result.ok(value)/Result.err(error)— constructionResult.try(() => ...)/AsyncResult.try(async () => ...)— wrap throwing code.map(),.mapErr(),.andThen()— transforms.take()— early return pattern (Rust's?operator equivalent).match({ ok, err })— pattern matchingResult.all()/Result.any()— combinatorsMaybeAsync<T, E>— flexible sync/async return typeBaseError— base class for all Trellis error types
See the source and inline JSDoc for full API details.
