Module maybe

Optional values.

Remarks

Maybe<T> is a type that represents an optional value. It is represented by two variants: Nothing and Just<T>.

  • Nothing is the absent Maybe and contains no value.
  • A Just<T> is a present Maybe and contains a value of type T.

The companion Maybe:namespace namespace provides utilities for working with the Maybe<T> type.

Common uses for Maybe include:

  • Initial values
  • Nullable values
  • Return values for functions that are not defined over their entire input range (partial functions)
  • Return values for reporting simple failures, where Nothing is returned on failure

Using Maybe with promises

AsyncMaybe<T> is an alias for Promise<Maybe<T>>. The companion AsyncMaybe:namespace namespace provides utilities for working with the AsyncMaybe<T> type.

To accommodate promise-like values, this module also provides the AsyncMaybeLike<T> type as an alias for PromiseLike<Maybe<T>>.

Importing from this module

The types and namespaces from this module can be imported under the same aliases:

import { AsyncMaybe, Maybe } from "@neotype/prelude/maybe.js";

Or, they can be imported and aliased separately:

import {
type AsyncMaybe,
type Maybe,
AsyncMaybe as AM,
Maybe as M
} from "@neotype/prelude/maybe.js";

Index

Namespaces

Type Aliases

Generated using TypeDoc