Skip to content

Commit 2fe447c

Browse files
authored
Update forEach function in Chunk to include missing index paramet… (#4404)
1 parent 03c048c commit 2fe447c

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

.changeset/nine-waves-protect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect": patch
3+
---
4+
5+
Update `forEach` function in `Chunk` to include missing index parameter.

packages/effect/src/Chunk.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,14 +738,21 @@ export const flatMap: {
738738
})
739739

740740
/**
741-
* Applies the specified function to each element of the `List`.
741+
* Iterates over each element of a `Chunk` and applies a function to it.
742+
*
743+
* **Details**
744+
*
745+
* This function processes every element of the given `Chunk`, calling the
746+
* provided function `f` on each element. It does not return a new value;
747+
* instead, it is primarily used for side effects, such as logging or
748+
* accumulating data in an external variable.
742749
*
743750
* @since 2.0.0
744751
* @category combinators
745752
*/
746753
export const forEach: {
747-
<A, B>(f: (a: A) => B): (self: Chunk<A>) => void
748-
<A, B>(self: Chunk<A>, f: (a: A) => B): void
754+
<A, B>(f: (a: A, index: number) => B): (self: Chunk<A>) => void
755+
<A, B>(self: Chunk<A>, f: (a: A, index: number) => B): void
749756
} = dual(2, <A, B>(self: Chunk<A>, f: (a: A) => B): void => toReadonlyArray(self).forEach(f))
750757

751758
/**

packages/effect/test/Chunk.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,9 +840,9 @@ describe("Chunk", () => {
840840
})
841841

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

848848
it("sortWith", () => {

0 commit comments

Comments
 (0)