<A>(self: Option<A>): A | nullExtracts the value from a Some, or returns null for None.
When to use
Use when you need to pass absent Option values to APIs that expect null.
Details
Some→ the inner valueNone→null
Example (Unwrapping to null)
import { Option } from "effect"
console.log(Option.getOrNull(Option.some(1)))
// Output: 1
console.log(Option.getOrNull(Option.none()))
// Output: nullSource effect/Option.ts:9761 lines
export const const getOrNull: <A>(
self: Option<A>
) => A | null
Extracts the value from a Some, or returns null for None.
When to use
Use when you need to pass absent Option values to APIs that expect null.
Details
Some → the inner value
None → null
Example (Unwrapping to null)
import { Option } from "effect"
console.log(Option.getOrNull(Option.some(1)))
// Output: 1
console.log(Option.getOrNull(Option.none()))
// Output: null
getOrNull: <function (type parameter) A in <A>(self: Option<A>): A | nullA>(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>): A | nullA>) => function (type parameter) A in <A>(self: Option<A>): A | nullA | null = const getOrElse: {
<B>(onNone: LazyArg<B>): <A>(
self: Option<A>
) => B | A
<A, B>(self: Option<A>, onNone: LazyArg<B>):
| A
| B
}
getOrElse(import constNullconstNull)Referenced by 2 symbols