zena:option

zena
import {…} from 'zena:option';

Option type for representing optional values without null.

Option is a union of Some and None. Unlike T | null, Option works for all types including primitives, because Some is always a reference type (it boxes the value).

For performance-critical code where allocation matters, prefer multi-return (T, boolean) patterns instead.

Classes

Some

zena
class Some<T>

Represents a present value.

Constructors
zena
new(value: T)
#
Properties
zena
value: T
#

None

zena
class None

Represents an absent value.

Type aliases

Option

zena
type Option<T> = Some<T> | None

A value that is either present (Some) or absent (None).

Functions

some

zena
function some<T>(value: T): Option<T>

Creates a Some containing the given value.

Variables

none

zena
let none: None

The singleton None instance.