Skip to content

Commit

Permalink
Update forEach function in Chunk to include missing index paramet… (
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Feb 9, 2025
1 parent 03c048c commit 2fe447c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-waves-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Update `forEach` function in `Chunk` to include missing index parameter.
13 changes: 10 additions & 3 deletions packages/effect/src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,14 +738,21 @@ export const flatMap: {
})

/**
* Applies the specified function to each element of the `List`.
* 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.
*
* @since 2.0.0
* @category combinators
*/
export const forEach: {
<A, B>(f: (a: A) => B): (self: Chunk<A>) => void
<A, B>(self: Chunk<A>, f: (a: A) => B): void
<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))

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/effect/test/Chunk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,9 @@ describe("Chunk", () => {
})

it("forEach", () => {
const as: Array<number> = []
Chunk.forEach(Chunk.make(1, 2, 3, 4), (n) => as.push(n))
deepStrictEqual(as, [1, 2, 3, 4])
const as: Array<string> = []
Chunk.forEach(Chunk.make(1, 2, 3, 4), (n, i) => as.push(`${n}-${i}`))
deepStrictEqual(as, ["1-0", "2-1", "3-2", "4-3"])
})

it("sortWith", () => {
Expand Down

0 comments on commit 2fe447c

Please sign in to comment.