<A>(self: Option<A>): AExtracts 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 valueNone→ throwsnew 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 NoneSource effect/Option.ts:11251 lines
export const const getOrThrow: <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
getOrThrow: <function (type parameter) A in <A>(self: Option<A>): AA>(self: Option<A>self: type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) A in <A>(self: Option<A>): AA>) => function (type parameter) A in <A>(self: Option<A>): AA = const getOrThrowWith: {
(onNone: () => unknown): <A>(
self: Option<A>
) => A
<A>(self: Option<A>, onNone: () => unknown): A
}
getOrThrowWith(() => new var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error("getOrThrow called on a None"))Referenced by 1 symbols