Hyperlinkv0.8.0-beta.28

Chunk

Chunk.fromNonEmptyArrayUnsafeconsteffect/Chunk.ts:602
<A>(self: NonEmptyReadonlyArray<A>): NonEmptyChunk<A>

Wraps a non-empty array into a non-empty chunk without copying.

When to use

Use when the input array is already known to be non-empty, 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 non-empty chunks without copying arrays)

import { Array, Chunk } from "effect"

const nonEmptyArray = Array.make(1, 2, 3, 4, 5)
const chunk = Chunk.fromNonEmptyArrayUnsafe(nonEmptyArray)
console.log(Chunk.toArray(chunk)) // [1, 2, 3, 4, 5]

// The result is guaranteed to be non-empty
console.log(Chunk.isNonEmpty(chunk)) // true
unsafe
Source effect/Chunk.ts:6022 lines
export const fromNonEmptyArrayUnsafe = <A>(self: NonEmptyReadonlyArray<A>): NonEmptyChunk<A> =>
  fromArrayUnsafe(self) as any
Referenced by 2 symbols