Hyperlinkv0.8.0-beta.28

Chunk

Chunk.fromArrayUnsafeconsteffect/Chunk.ts:571
<A>(self: ReadonlyArray<A>): Chunk<A>

Wraps an array into a chunk without copying.

When to use

Use when the input array can be shared with the resulting Chunk and avoiding a copy matters.

Gotchas

Mutating the source array after wrapping can mutate the resulting Chunk.

Example (Creating chunks without copying arrays)

import { Chunk } from "effect"

const array = [1, 2, 3, 4, 5]
const chunk = Chunk.fromArrayUnsafe(array)
console.log(Chunk.toArray(chunk)) // [1, 2, 3, 4, 5]

// Warning: Since this doesn't copy the array, mutations affect the chunk
array[0] = 999
console.log(Chunk.toArray(chunk)) // [999, 2, 3, 4, 5]
unsafe
Source effect/Chunk.ts:5712 lines
export const fromArrayUnsafe = <A>(self: ReadonlyArray<A>): Chunk<A> =>
  self.length === 0 ? empty() : self.length === 1 ? of(self[0]) : makeChunk({ _tag: "IArray", array: self })
Referenced by 24 symbols