Hyperlinkv0.8.0-beta.28

Chunk

Chunk.forEachconsteffect/Chunk.ts:1223
<A, B>(f: (a: A, index: number) => B): (self: Chunk<A>) => void
<A, B>(self: Chunk<A>, f: (a: A, index: number) => B): void

Iterates over each element of a Chunk and applies a function to it.

Details

This function processes every element of the given Chunk, calling the provided function f on each element. It does not return a new value; instead, it is primarily used for side effects, such as logging or accumulating data in an external variable.

Example (Iterating over chunk values)

import { Chunk } from "effect"

const chunk = Chunk.make(1, 2, 3, 4)

// Log each element
Chunk.forEach(chunk, (n) => console.log(`Value: ${n}`))
// Output:
// Value: 1
// Value: 2
// Value: 3
// Value: 4

// With index parameter
Chunk.forEach(chunk, (n, i) => console.log(`Index ${i}: ${n}`))
// Output:
// Index 0: 1
// Index 1: 2
// Index 2: 3
// Index 3: 4
combinators
Source effect/Chunk.ts:12234 lines
export const forEach: {
  <A, B>(f: (a: A, index: number) => B): (self: Chunk<A>) => void
  <A, B>(self: Chunk<A>, f: (a: A, index: number) => B): void
} = dual(2, <A, B>(self: Chunk<A>, f: (a: A) => B): void => toReadonlyArray(self).forEach(f))
Referenced by 1 symbols