<B, A, C = B>(options: {
readonly onNone: LazyArg<B>
readonly onSome: (a: A) => C
}): (self: Option<A>) => B | C
<A, B, C = B>(
self: Option<A>,
options: { readonly onNone: LazyArg<B>; readonly onSome: (a: A) => C }
): B | CPattern-matches on an Option, handling both None and Some cases.
When to use
Use when you need to handle both Some and None in one expression and
transform an Option into a plain value.
Details
- If
None, callsonNoneand returns its result - If
Some, callsonSomewith the value and returns its result - Supports the
dualAPI (data-last and data-first)
Example (Matching on an Option)
import { Option } from "effect"
const message = Option.match(Option.some(1), {
onNone: () => "Option is empty",
onSome: (value) => `Option has a value: ${value}`
})
console.log(message)
// Output: "Option has a value: 1"export const const match: {
<B, A, C = B>(options: {
readonly onNone: LazyArg<B>
readonly onSome: (a: A) => C
}): (self: Option<A>) => B | C
<A, B, C = B>(
self: Option<A>,
options: {
readonly onNone: LazyArg<B>
readonly onSome: (a: A) => C
}
): B | C
}
Pattern-matches on an Option, handling both None and Some cases.
When to use
Use when you need to handle both Some and None in one expression and
transform an Option into a plain value.
Details
- If
None, calls onNone and returns its result
- If
Some, calls onSome with the value and returns its result
- Supports the
dual API (data-last and data-first)
Example (Matching on an Option)
import { Option } from "effect"
const message = Option.match(Option.some(1), {
onNone: () => "Option is empty",
onSome: (value) => `Option has a value: ${value}`
})
console.log(message)
// Output: "Option has a value: 1"
match: {
<function (type parameter) B in <B, A, C = B>(options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): (self: Option<A>) => B | C
B, function (type parameter) A in <B, A, C = B>(options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): (self: Option<A>) => B | C
A, function (type parameter) C in <B, A, C = B>(options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): (self: Option<A>) => B | C
C = function (type parameter) B in <B, A, C = B>(options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): (self: Option<A>) => B | C
B>(options: {
readonly onNone: LazyArg<B>
readonly onSome: (a: A) => C
}
options: {
readonly onNone: LazyArg<B>onNone: import LazyArgLazyArg<function (type parameter) B in <B, A, C = B>(options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): (self: Option<A>) => B | C
B>
readonly onSome: (a: A) => ConSome: (a: Aa: function (type parameter) A in <B, A, C = B>(options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): (self: Option<A>) => B | C
A) => function (type parameter) C in <B, A, C = B>(options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): (self: Option<A>) => B | C
C
}): (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 <B, A, C = B>(options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): (self: Option<A>) => B | C
A>) => function (type parameter) B in <B, A, C = B>(options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): (self: Option<A>) => B | C
B | function (type parameter) C in <B, A, C = B>(options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): (self: Option<A>) => B | C
C
<function (type parameter) A in <A, B, C = B>(self: Option<A>, options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
A, function (type parameter) B in <A, B, C = B>(self: Option<A>, options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
B, function (type parameter) C in <A, B, C = B>(self: Option<A>, options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
C = function (type parameter) B in <A, B, C = B>(self: Option<A>, options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
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, C = B>(self: Option<A>, options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
A>, options: {
readonly onNone: LazyArg<B>
readonly onSome: (a: A) => C
}
options: {
readonly onNone: LazyArg<B>onNone: import LazyArgLazyArg<function (type parameter) B in <A, B, C = B>(self: Option<A>, options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
B>
readonly onSome: (a: A) => ConSome: (a: Aa: function (type parameter) A in <A, B, C = B>(self: Option<A>, options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
A) => function (type parameter) C in <A, B, C = B>(self: Option<A>, options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
C
}): function (type parameter) B in <A, B, C = B>(self: Option<A>, options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
B | function (type parameter) C in <A, B, C = B>(self: Option<A>, options: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
C
} = import dualdual(
2,
<function (type parameter) A in <A, B, C = B>(self: Option<A>, { onNone, onSome }: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
A, function (type parameter) B in <A, B, C = B>(self: Option<A>, { onNone, onSome }: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
B, function (type parameter) C in <A, B, C = B>(self: Option<A>, { onNone, onSome }: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
C = function (type parameter) B in <A, B, C = B>(self: Option<A>, { onNone, onSome }: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
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, C = B>(self: Option<A>, { onNone, onSome }: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
A>, { onNone: LazyArg<B>onNone, onSome: (a: A) => ConSome }: {
readonly onNone: LazyArg<B>onNone: import LazyArgLazyArg<function (type parameter) B in <A, B, C = B>(self: Option<A>, { onNone, onSome }: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
B>
readonly onSome: (a: A) => ConSome: (a: Aa: function (type parameter) A in <A, B, C = B>(self: Option<A>, { onNone, onSome }: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
A) => function (type parameter) C in <A, B, C = B>(self: Option<A>, { onNone, onSome }: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
C
}): function (type parameter) B in <A, B, C = B>(self: Option<A>, { onNone, onSome }: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
B | function (type parameter) C in <A, B, C = B>(self: Option<A>, { onNone, onSome }: {
readonly onNone: LazyArg<B>;
readonly onSome: (a: A) => C;
}): B | C
C => 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() : onSome: (a: A) => ConSome(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)
)