Skip to content

Commit 1ac4d86

Browse files
committed
Merge branch 'main' into date-format-functions-with-options
2 parents 6876ab7 + f77964d commit 1ac4d86

File tree

6 files changed

+908
-32
lines changed

6 files changed

+908
-32
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
- Change `Set.add` to not return self, to indicate that it's mutable. https://github.com/rescript-association/rescript-core/pull/35
99
- Change `Iterator` bindings to have the same shape as `AsyncIterator` for consistency. https://github.com/rescript-association/rescript-core/pull/34
1010
- Add `Iterator.toArray` binding for turning an iterator into an array. https://github.com/rescript-association/rescript-core/pull/34
11+
- Add `Array.at` binding for returning an array item by its index. https://github.com/rescript-association/rescript-core/pull/48
12+
- Fixed type signatures of `Array.fromArrayLikeWithMap` and `Array.fromIteratorWithMap`. https://github.com/rescript-association/rescript-core/pull/50
13+
- Remove internal async/await helpers that do not need to be exposed in `Core`.
1114

1215
### Documentation
1316

src/Core__Array.res

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ external setUnsafe: (array<'a>, int, 'a) => unit = "%array_unsafe_set"
66

77
@val external fromArrayLike: Js.Array2.array_like<'a> => array<'a> = "Array.from"
88
@val
9-
external fromArrayLikeWithMap: (Js.Array2.array_like<'a>, 'a => 'b) => array<'a> = "Array.from"
9+
external fromArrayLikeWithMap: (Js.Array2.array_like<'a>, 'a => 'b) => array<'b> = "Array.from"
1010

1111
@val external fromIterator: Core__Iterator.t<'a> => array<'a> = "Array.from"
12-
@val external fromIteratorWithMap: (Core__Iterator.t<'a>, 'a => 'c) => array<'a> = "Array.from"
12+
@val external fromIteratorWithMap: (Core__Iterator.t<'a>, 'a => 'b) => array<'b> = "Array.from"
1313

1414
@val external isArray: 'a => bool = "Array.isArray"
1515

@@ -196,3 +196,5 @@ let filterMap = (a, f) => filterMapU(a, (. a) => f(a))
196196

197197
// TODO: Change this implementation?
198198
let flatMap = (a, f) => []->concatMany(map(a, f))
199+
200+
@send external at: (array<'a>, int) => option<'a> = "at"

src/Core__Array.resi

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
@val external fromWithMap: ('a, 'b => 'c) => array<'c> = "Array.from"
33
@val external fromArrayLike: Js.Array2.array_like<'a> => array<'a> = "Array.from"
44
@val
5-
external fromArrayLikeWithMap: (Js.Array2.array_like<'a>, 'a => 'b) => array<'a> = "Array.from"
5+
external fromArrayLikeWithMap: (Js.Array2.array_like<'a>, 'a => 'b) => array<'b> = "Array.from"
66
@val external fromIterator: Core__Iterator.t<'a> => array<'a> = "Array.from"
7-
@val external fromIteratorWithMap: (Core__Iterator.t<'a>, 'a => 'c) => array<'a> = "Array.from"
7+
@val external fromIteratorWithMap: (Core__Iterator.t<'a>, 'a => 'b) => array<'b> = "Array.from"
88
@val external isArray: 'a => bool = "Array.isArray"
99
@get external length: array<'a> => int = "length"
1010
@send external copyAllWithin: (array<'a>, ~target: int) => array<'a> = "copyWithin"
@@ -103,3 +103,21 @@ let filterMap: (array<'a>, 'a => option<'b>) => array<'b>
103103
let shuffle: array<'a> => array<'a>
104104
let shuffleInPlace: array<'a> => unit
105105
let flatMap: (array<'a>, 'a => array<'b>) => array<'b>
106+
107+
108+
/**
109+
`at(array, index)`
110+
111+
Get an element by its index. Negative indices count backwards from the last item.
112+
113+
## Examples
114+
```rescript
115+
["a", "b", "c"]->Array.at(0) // Some("a")
116+
["a", "b", "c"]->Array.at(2) // Some("c")
117+
["a", "b", "c"]->Array.at(3) // None
118+
["a", "b", "c"]->Array.at(-1) // Some("c")
119+
["a", "b", "c"]->Array.at(-3) // Some("a")
120+
["a", "b", "c"]->Array.at(-4) // None
121+
```
122+
*/
123+
@send external at: (array<'a>, int) => option<'a> = "at"

0 commit comments

Comments
 (0)