For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/control/ok.md.

ok

Constructs a success Result.

const result = ok(value)

Usage

ok(value)

Use ok when you want to return a Result directly without going through attempt. Common in validation functions, parsers, or any code that wants to return a Result as its native shape.

import { ok, err, type Result } from 'massaman'

function divide(a: number, b: number): Result<number> {
  if (b === 0) return err('division by zero')
  return ok(a / b)
}

Parameters

valueTrequired

the success value. Can be null, undefined, or any other type — the ok: true discriminant determines success, not the value's truthiness.

Returns

{ ok: true, value, error: null }.

Ok<T>

See also