Skip to main content

Built and signed on GitHub Actions

The optional module provides the types `Option<T>` and `Result<T, E>`.

This package works with Bun, Cloudflare Workers, Node.js, Deno, Browsers
JSR Score
100%
Published
4 days ago (0.1.0)

The optional module provides the types Option<T> and Result<T, E>. The functions some, none, and from are provided to create Option<T> instances. The functions ok, err, and from are provided to create Result<T, E> instances.

Basic Usage

import { ok, err, some, none } from "@gnome/optional";

const r = ok(10);
console.log(r.isOk);
console.log(r.isError);

console.log(r.map((v) => v.toString()))

const o1 = none<number>();
console.log(o1.isSome);
console.log(o1.isNone);

const o = some(10);
console.log(o.isSome);
console.log(o.isNone);

Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @gnome/optional

Import symbol

import * as mod from "@gnome/optional";

Add Package

npx jsr add @gnome/optional

Import symbol

import * as mod from "@gnome/optional";

Add Package

yarn dlx jsr add @gnome/optional

Import symbol

import * as mod from "@gnome/optional";

Add Package

pnpm dlx jsr add @gnome/optional

Import symbol

import * as mod from "@gnome/optional";

Add Package

bunx jsr add @gnome/optional

Import symbol

import * as mod from "@gnome/optional";