<B>(onNone: LazyArg<B>): <A>(self: Option<A>) => B | A
<A, B>(self: Option<A>, onNone: LazyArg<B>): A | BExtracts the value from a Some, or evaluates a fallback thunk on None.
When to use
Use when providing a default value for an absent Option
- Unwrapping with lazy evaluation of the fallback
Details
Some→ returns the inner valueNone→ callsonNone()and returns its resultonNoneis only called when needed (lazy)
Example (Unwrapping with a fallback)
import { Option } from "effect"
console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))
// Output: 1
console.log(Option.none().pipe(Option.getOrElse(() => 0)))
// Output: 0export const const getOrElse: {
<B>(onNone: LazyArg<B>): <A>(
self: Option<A>
) => B | A
<A, B>(self: Option<A>, onNone: LazyArg<B>):
| A
| B
}
Extracts the value from a Some, or evaluates a fallback thunk on None.
When to use
Use when providing a default value for an absent Option
- Unwrapping with lazy evaluation of the fallback
Details
Some → returns the inner value
None → calls onNone() and returns its result
onNone is only called when needed (lazy)
Example (Unwrapping with a fallback)
import { Option } from "effect"
console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))
// Output: 1
console.log(Option.none().pipe(Option.getOrElse(() => 0)))
// Output: 0
getOrElse: {
<function (type parameter) B in <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => B | AB>(onNone: LazyArg<B>onNone: import LazyArgLazyArg<function (type parameter) B in <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => B | AB>): <function (type parameter) A in <A>(self: Option<A>): B | 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>): B | AA>) => function (type parameter) B in <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => B | AB | function (type parameter) A in <A>(self: Option<A>): B | AA
<function (type parameter) A in <A, B>(self: Option<A>, onNone: LazyArg<B>): A | BA, function (type parameter) B in <A, B>(self: Option<A>, onNone: LazyArg<B>): A | BB>(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, B>(self: Option<A>, onNone: LazyArg<B>): A | BA>, onNone: LazyArg<B>onNone: import LazyArgLazyArg<function (type parameter) B in <A, B>(self: Option<A>, onNone: LazyArg<B>): A | BB>): function (type parameter) A in <A, B>(self: Option<A>, onNone: LazyArg<B>): A | BA | function (type parameter) B in <A, B>(self: Option<A>, onNone: LazyArg<B>): A | BB
} = import dualdual(
2,
<function (type parameter) A in <A, B>(self: Option<A>, onNone: LazyArg<B>): A | BA, function (type parameter) B in <A, B>(self: Option<A>, onNone: LazyArg<B>): A | BB>(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, B>(self: Option<A>, onNone: LazyArg<B>): A | BA>, onNone: LazyArg<B>onNone: import LazyArgLazyArg<function (type parameter) B in <A, B>(self: Option<A>, onNone: LazyArg<B>): A | BB>): function (type parameter) A in <A, B>(self: Option<A>, onNone: LazyArg<B>): A | BA | function (type parameter) B in <A, B>(self: Option<A>, onNone: LazyArg<B>): A | BB => const isNone: <A>(
self: Option<A>
) => self is None<A>
Checks whether an Option is None (absent).
When to use
Use when you need to branch on an absent Option before accessing .value.
Details
- Acts as a type guard, narrowing to
None<A>
Example (Checking for None)
import { Option } from "effect"
console.log(Option.isNone(Option.some(1)))
// Output: false
console.log(Option.isNone(Option.none()))
// Output: true
isNone(self: Option<A>self) ? onNone: LazyArg<B>onNone() : 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
)