@@ -6,7 +6,21 @@ external fromArrayLikeWithMap: (Js.Array2.array_like<'a>, 'a => 'b) => array<'b>
66@val external fromIterator : Core__Iterator .t <'a > => array <'a > = "Array.from"
77@val external fromIteratorWithMap : (Core__Iterator .t <'a >, 'a => 'b ) => array <'b > = "Array.from"
88@val external isArray : 'a => bool = "Array.isArray"
9- @get external length : array <'a > => int = "length"
9+
10+ /**
11+ `length(array)` returns the `int` length (number of items) of the array.
12+
13+ See [`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length) on MDN.
14+
15+ ## Examples
16+ ```rescript
17+ let someArray = ["hi", "hello"]
18+
19+ Console.log(someArray->Array.length) // 2
20+ ```
21+ */
22+ @get
23+ external length : array <'a > => int = "length"
1024@send external copyAllWithin : (array <'a >, ~target : int ) => array <'a > = "copyWithin"
1125@send
1226external copyWithinToEnd : (array <'a >, ~target : int , ~start : int ) => array <'a > = "copyWithin"
@@ -15,22 +29,205 @@ external copyWithin: (array<'a>, ~target: int, ~start: int, ~end: int) => array<
1529@send external fillAllInPlace : (array <'a >, 'a ) => unit = "fill"
1630@send external fillInPlaceToEnd : (array <'a >, 'a , ~start : int ) => unit = "fill"
1731@send external fillInPlace : (array <'a >, 'a , ~start : int , ~end : int ) => unit = "fill"
18- @send external pop : array <'a > => option <'a > = "pop"
19- @send external push : (array <'a >, 'a ) => unit = "push"
20- @variadic @send external pushMany : (array <'a >, array <'a >) => unit = "push"
21- @send external reverseInPlace : array <'a > => unit = "reverse"
22- @send external shift : array <'a > => option <'a > = "shift"
32+
33+ /**
34+ `pop(array)` pops off the last item in the array, and returns it.
35+
36+ Beware this will *mutate* the array.
37+
38+ See [`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop) on MDN.
39+
40+ ## Examples
41+ ```rescript
42+ let someArray = ["hi", "hello"]
43+ let lastItem = someArray->Array.pop // "hello"
44+
45+ Console.log(someArray) // ["hi"]. Notice last item is gone.
46+ ```
47+ */
48+ @send
49+ external pop : array <'a > => option <'a > = "pop"
50+
51+ /**
52+ `push(array, item)` pushes a new item to the end of the array.
53+
54+ Beware this will *mutate* the array.
55+
56+ See [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) on MDN.
57+
58+ ## Examples
59+ ```rescript
60+ let someArray = ["hi", "hello"]
61+ someArray->Array.push("yay")
62+
63+ Console.log(someArray) // ["hi", "hello", "yay"]
64+ ```
65+ */
66+ @send
67+ external push : (array <'a >, 'a ) => unit = "push"
68+
69+ /**
70+ `pushMany(array, itemsArray)` pushes many new items to the end of the array.
71+
72+ Beware this will *mutate* the array.
73+
74+ See [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) on MDN.
75+
76+ ## Examples
77+ ```rescript
78+ let someArray = ["hi", "hello"]
79+ someArray->Array.pushMany(["yay", "wehoo"])
80+
81+ Console.log(someArray) // ["hi", "hello", "yay", "wehoo"]
82+ ```
83+ */
84+ @variadic
85+ @send
86+ external pushMany : (array <'a >, array <'a >) => unit = "push"
87+
88+ /**
89+ `reverse(array)` reverses the order of the items in the array.
90+
91+ Beware this will *mutate* the array.
92+
93+ See [`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse) on MDN.
94+
95+ ## Examples
96+ ```rescript
97+ let someArray = ["hi", "hello"]
98+ someArray->Array.reverse
99+
100+ Console.log(someArray) // ["hello", "h1"]
101+ ```
102+ */
103+ @send
104+ external reverseInPlace : array <'a > => unit = "reverse"
105+
106+ /**
107+ `shift(array)` removes the first item in the array, and returns it.
108+
109+ Beware this will *mutate* the array.
110+
111+ See [`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift) on MDN.
112+
113+ ## Examples
114+ ```rescript
115+ let someArray = ["hi", "hello"]
116+ let lastItem = someArray->Array.shift // "hi"
117+
118+ Console.log(someArray) // ["hello"]. Notice first item is gone.
119+ ```
120+ */
121+ @send
122+ external shift : array <'a > => option <'a > = "shift"
23123let sort : (array <'a >, ('a , 'a ) => int ) => array <'a >
24124@send external sortInPlace : (array <'a >, ('a , 'a ) => int ) => unit = "sort"
25125@variadic @send
26126external spliceInPlace : (array <'a >, ~start : int , ~remove : int , ~insert : array <'a >) => unit =
27127 "splice"
28- @send external unshift : (array <'a >, 'a ) => unit = "unshift"
29- @variadic @send external unshiftMany : (array <'a >, array <'a >) => unit = "unshift"
30- @send external concat : (array <'a >, array <'a >) => array <'a > = "concat"
31- @variadic @send external concatMany : (array <'a >, array <array <'a >>) => array <'a > = "concat"
32- @send external flat : array <array <'a >> => array <'a > = "flat"
33- @send external includes : (array <'a >, 'a ) => bool = "includes"
128+
129+ /**
130+ `unshift(array, item)` inserts a new item at the start of the array.
131+
132+ Beware this will *mutate* the array.
133+
134+ See [`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) on MDN.
135+
136+ ## Examples
137+ ```rescript
138+ let someArray = ["hi", "hello"]
139+ someArray->Array.unshift("yay")
140+
141+ Console.log(someArray) // ["yay", "hi", "hello"]
142+ ```
143+ */
144+ @send
145+ external unshift : (array <'a >, 'a ) => unit = "unshift"
146+
147+ /**
148+ `unshiftMany(array, itemsArray)` inserts many new items to the start of the array.
149+
150+ Beware this will *mutate* the array.
151+
152+ See [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) on MDN.
153+
154+ ## Examples
155+ ```rescript
156+ let someArray = ["hi", "hello"]
157+ someArray->Array.unshiftMany(["yay", "wehoo"])
158+
159+ Console.log(someArray) // ["yay", "wehoo", "hi", "hello"]
160+ ```
161+ */
162+ @variadic
163+ @send
164+ external unshiftMany : (array <'a >, array <'a >) => unit = "unshift"
165+
166+ /**
167+ `concat(array1, array2)` concatenates two arrays, creating a new array.
168+
169+ See [`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat) on MDN.
170+
171+ ## Examples
172+ ```rescript
173+ let array1 = ["hi", "hello"]
174+ let array2 = ["yay", "wehoo"]
175+
176+ let someArray = array1->Array.concat(array2)
177+
178+ Console.log(someArray) // ["hi", "hello", "yay", "wehoo"]
179+ ```
180+ */
181+ @send
182+ external concat : (array <'a >, array <'a >) => array <'a > = "concat"
183+
184+ /**
185+ `concatMany(array1, arrays)` concatenates array1 with several other arrays, creating a new array.
186+
187+ See [`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat) on MDN.
188+
189+ ## Examples
190+ ```rescript
191+ let array1 = ["hi", "hello"]
192+ let array2 = ["yay"]
193+ let array3 = ["wehoo"]
194+
195+ let someArray = array1->Array.concatMany([array2, array3])
196+
197+ Console.log(someArray) // ["hi", "hello", "yay", "wehoo"]
198+ ```
199+ */
200+ @variadic
201+ @send
202+ external concatMany : (array <'a >, array <array <'a >>) => array <'a > = "concat"
203+
204+ /**
205+ `flat(arrays)` flattens the provided arrays into a single array.
206+
207+ See [`Array.flat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) on MDN.
208+
209+ ## Examples
210+ ```rescript
211+ Console.log([[1], [2], [3, 4]]->Array.flat) // [1, 2, 3, 4]
212+ ```
213+ */
214+ @send
215+ external flat : array <array <'a >> => array <'a > = "flat"
216+
217+ /**
218+ `includes(array, item)` checks whether `array` includes `item`, by doing a [strict check for equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality).
219+
220+ See [`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes) on MDN.
221+
222+ ## Examples
223+ ```rescript
224+ Console.log([1, 2]->Array.includes(1)) // true
225+ Console.log([1, 2]->Array.includes(3)) // false
226+ Console.log([{"language": "ReScript"}]->Array.includes({"language": "ReScript"})) // false, because of strict equality
227+ ```
228+ */
229+ @send
230+ external includes : (array <'a >, 'a ) => bool = "includes"
34231@send external indexOf : (array <'a >, 'a ) => int = "indexOf"
35232let indexOfOpt : (array <'a >, 'a ) => option <int >
36233@send external indexOfFrom : (array <'a >, 'a , int ) => int = "indexOf"
0 commit comments