Package: effect
Module: Option
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
Some → returns the inner valueNone → throws the value returned by onNone()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
getOrThrow for a version with a default errorgetOrElse for a non-throwing alternativeSignature
declare const getOrThrowWith: { (onNone: () => unknown): <A>(self: Option<A>) => A; <A>(self: Option<A>, onNone: () => unknown): A; }
Since v2.0.0