rescript-lang.org icon indicating copy to clipboard operation
rescript-lang.org copied to clipboard

All signatures or descriptions of findIndexi are incorrect

Open danielo515 opened this issue 2 years ago • 3 comments

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.

danielo515 avatar Mar 22 '23 17:03 danielo515

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.

chriswilty avatar May 18 '23 09:05 chriswilty

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

ryyppy avatar May 26 '23 07:05 ryyppy

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?

danielo515 avatar Jun 15 '23 08:06 danielo515