Using pipe with reduce

With the following code
let sum = lines -> -> Array.reduce((a,b)=>a + b, 0)
treatline being a function that convert a string to an int,
i receive the following error
This has type: int But this function argument is expecting: ((int, int) => int, int) => (int, int) => int
With the 0 accumulator being the source of error ?
I’m confused.
Thank you.

Are you sure you’ve open RescriptCore, it looks like you’re using a library that is t-last, so the first argument is a function and not t.

In reduce in Rescript Core, the initial value comes first instead of last like in JS. This is to make type inference work as good as it can. So, start with the initial value, then the function.

I am more and more confused :thinking:

That example is just wrong, sorry. The function signature is correct though.

1 Like

Thank you, reduce(xs, f, init) seems wrong too.

Here’s a PR to fix the example: docs: fix broken example for Array.reduce by jderochervlk · Pull Request #183 · rescript-association/rescript-core · GitHub