Use @gordonb/result — Rust-like Result and Option types for TypeScript. Use when a project imports @gordonb/result, or when the user mentions ok/err results, safeTry, data-last combinators, or bridging Zod safeParse into Results.
Ships in result. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Rust-like Result and Option types for TypeScript. Plain data, pure functions, no wrapper classes.
deno add jsr:@gordonb/result
@gordonb/result — namespace imports (Result, Option)@gordonb/result/result — Result utilities@gordonb/result/option — Option utilities@gordonb/result/result/combinators — data-last Result combinators for piping@gordonb/result/option/combinators — data-last Option combinators for piping@gordonb/result/result/zod — Zod safeParse bridge@gordonb/result/pipe — pipe, flow, pipeAsync, flowAsync (re-exported from
@gordonb/pipe)A Result<T, E> is a discriminated union: Ok<T> | Err<E>.
type Ok<T> = { ok: true; value: T; error?: undefined };
type Err<E> = { ok: false; value?: undefined; error: E };
type Result<T, E> = Ok<T> | Err<E>;
import * as Result from "@gordonb/result/result";
Result.ok(42); // { ok: true, value: 42 }
Result.err("not found"); // { ok: false, error: "not found" }
Result.isOk(result); // result is Ok<T>
Result.isErr(result); // result is Err<E>
Both fields can be destructured directly. The destructured discriminant still narrows:
const { ok, value, error } = result;
if (ok) {
// value narrows from `T | undefined` to `T`
} else {
// error narrows from `E | undefined` to `E`
}
Result.unwrap(result); // returns T or throws TypeError (with error as cause)
Result.unwrapOr(result, defaultValue); // returns T or defaultValue
Result.unwrapOrElse(result, (error) => fallback); // returns T or computes fallback from error
Result.map(result, (value) => newValue); // Ok mapped, Err passes through
Result.mapOr(result, (value) => newValue, defaultValue); // mapped value or default
Result.mapOrElse(result, (value) => newValue, (error) => fallback); // mapped or computed fallback
Result.flatMap(result, (value) => Result.ok(newValue)); // chains Result-returning functions
Result.mapErr(result, (error) => newError); // Err mapped, Ok passes through
Note the argument order: Result.mapOr(result, fn, defaultValue) takes the
function before the default, while Option.mapOr(value, defaultValue, fn)
takes the default before the function.
const parsed = Result.perform(() => JSON.parse(input)); // Result<any, unknown>
const data = await Result.performAsync(() => fetch(url)); // Promise<Result<Response, unknown>>
safeTry and safeTryAsync are aliases for perform and performAsync.
Result.toOption(result); // Ok<T> -> T, Err -> undefined
Result.intoResult(value, error); // Result<Option<T>, E>
// For libraries that return separate value/error (e.g. Supabase)
An Option<T> is T | undefined. Null is not used; use from to coalesce
null.
type Option<T> = T | undefined;
type Nullish<T> = T | null | undefined;
import * as Option from "@gordonb/result/option";
Option.from(value); // coalesces null to undefined
Option.isSome(value); // value is T
Option.isNone(value); // value is undefined
Option.isNullish(value); // value is null | undefined
Option.unwrap(value); // returns T or throws TypeError
Option.unwrapOr(value, defaultValue); // returns T or defaultValue
Option.unwrapOrElse(value, () => fallback); // returns T or computes fallback
Option.map(value, (v) => newValue); // Some mapped, None passes through
Option.mapOr(value, defaultValue, (v) => newValue); // mapped or default
Option.mapOrElse(value, () => fallback, defaultValue); // mapped or fallback
Note: Option.mapOr takes the default before the function — the opposite
order from Result.mapOr.
Curried, data-last versions of Result and Option operations. Designed for use
with pipe and flow. Callbacks passed to combinators need explicit parameter
annotations (e.g. map((x: number) => x + 5)) — inference does not flow through
the curried form.
import * as Result from "@gordonb/result/result";
import { flatMap, map, unwrapOr } from "@gordonb/result/result/combinators";
import { pipe } from "@gordonb/result/pipe";
const result = pipe(
Result.ok(10),
map((x: number) => x + 5),
flatMap((x: number) => x > 10 ? Result.ok(x * 2) : Result.err("too small")),
unwrapOr(0),
);
// 30
Available: map, mapOr, mapOrElse, flatMap, mapErr, unwrapOr,
unwrapOrElse
import * as OC from "@gordonb/result/option/combinators";
import { pipe } from "@gordonb/result/pipe";
const display = pipe(
items[0],
OC.map((s: string) => s.toUpperCase()),
OC.unwrapOr("(empty)"),
);
Available: OC.map, OC.mapOr, OC.mapOrElse, OC.unwrapOr,
OC.unwrapOrElse
Re-exported from @gordonb/pipe.
import { flow, flowAsync, pipe, pipeAsync } from "@gordonb/result/pipe";
pipe(value, fn1, fn2, fn3); // fn3(fn2(fn1(value)))
const transform = flow(fn1, fn2); // (value) => fn2(fn1(value))
await pipeAsync(value, asyncFn1, asyncFn2);
const asyncTransform = flowAsync(asyncFn1, asyncFn2);
Converts Zod's safeParse result into a Result. Structurally typed — no
runtime or type dependency on Zod; any { success, data, error } shape works.
import { z } from "zod";
import { toResult as zodToResult } from "@gordonb/result/result/zod";
const User = z.object({ name: z.string(), age: z.number() });
const result = zodToResult(User.safeParse(input));
// Ok<{ name: string; age: number }> or Err<ZodError>
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
/result:resultfrom result
npx claudepluginhub gordonbrander/result --plugin result