Skip to content

std-core

Option and Result, the canonical optional/error types.

Types

Option

type Option<T> = Some(T) | None

Some(value) — an optional value is present.

Result

type Result<T, E> = Ok(T) | Err(E)

Ok(value) or Err(error) — explicit success/failure without exceptions.

Functions

some

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

Wrap value in Some.

isSome

function isSome<T>(o: Option<T>): boolean

Return true when the option is Some.

unwrapOr

function unwrapOr<T>(o: Option<T>, fallback: T): T

Return value from Some, or fallback for None.

ok

function ok<T, E>(value: T): Result<T, E>

Construct Ok(value).

err

function err<T, E>(error: E): Result<T, E>

Construct Err(error).

isOk

function isOk<T, E>(r: Result<T, E>): boolean

resultOr

function resultOr<T, E>(r: Result<T, E>, fallback: T): T
Documentation