<A>(self: Iterable<A>): Chunk<A>Creates a new Chunk from an iterable collection of values.
Example (Creating chunks from iterables)
import { Chunk } from "effect"
const chunk = Chunk.fromIterable([1, 2, 3])
console.log(Chunk.toArray(chunk)) // [1, 2, 3]constructors
Source effect/Chunk.ts:3532 lines
export const const fromIterable: <A>(
self: Iterable<A>
) => Chunk<A>
Creates a new Chunk from an iterable collection of values.
Example (Creating chunks from iterables)
import { Chunk } from "effect"
const chunk = Chunk.fromIterable([1, 2, 3])
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
fromIterable = <function (type parameter) A in <A>(self: Iterable<A>): Chunk<A>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<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: Iterable<A>): Chunk<A>A> =>
const isChunk: {
<A>(u: Iterable<A>): u is Chunk<A>
(u: unknown): u is Chunk<unknown>
}
isChunk(self: Iterable<A>self) ? 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 : 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.fromIterable(self: Iterable<A>self))Referenced by 6 symbols