Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@unthrown/boxed

Boxed interop for unthrown's Result.

📖 Documentation · API Reference

pnpm add @unthrown/boxed @bloodyowl/boxed

Boxed's Result has two channels (Ok/Error) and no defect channel. Coming in, every Boxed result is an Ok or Error — never a Defect. Going out, a Defect has nowhere to live, so toBoxed forces you to triage it with onDefect — no defect is ever silently folded into your domain error type.

import { Ok } from "unthrown";
import { toBoxed, fromBoxed } from "@unthrown/boxed";
import { Result } from "@bloodyowl/boxed";

toBoxed(Ok(1), (cause) => ({ _tag: "Bug", cause })); // Result.Ok(1)
fromBoxed(Result.Ok(1)); // Result<number, never>
  • toBoxed(r, onDefect) / fromBoxed(r) — sync Result ↔ Result.
  • toBoxedFuture(ar, onDefect) / fromBoxedFuture(future) — async AsyncResult ↔ Future<Result>.

Boxed's Option has no analogue here — per unthrown's design, absence is expressed with T | undefined or Result<T, NotFound> (see fromNullable), not a dedicated Option type.

@bloodyowl/boxed is a peer dependency. (Boxed was formerly published as @swan-io/boxed, now deprecated in favour of this maintained scope.)

License

MIT © Benoit TRAVERS