<A>(self: Option<A>, collection: Iterable<Option<A>>): Option<
[A, ...Array<A>]
>Combines a primary Option with an iterable of Options into a tuple if
all are Some.
When to use
Use when you need several Option values of the same type to all be Some
and return them as a non-empty tuple.
Details
- All
Some→Some([self.value, ...rest]) - Any
None→None
Example (Combining many Options)
import { Option } from "effect"
const first = Option.some(1)
const rest = [Option.some(2), Option.some(3)]
console.log(Option.productMany(first, rest))
// Output: { _id: 'Option', _tag: 'Some', value: [1, 2, 3] }
console.log(Option.productMany(first, [Option.some(2), Option.none()]))
// Output: { _id: 'Option', _tag: 'None' }export const const productMany: <A>(
self: Option<A>,
collection: Iterable<Option<A>>
) => Option<[A, ...Array<A>]>
Combines a primary Option with an iterable of Options into a tuple if
all are Some.
When to use
Use when you need several Option values of the same type to all be Some
and return them as a non-empty tuple.
Details
- All
Some → Some([self.value, ...rest])
- Any
None → None
Example (Combining many Options)
import { Option } from "effect"
const first = Option.some(1)
const rest = [Option.some(2), Option.some(3)]
console.log(Option.productMany(first, rest))
// Output: { _id: 'Option', _tag: 'Some', value: [1, 2, 3] }
console.log(Option.productMany(first, [Option.some(2), Option.none()]))
// Output: { _id: 'Option', _tag: 'None' }
productMany = <function (type parameter) A in <A>(self: Option<A>, collection: Iterable<Option<A>>): Option<[A, ...Array<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>, collection: Iterable<Option<A>>): Option<[A, ...Array<A>]>A>,
collection: Iterable<Option<A>>collection: interface Iterable<T, TReturn = any, TNext = any>Iterable<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>, collection: Iterable<Option<A>>): Option<[A, ...Array<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) A in <A>(self: Option<A>, collection: Iterable<Option<A>>): Option<[A, ...Array<A>]>A, ...interface Array<T>Array<function (type parameter) A in <A>(self: Option<A>, collection: Iterable<Option<A>>): Option<[A, ...Array<A>]>A>]> => {
if (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)) {
return const none: <A = never>() => Option<A>Creates an Option representing the absence of a value.
When to use
Use to represent a missing or uninitialized value, such as returning "no
result" from a function.
Details
- Returns
Option<never>, which is a subtype of Option<A> for any A
- Always returns the same singleton instance
Example (Creating an empty Option)
import { Option } from "effect"
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }
none()
}
const const out: [A, ...A[]]const out: {
0: A;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => A | undefined;
push: (...items: Array<A>) => number;
concat: { (...items: Array<ConcatArray<A>>): Array<A>; (...items: Array<A | ConcatArray<A>>): Array<A> };
join: (separator?: string) => string;
reverse: () => Array<A>;
shift: () => A | undefined;
slice: (start?: number, end?: number) => Array<A>;
sort: (compareFn?: ((a: A, b: A) => number) | undefined) => [A, ...A[]];
splice: { (start: number, deleteCount?: number): Array<A>; (start: number, deleteCount: number, ...items: Array<A>): Array<A> };
unshift: (...items: Array<A>) => number;
indexOf: (searchElement: A, fromIndex?: number) => number;
lastIndexOf: (searchElement: A, fromIndex?: number) => number;
every: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): this is S[]; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: A, index: number, array: Array<A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: A, index: number, array: Array<A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): Array<A> };
reduce: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A, initialValue: A): A; (callbackfn: (previousVa…;
reduceRight: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A, initialValue: A): A; (callbackfn: (previousVa…;
find: { (predicate: (value: A, index: number, obj: Array<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, obj: Array<A>) => unknown, thisArg?: any): A | undefined };
findIndex: (predicate: (value: A, index: number, obj: Array<A>) => unknown, thisArg?: any) => number;
fill: (value: A, start?: number, end?: number) => [A, ...A[]];
copyWithin: (target: number, start: number, end?: number) => [A, ...A[]];
entries: () => ArrayIterator<[number, A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<A>;
includes: (searchElement: A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: A, index: number, array: Array<A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => A | undefined;
findLast: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): A | undefined };
findLastIndex: (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<A>;
toSorted: (compareFn?: ((a: A, b: A) => number) | undefined) => Array<A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<A>): Array<A>; (start: number, deleteCount?: number): Array<A> };
with: (index: number, value: A) => Array<A>;
}
out: [function (type parameter) A in <A>(self: Option<A>, collection: Iterable<Option<A>>): Option<[A, ...Array<A>]>A, ...interface Array<T>Array<function (type parameter) A in <A>(self: Option<A>, collection: Iterable<Option<A>>): Option<[A, ...Array<A>]>A>] = [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]
for (const const o: Option<A>o of collection: Iterable<Option<A>>collection) {
if (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(const o: Option<A>o)) {
return const none: <A = never>() => Option<A>Creates an Option representing the absence of a value.
When to use
Use to represent a missing or uninitialized value, such as returning "no
result" from a function.
Details
- Returns
Option<never>, which is a subtype of Option<A> for any A
- Always returns the same singleton instance
Example (Creating an empty Option)
import { Option } from "effect"
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }
none()
}
const out: [A, ...A[]]const out: {
0: A;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => A | undefined;
push: (...items: Array<A>) => number;
concat: { (...items: Array<ConcatArray<A>>): Array<A>; (...items: Array<A | ConcatArray<A>>): Array<A> };
join: (separator?: string) => string;
reverse: () => Array<A>;
shift: () => A | undefined;
slice: (start?: number, end?: number) => Array<A>;
sort: (compareFn?: ((a: A, b: A) => number) | undefined) => [A, ...A[]];
splice: { (start: number, deleteCount?: number): Array<A>; (start: number, deleteCount: number, ...items: Array<A>): Array<A> };
unshift: (...items: Array<A>) => number;
indexOf: (searchElement: A, fromIndex?: number) => number;
lastIndexOf: (searchElement: A, fromIndex?: number) => number;
every: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): this is S[]; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: A, index: number, array: Array<A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: A, index: number, array: Array<A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): Array<A> };
reduce: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A, initialValue: A): A; (callbackfn: (previousVa…;
reduceRight: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A, initialValue: A): A; (callbackfn: (previousVa…;
find: { (predicate: (value: A, index: number, obj: Array<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, obj: Array<A>) => unknown, thisArg?: any): A | undefined };
findIndex: (predicate: (value: A, index: number, obj: Array<A>) => unknown, thisArg?: any) => number;
fill: (value: A, start?: number, end?: number) => [A, ...A[]];
copyWithin: (target: number, start: number, end?: number) => [A, ...A[]];
entries: () => ArrayIterator<[number, A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<A>;
includes: (searchElement: A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: A, index: number, array: Array<A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => A | undefined;
findLast: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): A | undefined };
findLastIndex: (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<A>;
toSorted: (compareFn?: ((a: A, b: A) => number) | undefined) => Array<A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<A>): Array<A>; (start: number, deleteCount?: number): Array<A> };
with: (index: number, value: A) => Array<A>;
}
out.Array<A>.push(...items: A[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(const o: Some<A>const o: {
_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;
}
o.Some<A>.value: Avalue)
}
return const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some(const out: [A, ...A[]]const out: {
0: A;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => A | undefined;
push: (...items: Array<A>) => number;
concat: { (...items: Array<ConcatArray<A>>): Array<A>; (...items: Array<A | ConcatArray<A>>): Array<A> };
join: (separator?: string) => string;
reverse: () => Array<A>;
shift: () => A | undefined;
slice: (start?: number, end?: number) => Array<A>;
sort: (compareFn?: ((a: A, b: A) => number) | undefined) => [A, ...A[]];
splice: { (start: number, deleteCount?: number): Array<A>; (start: number, deleteCount: number, ...items: Array<A>): Array<A> };
unshift: (...items: Array<A>) => number;
indexOf: (searchElement: A, fromIndex?: number) => number;
lastIndexOf: (searchElement: A, fromIndex?: number) => number;
every: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): this is S[]; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: A, index: number, array: Array<A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: A, index: number, array: Array<A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): Array<A> };
reduce: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A, initialValue: A): A; (callbackfn: (previousVa…;
reduceRight: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A, initialValue: A): A; (callbackfn: (previousVa…;
find: { (predicate: (value: A, index: number, obj: Array<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, obj: Array<A>) => unknown, thisArg?: any): A | undefined };
findIndex: (predicate: (value: A, index: number, obj: Array<A>) => unknown, thisArg?: any) => number;
fill: (value: A, start?: number, end?: number) => [A, ...A[]];
copyWithin: (target: number, start: number, end?: number) => [A, ...A[]];
entries: () => ArrayIterator<[number, A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<A>;
includes: (searchElement: A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: A, index: number, array: Array<A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => A | undefined;
findLast: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): A | undefined };
findLastIndex: (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<A>;
toSorted: (compareFn?: ((a: A, b: A) => number) | undefined) => Array<A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<A>): Array<A>; (start: number, deleteCount?: number): Array<A> };
with: (index: number, value: A) => Array<A>;
}
out)
}