Hyperlinkv0.8.0-beta.28

Array

Array.fromIterableconsteffect/Array.ts:304
<A>(collection: Iterable<A>): Array<A>

Converts an Iterable to an Array.

When to use

Use to convert any Iterable (Set, Generator, etc.) into an array.

Details

If the input is already an array, this returns it by reference without copying. Otherwise, it creates a new array from the iterable. Use copy if you need a fresh array even when the input is already an array.

Example (Converting a Set to an array)

import { Array } from "effect"

const result = Array.fromIterable(new Set([1, 2, 3]))
console.log(result) // [1, 2, 3]
constructorsensurecopy
Source effect/Array.ts:3042 lines
export const fromIterable = <A>(collection: Iterable<A>): Array<A> =>
  Array.isArray(collection) ? collection : Array.from(collection)
Referenced by 45 symbols