(onNone: () => unknown): <A>(self: Option<A>) => A
<A>(self: Option<A>, onNone: () => unknown): AExtracts 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 byonNone()
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: missingexport const const getOrThrowWith: {
(onNone: () => unknown): <A>(
self: Option<A>
) => A
<A>(self: Option<A>, onNone: () => unknown): A
}
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 value
None → 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
getOrThrowWith: {
(onNone: () => unknownonNone: () => unknown): <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
<function (type parameter) A in <A>(self: Option<A>, onNone: () => unknown): 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>, onNone: () => unknown): AA>, onNone: () => unknownonNone: () => unknown): function (type parameter) A in <A>(self: Option<A>, onNone: () => unknown): AA
} = import dualdual(2, <function (type parameter) A in <A>(self: Option<A>, onNone: () => unknown): 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>, onNone: () => unknown): AA>, onNone: () => unknownonNone: () => unknown): function (type parameter) A in <A>(self: Option<A>, onNone: () => unknown): AA => {
if (const isSome: <A>(
self: Option<A>
) => self is Some<A>
Checks whether an Option contains a value (Some).
When to use
Use when you need to branch on a present Option before accessing .value.
Details
- Acts as a type guard, narrowing to
Some<A>
Example (Checking for Some)
import { Option } from "effect"
console.log(Option.isSome(Option.some(1)))
// Output: true
console.log(Option.isSome(Option.none()))
// Output: false
isSome(self: Option<A>self)) {
return self: Option<A>(parameter) self: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self.Some<A>.value: Avalue
}
throw onNone: () => unknownonNone()
})