<B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => B
<A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BReduces the elements of a chunk from left to right.
Example (Reducing from the left)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 3, 4, 5)
const sum = Chunk.reduce(chunk, 0, (acc, n) => acc + n)
console.log(sum) // 15
// String concatenation with index
const words = Chunk.make("a", "b", "c")
const result = Chunk.reduce(words, "", (acc, word, i) => acc + `${i}:${word} `)
console.log(result) // "0:a 1:b 2:c "
// Find maximum
const max = Chunk.reduce(chunk, -Infinity, (acc, n) => Math.max(acc, n))
console.log(max) // 5folding
Source effect/Chunk.ts:28604 lines
export const const reduce: {
<B, A>(b: B, f: (b: B, a: A, i: number) => B): (
self: Chunk<A>
) => B
<A, B>(
self: Chunk<A>,
b: B,
f: (b: B, a: A, i: number) => B
): B
}
Reduces the elements of a chunk from left to right.
Example (Reducing from the left)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 3, 4, 5)
const sum = Chunk.reduce(chunk, 0, (acc, n) => acc + n)
console.log(sum) // 15
// String concatenation with index
const words = Chunk.make("a", "b", "c")
const result = Chunk.reduce(words, "", (acc, word, i) => acc + `${i}:${word} `)
console.log(result) // "0:a 1:b 2:c "
// Find maximum
const max = Chunk.reduce(chunk, -Infinity, (acc, n) => Math.max(acc, n))
console.log(max) // 5
reduce: {
<function (type parameter) B in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BB, function (type parameter) A in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BA>(b: Bb: function (type parameter) B in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BB, f: (b: B, a: A, i: number) => Bf: (b: Bb: function (type parameter) B in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BB, a: Aa: function (type parameter) A in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BA, i: numberi: number) => function (type parameter) B in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BB): (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 <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BA>) => function (type parameter) B in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BB
<function (type parameter) A in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BA, function (type parameter) B in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BB>(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, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BA>, b: Bb: function (type parameter) B in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BB, f: (b: B, a: A, i: number) => Bf: (b: Bb: function (type parameter) B in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BB, a: Aa: function (type parameter) A in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BA, i: numberi: number) => function (type parameter) B in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BB): function (type parameter) B in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BB
} = import RARA.reduce