<B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<B | A>
<A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>Returns the fallback Option if self is None; otherwise returns self.
When to use
Use when you need a lazy fallback Option, such as when building priority
chains of optional values.
Details
Some→ returnsselfunchangedNone→ evaluates and returnsthat()thatis lazily evaluated
Example (Providing a fallback Option)
import { Option } from "effect"
console.log(Option.none().pipe(Option.orElse(() => Option.some("b"))))
// Output: { _id: 'Option', _tag: 'Some', value: 'b' }
console.log(Option.some("a").pipe(Option.orElse(() => Option.some("b"))))
// Output: { _id: 'Option', _tag: 'Some', value: 'a' }export const const orElse: {
<B>(that: LazyArg<Option<B>>): <A>(
self: Option<A>
) => Option<B | A>
<A, B>(
self: Option<A>,
that: LazyArg<Option<B>>
): Option<A | B>
}
Returns the fallback Option if self is None; otherwise returns self.
When to use
Use when you need a lazy fallback Option, such as when building priority
chains of optional values.
Details
Some → returns self unchanged
None → evaluates and returns that()
that is lazily evaluated
Example (Providing a fallback Option)
import { Option } from "effect"
console.log(Option.none().pipe(Option.orElse(() => Option.some("b"))))
// Output: { _id: 'Option', _tag: 'Some', value: 'b' }
console.log(Option.some("a").pipe(Option.orElse(() => Option.some("b"))))
// Output: { _id: 'Option', _tag: 'Some', value: 'a' }
orElse: {
<function (type parameter) B in <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<B | A>B>(that: LazyArg<Option<B>>that: import LazyArgLazyArg<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) B in <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<B | A>B>>): <function (type parameter) A in <A>(self: Option<A>): Option<B | A>A>(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>): Option<B | A>A>) => 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) B in <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<B | A>B | function (type parameter) A in <A>(self: Option<A>): Option<B | A>A>
<function (type parameter) A in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>A, function (type parameter) B in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>B>(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>, that: LazyArg<Option<B>>): Option<A | B>A>, that: LazyArg<Option<B>>that: import LazyArgLazyArg<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) B in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>B>>): 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>, that: LazyArg<Option<B>>): Option<A | B>A | function (type parameter) B in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>B>
} = import dualdual(
2,
<function (type parameter) A in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>A, function (type parameter) B in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>B>(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>, that: LazyArg<Option<B>>): Option<A | B>A>, that: LazyArg<Option<B>>that: import LazyArgLazyArg<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) B in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>B>>): 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>, that: LazyArg<Option<B>>): Option<A | B>A | function (type parameter) B in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>B> => 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) ? that: LazyArg<Option<B>>that() : 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
)