rescript-lang / rescript-lang.org

Official documentation website for the ReScript programming language
https://rescript-lang.org
MIT License
1.85k stars 248 forks source link

All signatures or descriptions of findIndexi are incorrect #664

Open danielo515 opened 1 year ago

danielo515 commented 1 year ago

https://rescript-lang.org/docs/manual/latest/api/js/array#findindexi

let findIndexi: (('a, int) => bool, t<'a>) => int
Returns Some(value) for the first element in the array that satisifies the given predicate function, or None if no element satisifies the predicate. The predicate function takes an array element and an index as its parameters. See [Array.find](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) on MDN.

RES
// find index of first positive item at an odd index
let positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0

Js.Array.findIndexi(positiveOddElement, [66, -33, 55, 88, 22]) == 3
Js.Array.findIndexi(positiveOddElement, [66, -33, 55, -88, 22]) == -1

If it returns an int, then it does not return Some | None. Or the signature is wrong or the description is wrong.

chriswilty commented 1 year ago

Actually it would be really useful to have a variant of these findIndex/i functions that does indeed return an option, similarly to find, if we are encouraged to use pattern matching instead of the ternary operator.

ryyppy commented 1 year ago

These APIs will be superseded by rescript-core functionality: https://github.com/rescript-association/rescript-core

danielo515 commented 1 year ago

These APIs will be superseded by rescript-core functionality: https://github.com/rescript-association/rescript-core

That doesn't mean this API should be abandoned, does it?