Skip to content

Commit 7bbdff0

Browse files
committed
docs for indexOf and includes
1 parent f8b6c0e commit 7bbdff0

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/Core__Array.resi

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,36 @@ Console.log([{"language": "ReScript"}]->Array.includes({"language": "ReScript"})
251251
*/
252252
@send
253253
external includes: (array<'a>, 'a) => bool = "includes"
254-
@send external indexOf: (array<'a>, 'a) => int = "indexOf"
254+
255+
/**
256+
`indexOf(array, item)` returns the index of the provided `item` in `array`. Uses [strict check for equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) when comparing items.
257+
258+
Returns `-1` if the item doesn not exist. Check out `Array.indexOfOpt` for a version that returns `None` instead of `-1` if the item does not exist.
259+
260+
See [`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) on MDN.
261+
262+
## Examples
263+
```rescript
264+
Console.log([1, 2]->Array.indexOf(2)) // 1
265+
Console.log([1, 2]->Array.indexOf(3)) // -1
266+
Console.log([{"language": "ReScript"}]->Array.indexOf({"language": "ReScript"})) // -1, because of strict equality
267+
```
268+
*/
269+
@send
270+
external indexOf: (array<'a>, 'a) => int = "indexOf"
271+
272+
/**
273+
`indexOfOpt(array, item)` returns an option of the index of the provided `item` in `array`. Uses [strict check for equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) when comparing items.
274+
275+
See [`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) on MDN.
276+
277+
## Examples
278+
```rescript
279+
Console.log([1, 2]->Array.indexOfOpt(2)) // Some(1)
280+
Console.log([1, 2]->Array.indexOfOpt(3)) // None
281+
Console.log([{"language": "ReScript"}]->Array.indexOfOpt({"language": "ReScript"})) // None, because of strict equality
282+
```
283+
*/
255284
let indexOfOpt: (array<'a>, 'a) => option<int>
256285
@send external indexOfFrom: (array<'a>, 'a, int) => int = "indexOf"
257286
@send external joinWith: (array<'a>, string) => string = "join"

0 commit comments

Comments
 (0)