Skip to content

Fixing the reduce documentation #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pages/docs/manual/latest/api/belt/array.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,16 @@ let reduceU: (array<'b>, 'a, (. 'a, 'b) => 'a) => 'a
let reduce: (array<'b>, 'a, ('a, 'b) => 'a) => 'a
```

`reduce(xs, init, f)`
`reduce(arr, init, f)`

Applies `f` to each element of `xs` from beginning to end. Function `f` has two parameters: the item from the list and an “accumulator”; which starts with a value of `init`. `reduce` returns the final value of the accumulator.
Applies `f` to each element of `arr`.

Function `f` has two parameters: an "accumulator" which starts with a value of `init` and the next value from the array.

It returns the final value of the accumulator.

```res example
Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10
Belt.Array.reduce([2, 3, 4], 1, (acc, value) => acc + value) == 10

Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd"
```
Expand Down