<A, B>(self: Chunk<readonly [A, B]>): [Chunk<A>, Chunk<B>]Takes a Chunk of pairs and returns two corresponding Chunks.
Details
This function is the reverse of zip.
Example (Unzipping pairs)
import { Chunk } from "effect"
const pairs = Chunk.make(
[1, "a"] as const,
[2, "b"] as const,
[3, "c"] as const
)
const [numbers, letters] = Chunk.unzip(pairs)
console.log(Chunk.toArray(numbers)) // [1, 2, 3]
console.log(Chunk.toArray(letters)) // ["a", "b", "c"]
// Empty chunk
const empty = Chunk.empty<[number, string]>()
const [emptyNums, emptyStrs] = Chunk.unzip(empty)
console.log(Chunk.toArray(emptyNums)) // []
console.log(Chunk.toArray(emptyStrs)) // []export const const unzip: <A, B>(
self: Chunk<readonly [A, B]>
) => [Chunk<A>, Chunk<B>]
Takes a Chunk of pairs and returns two corresponding Chunks.
Details
This function is the reverse of zip.
Example (Unzipping pairs)
import { Chunk } from "effect"
const pairs = Chunk.make(
[1, "a"] as const,
[2, "b"] as const,
[3, "c"] as const
)
const [numbers, letters] = Chunk.unzip(pairs)
console.log(Chunk.toArray(numbers)) // [1, 2, 3]
console.log(Chunk.toArray(letters)) // ["a", "b", "c"]
// Empty chunk
const empty = Chunk.empty<[number, string]>()
const [emptyNums, emptyStrs] = Chunk.unzip(empty)
console.log(Chunk.toArray(emptyNums)) // []
console.log(Chunk.toArray(emptyStrs)) // []
unzip = <function (type parameter) A in <A, B>(self: Chunk<readonly [A, B]>): [Chunk<A>, Chunk<B>]A, function (type parameter) B in <A, B>(self: Chunk<readonly [A, B]>): [Chunk<A>, Chunk<B>]B>(self: Chunk<readonly [A, B]>(parameter) self: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: 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<readonly [function (type parameter) A in <A, B>(self: Chunk<readonly [A, B]>): [Chunk<A>, Chunk<B>]A, function (type parameter) B in <A, B>(self: Chunk<readonly [A, B]>): [Chunk<A>, Chunk<B>]B]>): [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, B>(self: Chunk<readonly [A, B]>): [Chunk<A>, Chunk<B>]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) B in <A, B>(self: Chunk<readonly [A, B]>): [Chunk<A>, Chunk<B>]B>] => {
const [const left: anyleft, const right: anyright] = import RARA.unzip(self: Chunk<readonly [A, B]>(parameter) self: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self)
return [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(const left: anyleft), 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(const right: anyright)]
}