Skip to main content
Module

x/ahh/src/option.ts

Opinionated idiomatic features for TypeScript.
Go to Latest
import * as ahh from "https://deno.land/x/ahh@v0.12.1/src/option.ts";

Contains an idiomatic Option type and related functions.

The types and functions provided in this module likely follow how you already handle optional values yourself. A quick look at what the Option type boils down to shows how simple it is:

type Option<T> = (undefined | null) | T;

Almost all built-in and external modules handle the none side as undefined or null, and the some side as the value itself. This is exactly the same as what the type above defines.

Since optionals are not special, we still have access to the features built into the language, such as:

This module simply provides extra functionality on-top of these.

Functions

Returns option if fn returns true and it is a Some.

Returns whether option is a None.

Returns whether option is a Some.

Returns option with its value mapped via fn, if it is a Some.

Type Aliases

A value that is either undefined or null.

A value that is either Some or None.

A value this is neither undefined nor null.