rescript-lang.org
rescript-lang.org copied to clipboard
All signatures or descriptions of findIndexi are incorrect
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.
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.
These APIs will be superseded by rescript-core functionality: https://github.com/rescript-association/rescript-core
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?