effect-io-ai

Package: effect
Module: Option

Option.getOrThrowWith

Extracts the value from a Some, or throws a custom error for None.

When to use

Use when you need fail-fast unwrapping of an Option for unexpected absence and want to provide a descriptive debugging error.

Details

Example (Throwing a custom error)

import { Option } from "effect"

console.log(Option.getOrThrowWith(Option.some(1), () => new Error("missing")))
// Output: 1

Option.getOrThrowWith(Option.none(), () => new Error("missing"))
// throws Error: missing

See

Signature

declare const getOrThrowWith: { (onNone: () => unknown): <A>(self: Option<A>) => A; <A>(self: Option<A>, onNone: () => unknown): A; }

Source

Since v2.0.0