<A>(self: Option.Option<A>): Array<A>Converts an Option to an array: Some(a) becomes [a], None becomes [].
When to use
Use to convert a single Option into an array for downstream array operations.
Example (Converting an Option to an array)
import { Array, Option } from "effect"
console.log(Array.fromOption(Option.some(1))) // [1]
console.log(Array.fromOption(Option.none())) // []export const const fromOption: <A>(
self: Option.Option<A>
) => Array<A>
Converts an Option to an array: Some(a) becomes [a], None becomes [].
When to use
Use to convert a single Option into an array for downstream array operations.
Example (Converting an Option to an array)
import { Array, Option } from "effect"
console.log(Array.fromOption(Option.some(1))) // [1]
console.log(Array.fromOption(Option.none())) // []
fromOption: <function (type parameter) A in <A>(self: Option.Option<A>): Array<A>A>(self: Option.Option<A>self: import OptionOption.type Option<A> = Option.None<A> | Option.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.Option<A>): Array<A>A>) => interface Array<T>Array<function (type parameter) A in <A>(self: Option.Option<A>): Array<A>A> = import OptionOption.const toArray: <A>(
self: Option<A>
) => Array<A>
Converts an Option into an Array.
When to use
Use when you need to pass an Option to array-based APIs or spread optional
values into collections.
Details
Some → single-element array [value]
None → empty array []
Example (Converting to an array)
import { Option } from "effect"
console.log(Option.toArray(Option.some(1)))
// Output: [1]
console.log(Option.toArray(Option.none()))
// Output: []
toArray