Plain objects
Options are data, not class instances. Inspect, serialize, and pass them around like ordinary JavaScript objects.
{ type: "Some", value: 42 }An Option type for values that may not exist.
npm install byenullimport { 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"),
);An Option is either Some, containing a value, or None. Transform the value when it exists; let absence pass through when it doesn’t.
Options are data, not class instances. Inspect, serialize, and pass them around like ordinary JavaScript objects.
{ type: "Some", value: 42 }Use map, andThen, and orElse in a pipeline. A None skips the remaining value transformations.
Use the same operations with Options and promises of Options. Await the result when your pipeline is asynchronous.
How async worksbyenull 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 guidetoResult(error)fromResultInstall the package, then follow the guide to your first pipeline.