Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Change `Set.add` to not return self, to indicate that it's mutable. https://github.com/rescript-association/rescript-core/pull/35
- Change `Iterator` bindings to have the same shape as `AsyncIterator` for consistency. https://github.com/rescript-association/rescript-core/pull/34
- Add `Iterator.toArray` binding for turning an iterator into an array. https://github.com/rescript-association/rescript-core/pull/34
- Add `Array.at` binding for returning an array item by its index. https://github.com/rescript-association/rescript-core/pull/48

### Documentation

Expand Down
2 changes: 2 additions & 0 deletions src/Core__Array.res
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,5 @@ let filterMap = (a, f) => filterMapU(a, (. a) => f(a))

// TODO: Change this implementation?
let flatMap = (a, f) => []->concatMany(map(a, f))

@send external at: (array<'a>, int) => option<'a> = "at"
18 changes: 18 additions & 0 deletions src/Core__Array.resi
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,21 @@ let filterMap: (array<'a>, 'a => option<'b>) => array<'b>
let shuffle: array<'a> => array<'a>
let shuffleInPlace: array<'a> => unit
let flatMap: (array<'a>, 'a => array<'b>) => array<'b>


/**
`at(array, index)`

Get an element by its index. Negative indices count backwards from the last item.

## Examples
```rescript
["a", "b", "c"]->Array.at(0) // Some("a")
["a", "b", "c"]->Array.at(2) // Some("c")
["a", "b", "c"]->Array.at(3) // None
["a", "b", "c"]->Array.at(-1) // Some("c")
["a", "b", "c"]->Array.at(-3) // Some("a")
["a", "b", "c"]->Array.at(-4) // None
```
*/
@send external at: (array<'a>, int) => option<'a> = "at"