<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]export const const fromArrayUnsafe: <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]
fromArrayUnsafe = <function (type parameter) A in <A>(self: ReadonlyArray<A>): Chunk<A>A>(self: readonly A[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) A in <A>(self: ReadonlyArray<A>): Chunk<A>A>): interface Chunk<out A>A Chunk is an immutable, ordered collection optimized for efficient concatenation and access patterns.
Example (Inspecting chunk values)
import { Chunk } from "effect"
const chunk: Chunk.Chunk<number> = Chunk.make(1, 2, 3)
console.log(chunk.length) // 3
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
A namespace containing utility types for Chunk operations.
Example (Working with Chunk utility types)
import type { Chunk } from "effect"
// Extract the element type from a Chunk
declare const chunk: Chunk.Chunk<string>
type ElementType = Chunk.Chunk.Infer<typeof chunk> // string
// Create a preserving non-emptiness
declare const nonEmptyChunk: Chunk.NonEmptyChunk<number>
type WithString = Chunk.Chunk.With<typeof nonEmptyChunk, string> // Chunk.NonEmptyChunk<string>
Chunk<function (type parameter) A in <A>(self: ReadonlyArray<A>): Chunk<A>A> =>
self: readonly A[]self.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length === 0 ? const empty: <A = never>() => Chunk<A>Creates an empty Chunk.
Example (Creating an empty chunk)
import { Chunk } from "effect"
const emptyChunk = Chunk.empty()
console.log(Chunk.size(emptyChunk)) // 0
empty() : self: readonly A[]self.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length === 1 ? const of: <A>(a: A) => NonEmptyChunk<A>Builds a NonEmptyChunk from a single element.
Example (Creating a single-element chunk)
import { Chunk } from "effect"
const chunk = Chunk.of("hello")
console.log(Chunk.toArray(chunk)) // ["hello"]
of(self: readonly A[]self[0]) : const makeChunk: <A>(
backing: Backing<A>
) => Chunk<A>
makeChunk({ IArray<A>._tag: "IArray"_tag: "IArray", IArray<A>.array: readonly A[]array: self: readonly A[]self })