Hyperlinkv0.8.0-beta.28

Option

Option.toArrayconsteffect/Option.ts:1884
<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: []
convertingfromIterable
Source effect/Option.ts:18841 lines
export const toArray = <A>(self: Option<A>): Array<A> => isNone(self) ? [] : [self.value]
Referenced by 1 symbols