Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All signatures or descriptions of findIndexi are incorrect #664

Open
danielo515 opened this issue Mar 22, 2023 · 3 comments
Open

All signatures or descriptions of findIndexi are incorrect #664

danielo515 opened this issue Mar 22, 2023 · 3 comments

Comments

@danielo515
Copy link

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
Copy link

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
Copy link
Member

ryyppy commented May 26, 2023

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

@danielo515
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants