<A>(self: Chunk<A>): Chunk<A>Removes duplicate elements from a Chunk, preserving the first occurrence
of each value.
Example (Removing duplicate values)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 2, 3, 1, 4, 3)
const result = Chunk.dedupe(chunk)
console.log(Chunk.toArray(result)) // [1, 2, 3, 4]
// Empty chunk
const empty = Chunk.empty<number>()
const emptyDeduped = Chunk.dedupe(empty)
console.log(Chunk.toArray(emptyDeduped)) // []
// No duplicates
const unique = Chunk.make(1, 2, 3)
const uniqueDeduped = Chunk.dedupe(unique)
console.log(Chunk.toArray(uniqueDeduped)) // [1, 2, 3]export const const dedupe: <A>(
self: Chunk<A>
) => Chunk<A>
Removes duplicate elements from a Chunk, preserving the first occurrence
of each value.
Example (Removing duplicate values)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 2, 3, 1, 4, 3)
const result = Chunk.dedupe(chunk)
console.log(Chunk.toArray(result)) // [1, 2, 3, 4]
// Empty chunk
const empty = Chunk.empty<number>()
const emptyDeduped = Chunk.dedupe(empty)
console.log(Chunk.toArray(emptyDeduped)) // []
// No duplicates
const unique = Chunk.make(1, 2, 3)
const uniqueDeduped = Chunk.dedupe(unique)
console.log(Chunk.toArray(uniqueDeduped)) // [1, 2, 3]
dedupe = <function (type parameter) A in <A>(self: Chunk<A>): Chunk<A>A>(self: Chunk<A>(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<function (type parameter) A in <A>(self: Chunk<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: Chunk<A>): Chunk<A>A> => 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(import RARA.const dedupe: <S extends Iterable<any>>(
self: S
) => S extends NonEmptyReadonlyArray<infer A>
? NonEmptyArray<A>
: S extends Iterable<infer A>
? Array<A>
: never
Removes duplicates using Equal.equivalence(), preserving the order of the
first occurrence.
When to use
Use to remove repeated values from an iterable when Effect's default equality
is the right comparison, preserving the first occurrence.
Example (Removing duplicates)
import { Array } from "effect"
console.log(Array.dedupe([1, 2, 1, 3, 2, 4])) // [1, 2, 3, 4]
dedupe(const toReadonlyArray: <
S extends Chunk<any>
>(
self: S
) => S extends NonEmptyChunk<any>
? RA.NonEmptyReadonlyArray<Chunk.Infer<S>>
: ReadonlyArray<Chunk.Infer<S>>
Converts a Chunk into a ReadonlyArray. If the provided Chunk is
non-empty (NonEmptyChunk), the function will return a
NonEmptyReadonlyArray, ensuring the non-empty property is preserved.
Example (Converting chunks to readonly arrays)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 3)
const readonlyArray = Chunk.toReadonlyArray(chunk)
console.log(readonlyArray) // [1, 2, 3]
// The result is read-only, modifications would cause TypeScript errors
// readonlyArray[0] = 10 // TypeScript error
// With empty chunk
const emptyChunk = Chunk.empty<number>()
console.log(Chunk.toReadonlyArray(emptyChunk)) // []
toReadonlyArray(self: Chunk<A>(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)))