Skip to content

Commit 67bc96f

Browse files
authored
docs: fix broken example for Array.reduce (#183)
* docs: fix broken example for Array.reduce * fix example signature * reduceWithIndex * reduceRight * f to fn
1 parent 532af3a commit 67bc96f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/Core__Array.resi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -699,47 +699,47 @@ Console.log(mappedArray) // ["Hello at position 0", "Hi at position 1", "Good by
699699
external mapWithIndex: (array<'a>, ('a, int) => 'b) => array<'b> = "map"
700700

701701
/**
702-
`reduce(xs, fn, init)`
702+
`reduce(xs, init, fn)`
703703
704704
Applies `fn` to each element of `xs` from beginning to end. Function `fn` 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.
705705
706706
```res example
707-
Array.reduce([2, 3, 4], (a, b) => a + b, 1) == 10
707+
Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10
708708
709-
Array.reduce(["a", "b", "c", "d"], (a, b) => a ++ b, "") == "abcd"
709+
Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd"
710710
```
711711
*/
712712
let reduce: (array<'a>, 'b, ('b, 'a) => 'b) => 'b
713713

714714
/**
715-
`reduceWithIndex(xs, fn, init)`
715+
`reduceWithIndex(x, init, fn)`
716716
717717
Applies `fn` to each element of `xs` from beginning to end. Function `fn` has three parameters: the item from the array and an “accumulator”, which starts with a value of `init` and the index of each element. `reduceWithIndex` returns the final value of the accumulator.
718718
719719
```res example
720-
Array.reduceWithIndex([1, 2, 3, 4], (acc, x, i) => acc + x + i, 0) == 16
720+
Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16
721721
```
722722
*/
723723
let reduceWithIndex: (array<'a>, 'b, ('b, 'a, int) => 'b) => 'b
724724

725725
/**
726-
`reduceRight(xs, fn, init)`
726+
`reduceRight(xs, init, fn)`
727727
728728
Works like `Array.reduce`; except that function `fn` is applied to each item of `xs` from the last back to the first.
729729
730730
```res example
731-
Array.reduceRight(["a", "b", "c", "d"], (a, b) => a ++ b, "") == "dcba"
731+
Array.reduceRight(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba"
732732
```
733733
*/
734734
let reduceRight: (array<'a>, 'b, ('b, 'a) => 'b) => 'b
735735

736736
/**
737-
`reduceRightWithIndex(xs, f, init)`
737+
`reduceRightWithIndex(xs, init, fn)`
738738
739739
Like `reduceRight`, but with an additional index argument on the callback function.
740740
741741
```res example
742-
Array.reduceRightWithIndex([1, 2, 3, 4], (acc, x, i) => acc + x + i, 0) == 16
742+
Array.reduceRightWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i, 0) == 16
743743
```
744744
*/
745745
let reduceRightWithIndex: (array<'a>, 'b, ('b, 'a, int) => 'b) => 'b

0 commit comments

Comments
 (0)