Hyperlinkv0.8.0-beta.28

Option

Option.getOrThrowconsteffect/Option.ts:1125
<A>(self: Option<A>): A

Extracts the value from a Some, or throws a default Error for None.

When to use

Use when you need quick fail-fast unwrapping of an Option and a generic error is acceptable.

Details

  • Some → returns the inner value
  • None → throws new Error("getOrThrow called on a None")

Example (Throwing a default error)

import { Option } from "effect"

console.log(Option.getOrThrow(Option.some(1)))
// Output: 1

Option.getOrThrow(Option.none())
// throws Error: getOrThrow called on a None
Source effect/Option.ts:11251 lines
export const getOrThrow: <A>(self: Option<A>) => A = getOrThrowWith(() => new Error("getOrThrow called on a None"))
Referenced by 1 symbols