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/isOk.md.

isOk

Type guard that narrows a Result to Ok.

if (isOk(result)) {
  // result.value is T
}

Usage

isOk(result)

isOk is how you discriminate a Result in TypeScript — inside the truthy branch, result.value is T; in the falsy branch, result is Err and result.error is Error.

import { attempt, isOk } from 'massaman'

const parsed = attempt(() => JSON.parse(input))
if (isOk(parsed)) {
  console.log(parsed.value) // narrowed to T
} else {
  console.error(parsed.error) // narrowed to Error
}

For pattern matching across both branches, prefer match with P.ok / P.err — it's exhaustive and reads better with multi-arm logic.

Parameters

resultResult<T>required

the result to test.

Returns

true if the result is a success.

result is Ok<T>

See also