Hyperlinkv0.8.0-beta.28

Chunk

Chunk.reduceconsteffect/Chunk.ts:2860
<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
folding
Source effect/Chunk.ts:28604 lines
export 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
} = RA.reduce