For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /index.md.

Make absence
explicit.

An Option type for values that may not exist.

npm install byenull
import { Option } from "byenull";

// A lookup may not return a value
const findUser = Option.fn((id: string) =>
  users.find((user) => user.id === id),
);

const name = Option.pipe(
  findUser("u1"),
  Option.map((user) => user.name),
  Option.unwrap("Anonymous"),
);
THE BASICS01 / OPTION

Values may be missing.
Make that visible.

An Option is either Some, containing a value, or None. Transform the value when it exists; let absence pass through when it doesn’t.

{ }

Plain objects

Options are data, not class instances. Inspect, serialize, and pass them around like ordinary JavaScript objects.

{ type: "Some", value: 42 }
>_

Composable operations

Use map, andThen, and orElse in a pipeline. A None skips the remaining value transformations.

Explore pipelines
~

Sync and async

Use the same operations with Options and promises of Options. Await the result when your pipeline is asynchronous.

How async works
INTEROPERABILITY02 / RESULT

A companion to byethrow.

byenull follows the API design of byethrow and provides conversions between Option and Result. The libraries have different authors; byenull is independently maintained and works on its own.

Read the conversion guide
byenullOption<T>presence / absence
toResult(error)
──────────────
fromResult
byethrowResult<T, E>success / failure

Start with an Option.

Install the package, then follow the guide to your first pipeline.