@grain/stdlib 0.6.6 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/array.gr +55 -7
- package/array.md +606 -560
- package/bigint.md +228 -228
- package/buffer.gr +85 -53
- package/buffer.md +442 -319
- package/bytes.gr +112 -35
- package/bytes.md +299 -219
- package/char.gr +201 -99
- package/char.md +447 -120
- package/exception.gr +11 -11
- package/exception.md +29 -4
- package/float32.gr +327 -3
- package/float32.md +698 -111
- package/float64.gr +320 -3
- package/float64.md +698 -111
- package/fs.gr +1082 -0
- package/fs.md +630 -0
- package/hash.gr +142 -88
- package/hash.md +105 -17
- package/int16.md +178 -178
- package/int32.gr +26 -5
- package/int32.md +266 -231
- package/int64.gr +27 -2
- package/int64.md +266 -231
- package/int8.md +178 -178
- package/json.gr +366 -51
- package/json.md +431 -15
- package/list.gr +328 -31
- package/list.md +759 -336
- package/map.gr +20 -12
- package/map.md +266 -260
- package/marshal.gr +41 -40
- package/marshal.md +14 -14
- package/number.gr +278 -35
- package/number.md +688 -269
- package/option.md +162 -162
- package/package.json +5 -3
- package/path.gr +48 -0
- package/path.md +180 -89
- package/pervasives.gr +2 -2
- package/pervasives.md +275 -275
- package/priorityqueue.gr +7 -7
- package/priorityqueue.md +131 -131
- package/queue.gr +183 -29
- package/queue.md +404 -148
- package/random.md +43 -43
- package/range.gr +4 -4
- package/range.md +42 -42
- package/rational.md +123 -123
- package/regex.gr +52 -51
- package/regex.md +102 -102
- package/result.md +118 -118
- package/runtime/atof/common.md +39 -39
- package/runtime/atof/decimal.gr +6 -6
- package/runtime/atof/decimal.md +14 -14
- package/runtime/atof/lemire.gr +5 -5
- package/runtime/atof/lemire.md +1 -1
- package/runtime/atof/parse.gr +16 -16
- package/runtime/atof/parse.md +2 -2
- package/runtime/atof/slow.md +1 -1
- package/runtime/atof/table.md +2 -2
- package/runtime/atoi/parse.gr +3 -3
- package/runtime/atoi/parse.md +1 -1
- package/runtime/bigint.gr +15 -47
- package/runtime/bigint.md +54 -60
- package/runtime/compare.gr +2 -2
- package/runtime/compare.md +8 -8
- package/runtime/dataStructures.md +211 -211
- package/runtime/debugPrint.gr +4 -1
- package/runtime/debugPrint.md +9 -9
- package/runtime/equal.gr +99 -77
- package/runtime/equal.md +8 -8
- package/runtime/exception.gr +62 -82
- package/runtime/exception.md +62 -11
- package/runtime/gc.gr +39 -45
- package/runtime/gc.md +4 -4
- package/runtime/malloc.gr +7 -7
- package/runtime/malloc.md +13 -13
- package/runtime/math/kernel/cos.gr +70 -0
- package/runtime/math/kernel/cos.md +14 -0
- package/runtime/math/kernel/sin.gr +65 -0
- package/runtime/math/kernel/sin.md +14 -0
- package/runtime/math/kernel/tan.gr +136 -0
- package/runtime/math/kernel/tan.md +14 -0
- package/runtime/math/rempio2.gr +244 -0
- package/runtime/math/rempio2.md +14 -0
- package/runtime/math/trig.gr +130 -0
- package/runtime/math/trig.md +28 -0
- package/runtime/math/umuldi.gr +26 -0
- package/runtime/math/umuldi.md +14 -0
- package/runtime/numberUtils.gr +29 -29
- package/runtime/numberUtils.md +12 -12
- package/runtime/numbers.gr +373 -381
- package/runtime/numbers.md +348 -342
- package/runtime/string.gr +37 -105
- package/runtime/string.md +20 -26
- package/runtime/unsafe/constants.md +24 -24
- package/runtime/unsafe/conv.md +19 -19
- package/runtime/unsafe/memory.gr +24 -20
- package/runtime/unsafe/memory.md +27 -7
- package/runtime/unsafe/offsets.gr +36 -0
- package/runtime/unsafe/offsets.md +88 -0
- package/runtime/unsafe/panic.gr +28 -0
- package/runtime/unsafe/panic.md +14 -0
- package/runtime/unsafe/tags.md +32 -32
- package/runtime/unsafe/wasmf32.md +28 -28
- package/runtime/unsafe/wasmf64.md +28 -28
- package/runtime/unsafe/wasmi32.md +47 -47
- package/runtime/unsafe/wasmi64.md +50 -50
- package/runtime/utf8.gr +189 -0
- package/runtime/utf8.md +117 -0
- package/runtime/wasi.gr +4 -2
- package/runtime/wasi.md +147 -147
- package/set.gr +18 -11
- package/set.md +253 -247
- package/stack.gr +171 -2
- package/stack.md +371 -89
- package/string.gr +352 -557
- package/string.md +298 -255
- package/uint16.md +170 -170
- package/uint32.gr +25 -4
- package/uint32.md +249 -214
- package/uint64.gr +25 -5
- package/uint64.md +249 -214
- package/uint8.md +170 -170
- package/uri.gr +57 -53
- package/uri.md +88 -89
- package/wasi/file.gr +67 -59
- package/wasi/file.md +308 -308
- package/wasi/process.md +26 -26
- package/wasi/random.md +12 -12
- package/wasi/time.md +16 -16
- package/runtime/utils/printing.gr +0 -60
- package/runtime/utils/printing.md +0 -26
package/array.md
CHANGED
|
@@ -39,22 +39,22 @@ No other changes yet.
|
|
|
39
39
|
</details>
|
|
40
40
|
|
|
41
41
|
```grain
|
|
42
|
-
length
|
|
42
|
+
length: (array: Array<a>) => Number
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
Provides the length of the input array.
|
|
46
46
|
|
|
47
47
|
Parameters:
|
|
48
48
|
|
|
49
|
-
|param|type|description|
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
| param | type | description |
|
|
50
|
+
| ------- | ---------- | -------------------- |
|
|
51
|
+
| `array` | `Array<a>` | The array to inspect |
|
|
52
52
|
|
|
53
53
|
Returns:
|
|
54
54
|
|
|
55
|
-
|type|description|
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
| type | description |
|
|
56
|
+
| -------- | ----------------------------------- |
|
|
57
|
+
| `Number` | The number of elements in the array |
|
|
58
58
|
|
|
59
59
|
Examples:
|
|
60
60
|
|
|
@@ -70,7 +70,7 @@ No other changes yet.
|
|
|
70
70
|
</details>
|
|
71
71
|
|
|
72
72
|
```grain
|
|
73
|
-
make
|
|
73
|
+
make: (length: Number, item: a) => Array<a>
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
Creates a new array of the specified length with each element being
|
|
@@ -78,16 +78,16 @@ initialized with the given value.
|
|
|
78
78
|
|
|
79
79
|
Parameters:
|
|
80
80
|
|
|
81
|
-
|param|type|description|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
| param | type | description |
|
|
82
|
+
| -------- | -------- | -------------------------------- |
|
|
83
|
+
| `length` | `Number` | The length of the new array |
|
|
84
|
+
| `item` | `a` | The value to store at each index |
|
|
85
85
|
|
|
86
86
|
Returns:
|
|
87
87
|
|
|
88
|
-
|type|description|
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
| type | description |
|
|
89
|
+
| ---------- | ------------- |
|
|
90
|
+
| `Array<a>` | The new array |
|
|
91
91
|
|
|
92
92
|
Throws:
|
|
93
93
|
|
|
@@ -110,7 +110,7 @@ No other changes yet.
|
|
|
110
110
|
</details>
|
|
111
111
|
|
|
112
112
|
```grain
|
|
113
|
-
init
|
|
113
|
+
init: (length: Number, fn: (Number => a)) => Array<a>
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
Creates a new array of the specified length where each element is
|
|
@@ -119,16 +119,16 @@ is called with the index of each array element.
|
|
|
119
119
|
|
|
120
120
|
Parameters:
|
|
121
121
|
|
|
122
|
-
|param|type|description|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
| param | type | description |
|
|
123
|
+
| -------- | ------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
124
|
+
| `length` | `Number` | The length of the new array |
|
|
125
|
+
| `fn` | `Number => a` | The initializer function to call with each index, where the value returned will be used to initialize the element |
|
|
126
126
|
|
|
127
127
|
Returns:
|
|
128
128
|
|
|
129
|
-
|type|description|
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
| type | description |
|
|
130
|
+
| ---------- | ------------- |
|
|
131
|
+
| `Array<a>` | The new array |
|
|
132
132
|
|
|
133
133
|
Throws:
|
|
134
134
|
|
|
@@ -143,6 +143,53 @@ Examples:
|
|
|
143
143
|
Array.init(5, n => n + 3) == [> 3, 4, 5, 6, 7]
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
+
### Array.**tryInit**
|
|
147
|
+
|
|
148
|
+
<details disabled>
|
|
149
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
150
|
+
No other changes yet.
|
|
151
|
+
</details>
|
|
152
|
+
|
|
153
|
+
```grain
|
|
154
|
+
tryInit:
|
|
155
|
+
(length: Number, fn: (Number => Result<a, b>)) => Result<Array<a>, b>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Creates a new array where each element is initialized with the `Ok`
|
|
159
|
+
result value of an initializer function. The initializer is called with the
|
|
160
|
+
index of each element, and returns the new array if all calls to the
|
|
161
|
+
initializer succeed or the first error otherwise.
|
|
162
|
+
|
|
163
|
+
Parameters:
|
|
164
|
+
|
|
165
|
+
| param | type | description |
|
|
166
|
+
| -------- | ------------------------ | ----------------------------------------------------------------------------------------------------------------------- |
|
|
167
|
+
| `length` | `Number` | The length of the new array |
|
|
168
|
+
| `fn` | `Number => Result<a, b>` | The initializer function to call with each index, where the `Ok` value returned will be used to initialize each element |
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
|
|
172
|
+
| type | description |
|
|
173
|
+
| --------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
174
|
+
| `Result<Array<a>, b>` | `Ok(array)` if all elements were successfully initialized or `Err(error)` if the initializer function returned an error |
|
|
175
|
+
|
|
176
|
+
Throws:
|
|
177
|
+
|
|
178
|
+
`InvalidArgument(String)`
|
|
179
|
+
|
|
180
|
+
* When `length` is not an integer
|
|
181
|
+
* When `length` is negative
|
|
182
|
+
|
|
183
|
+
Examples:
|
|
184
|
+
|
|
185
|
+
```grain
|
|
186
|
+
Array.tryInit(5, n => Ok(n + 3)) == [> 3, 4, 5, 6, 7]
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
```grain
|
|
190
|
+
Array.tryInit(5, n => if (n == 1) Err("stop") else Ok(n)) == Err("stop")
|
|
191
|
+
```
|
|
192
|
+
|
|
146
193
|
### Array.**get**
|
|
147
194
|
|
|
148
195
|
<details>
|
|
@@ -158,7 +205,7 @@ Array.init(5, n => n + 3) == [> 3, 4, 5, 6, 7]
|
|
|
158
205
|
</details>
|
|
159
206
|
|
|
160
207
|
```grain
|
|
161
|
-
get
|
|
208
|
+
get: (index: Number, array: Array<a>) => a
|
|
162
209
|
```
|
|
163
210
|
|
|
164
211
|
An alias for normal syntactic array access, i.e. `array[n]`.
|
|
@@ -168,16 +215,16 @@ A negative index is treated as an offset from the end of the array.
|
|
|
168
215
|
|
|
169
216
|
Parameters:
|
|
170
217
|
|
|
171
|
-
|param|type|description|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
218
|
+
| param | type | description |
|
|
219
|
+
| ------- | ---------- | ------------------- |
|
|
220
|
+
| `index` | `Number` | The index to access |
|
|
221
|
+
| `array` | `Array<a>` | The array to access |
|
|
175
222
|
|
|
176
223
|
Returns:
|
|
177
224
|
|
|
178
|
-
|type|description|
|
|
179
|
-
|
|
180
|
-
|
|
225
|
+
| type | description |
|
|
226
|
+
| ---- | -------------------------- |
|
|
227
|
+
| `a` | The element from the array |
|
|
181
228
|
|
|
182
229
|
Throws:
|
|
183
230
|
|
|
@@ -207,7 +254,7 @@ Array.get(1, [> 1, 2, 3, 4, 5]) == 2
|
|
|
207
254
|
</details>
|
|
208
255
|
|
|
209
256
|
```grain
|
|
210
|
-
set
|
|
257
|
+
set: (index: Number, value: a, array: Array<a>) => Void
|
|
211
258
|
```
|
|
212
259
|
|
|
213
260
|
An alias for normal syntactic array set, i.e. `array[n] = value`.
|
|
@@ -217,11 +264,11 @@ A negative index is treated as an offset from the end of the array.
|
|
|
217
264
|
|
|
218
265
|
Parameters:
|
|
219
266
|
|
|
220
|
-
|param|type|description|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
267
|
+
| param | type | description |
|
|
268
|
+
| ------- | ---------- | ------------------- |
|
|
269
|
+
| `index` | `Number` | The index to update |
|
|
270
|
+
| `value` | `a` | The value to store |
|
|
271
|
+
| `array` | `Array<a>` | The array to update |
|
|
225
272
|
|
|
226
273
|
Throws:
|
|
227
274
|
|
|
@@ -246,7 +293,7 @@ No other changes yet.
|
|
|
246
293
|
</details>
|
|
247
294
|
|
|
248
295
|
```grain
|
|
249
|
-
append
|
|
296
|
+
append: (array1: Array<a>, array2: Array<a>) => Array<a>
|
|
250
297
|
```
|
|
251
298
|
|
|
252
299
|
Creates a new array with the elements of the first array followed by
|
|
@@ -254,16 +301,16 @@ the elements of the second array. This does not modify the arguments.
|
|
|
254
301
|
|
|
255
302
|
Parameters:
|
|
256
303
|
|
|
257
|
-
|param|type|description|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
304
|
+
| param | type | description |
|
|
305
|
+
| -------- | ---------- | ---------------------------------------------- |
|
|
306
|
+
| `array1` | `Array<a>` | The array containing elements to appear first |
|
|
307
|
+
| `array2` | `Array<a>` | The array containing elements to appear second |
|
|
261
308
|
|
|
262
309
|
Returns:
|
|
263
310
|
|
|
264
|
-
|type|description|
|
|
265
|
-
|
|
266
|
-
|
|
311
|
+
| type | description |
|
|
312
|
+
| ---------- | ---------------------------------------------------------------------------------- |
|
|
313
|
+
| `Array<a>` | The new array containing elements from `array1` followed by elements from `array2` |
|
|
267
314
|
|
|
268
315
|
Throws:
|
|
269
316
|
|
|
@@ -285,7 +332,7 @@ No other changes yet.
|
|
|
285
332
|
</details>
|
|
286
333
|
|
|
287
334
|
```grain
|
|
288
|
-
concat
|
|
335
|
+
concat: (arrays: List<Array<a>>) => Array<a>
|
|
289
336
|
```
|
|
290
337
|
|
|
291
338
|
Creates a single array containing the elements of all arrays in the
|
|
@@ -293,15 +340,15 @@ provided list. Does not modify any of the input arguments.
|
|
|
293
340
|
|
|
294
341
|
Parameters:
|
|
295
342
|
|
|
296
|
-
|param|type|description|
|
|
297
|
-
|
|
298
|
-
|
|
343
|
+
| param | type | description |
|
|
344
|
+
| -------- | ---------------- | --------------------------------------- |
|
|
345
|
+
| `arrays` | `List<Array<a>>` | A list containing all arrays to combine |
|
|
299
346
|
|
|
300
347
|
Returns:
|
|
301
348
|
|
|
302
|
-
|type|description|
|
|
303
|
-
|
|
304
|
-
|
|
349
|
+
| type | description |
|
|
350
|
+
| ---------- | ------------- |
|
|
351
|
+
| `Array<a>` | The new array |
|
|
305
352
|
|
|
306
353
|
Throws:
|
|
307
354
|
|
|
@@ -323,7 +370,7 @@ No other changes yet.
|
|
|
323
370
|
</details>
|
|
324
371
|
|
|
325
372
|
```grain
|
|
326
|
-
copy
|
|
373
|
+
copy: (array: Array<a>) => Array<a>
|
|
327
374
|
```
|
|
328
375
|
|
|
329
376
|
Produces a shallow copy of the input array. The new array contains the
|
|
@@ -331,15 +378,15 @@ same elements as the original.
|
|
|
331
378
|
|
|
332
379
|
Parameters:
|
|
333
380
|
|
|
334
|
-
|param|type|description|
|
|
335
|
-
|
|
336
|
-
|
|
381
|
+
| param | type | description |
|
|
382
|
+
| ------- | ---------- | ----------------- |
|
|
383
|
+
| `array` | `Array<a>` | The array to copy |
|
|
337
384
|
|
|
338
385
|
Returns:
|
|
339
386
|
|
|
340
|
-
|type|description|
|
|
341
|
-
|
|
342
|
-
|
|
387
|
+
| type | description |
|
|
388
|
+
| ---------- | ---------------------------------------------------- |
|
|
389
|
+
| `Array<a>` | The new array containing the elements from the input |
|
|
343
390
|
|
|
344
391
|
Examples:
|
|
345
392
|
|
|
@@ -355,18 +402,18 @@ No other changes yet.
|
|
|
355
402
|
</details>
|
|
356
403
|
|
|
357
404
|
```grain
|
|
358
|
-
cycle
|
|
405
|
+
cycle: (fn: (a => Void), n: Number, array: Array<a>) => Void
|
|
359
406
|
```
|
|
360
407
|
|
|
361
408
|
Iterates an array a given number of times, calling an iterator function on each element.
|
|
362
409
|
|
|
363
410
|
Parameters:
|
|
364
411
|
|
|
365
|
-
|param|type|description|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
412
|
+
| param | type | description |
|
|
413
|
+
| ------- | ----------- | ----------------------------------------------- |
|
|
414
|
+
| `fn` | `a => Void` | The iterator function to call with each element |
|
|
415
|
+
| `n` | `Number` | The number of times to iterate the given array |
|
|
416
|
+
| `array` | `Array<a>` | The array to iterate |
|
|
370
417
|
|
|
371
418
|
Examples:
|
|
372
419
|
|
|
@@ -391,17 +438,17 @@ assert str == "abcabc"
|
|
|
391
438
|
</details>
|
|
392
439
|
|
|
393
440
|
```grain
|
|
394
|
-
forEach
|
|
441
|
+
forEach: (fn: (a => Void), array: Array<a>) => Void
|
|
395
442
|
```
|
|
396
443
|
|
|
397
444
|
Iterates an array, calling an iterator function on each element.
|
|
398
445
|
|
|
399
446
|
Parameters:
|
|
400
447
|
|
|
401
|
-
|param|type|description|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
448
|
+
| param | type | description |
|
|
449
|
+
| ------- | ----------- | ----------------------------------------------- |
|
|
450
|
+
| `fn` | `a => Void` | The iterator function to call with each element |
|
|
451
|
+
| `array` | `Array<a>` | The array to iterate |
|
|
405
452
|
|
|
406
453
|
Examples:
|
|
407
454
|
|
|
@@ -426,7 +473,7 @@ assert str == "abc"
|
|
|
426
473
|
</details>
|
|
427
474
|
|
|
428
475
|
```grain
|
|
429
|
-
forEachi
|
|
476
|
+
forEachi: (fn: ((a, Number) => Void), array: Array<a>) => Void
|
|
430
477
|
```
|
|
431
478
|
|
|
432
479
|
Iterates an array, calling an iterator function on each element.
|
|
@@ -434,10 +481,10 @@ Also passes the index as the second argument to the function.
|
|
|
434
481
|
|
|
435
482
|
Parameters:
|
|
436
483
|
|
|
437
|
-
|param|type|description|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
484
|
+
| param | type | description |
|
|
485
|
+
| ------- | --------------------- | ----------------------------------------------- |
|
|
486
|
+
| `fn` | `(a, Number) => Void` | The iterator function to call with each element |
|
|
487
|
+
| `array` | `Array<a>` | The array to iterate |
|
|
441
488
|
|
|
442
489
|
Examples:
|
|
443
490
|
|
|
@@ -462,7 +509,7 @@ assert str == "a0b1c2"
|
|
|
462
509
|
</details>
|
|
463
510
|
|
|
464
511
|
```grain
|
|
465
|
-
map
|
|
512
|
+
map: (fn: (a => b), array: Array<a>) => Array<b>
|
|
466
513
|
```
|
|
467
514
|
|
|
468
515
|
Produces a new array initialized with the results of a mapper function
|
|
@@ -470,16 +517,16 @@ called on each element of the input array.
|
|
|
470
517
|
|
|
471
518
|
Parameters:
|
|
472
519
|
|
|
473
|
-
|param|type|description|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
520
|
+
| param | type | description |
|
|
521
|
+
| ------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
522
|
+
| `fn` | `a => b` | The mapper function to call on each element, where the value returned will be used to initialize the element in the new array |
|
|
523
|
+
| `array` | `Array<a>` | The array to iterate |
|
|
477
524
|
|
|
478
525
|
Returns:
|
|
479
526
|
|
|
480
|
-
|type|description|
|
|
481
|
-
|
|
482
|
-
|
|
527
|
+
| type | description |
|
|
528
|
+
| ---------- | -------------------------------- |
|
|
529
|
+
| `Array<b>` | The new array with mapped values |
|
|
483
530
|
|
|
484
531
|
Examples:
|
|
485
532
|
|
|
@@ -495,7 +542,7 @@ No other changes yet.
|
|
|
495
542
|
</details>
|
|
496
543
|
|
|
497
544
|
```grain
|
|
498
|
-
mapi
|
|
545
|
+
mapi: (fn: ((a, Number) => b), array: Array<a>) => Array<b>
|
|
499
546
|
```
|
|
500
547
|
|
|
501
548
|
Produces a new array initialized with the results of a mapper function
|
|
@@ -503,16 +550,16 @@ called on each element of the input array and its index.
|
|
|
503
550
|
|
|
504
551
|
Parameters:
|
|
505
552
|
|
|
506
|
-
|param|type|description|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
553
|
+
| param | type | description |
|
|
554
|
+
| ------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
555
|
+
| `fn` | `(a, Number) => b` | The mapper function to call on each element, where the value returned will be used to initialize the element in the new array |
|
|
556
|
+
| `array` | `Array<a>` | The array to iterate |
|
|
510
557
|
|
|
511
558
|
Returns:
|
|
512
559
|
|
|
513
|
-
|type|description|
|
|
514
|
-
|
|
515
|
-
|
|
560
|
+
| type | description |
|
|
561
|
+
| ---------- | -------------------------------- |
|
|
562
|
+
| `Array<b>` | The new array with mapped values |
|
|
516
563
|
|
|
517
564
|
Examples:
|
|
518
565
|
|
|
@@ -528,7 +575,7 @@ No other changes yet.
|
|
|
528
575
|
</details>
|
|
529
576
|
|
|
530
577
|
```grain
|
|
531
|
-
reduce
|
|
578
|
+
reduce: (fn: ((a, b) => a), initial: a, array: Array<b>) => a
|
|
532
579
|
```
|
|
533
580
|
|
|
534
581
|
Combines all elements of an array using a reducer function,
|
|
@@ -541,17 +588,17 @@ returned. The accumulator starts with value `initial`.
|
|
|
541
588
|
|
|
542
589
|
Parameters:
|
|
543
590
|
|
|
544
|
-
|param|type|description|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
591
|
+
| param | type | description |
|
|
592
|
+
| --------- | ------------- | --------------------------------------------------------------------------------------------------------- |
|
|
593
|
+
| `fn` | `(a, b) => a` | The reducer function to call on each element, where the value returned will be the next accumulator value |
|
|
594
|
+
| `initial` | `a` | The initial value to use for the accumulator on the first iteration |
|
|
595
|
+
| `array` | `Array<b>` | The array to iterate |
|
|
549
596
|
|
|
550
597
|
Returns:
|
|
551
598
|
|
|
552
|
-
|type|description|
|
|
553
|
-
|
|
554
|
-
|
|
599
|
+
| type | description |
|
|
600
|
+
| ---- | ---------------------------------------- |
|
|
601
|
+
| `a` | The final accumulator returned from `fn` |
|
|
555
602
|
|
|
556
603
|
Examples:
|
|
557
604
|
|
|
@@ -571,7 +618,7 @@ No other changes yet.
|
|
|
571
618
|
</details>
|
|
572
619
|
|
|
573
620
|
```grain
|
|
574
|
-
reduceRight
|
|
621
|
+
reduceRight: (fn: ((a, b) => b), initial: b, array: Array<a>) => b
|
|
575
622
|
```
|
|
576
623
|
|
|
577
624
|
Combines all elements of an array using a reducer function,
|
|
@@ -584,17 +631,17 @@ returned. The accumulator starts with value `initial`.
|
|
|
584
631
|
|
|
585
632
|
Parameters:
|
|
586
633
|
|
|
587
|
-
|param|type|description|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
634
|
+
| param | type | description |
|
|
635
|
+
| --------- | ------------- | --------------------------------------------------------------------------------------------------------- |
|
|
636
|
+
| `fn` | `(a, b) => b` | The reducer function to call on each element, where the value returned will be the next accumulator value |
|
|
637
|
+
| `initial` | `b` | The initial value to use for the accumulator on the first iteration |
|
|
638
|
+
| `array` | `Array<a>` | The array to iterate |
|
|
592
639
|
|
|
593
640
|
Returns:
|
|
594
641
|
|
|
595
|
-
|type|description|
|
|
596
|
-
|
|
597
|
-
|
|
642
|
+
| type | description |
|
|
643
|
+
| ---- | ---------------------------------------- |
|
|
644
|
+
| `b` | The final accumulator returned from `fn` |
|
|
598
645
|
|
|
599
646
|
Examples:
|
|
600
647
|
|
|
@@ -610,7 +657,7 @@ No other changes yet.
|
|
|
610
657
|
</details>
|
|
611
658
|
|
|
612
659
|
```grain
|
|
613
|
-
reducei
|
|
660
|
+
reducei: (fn: ((a, b, Number) => a), initial: a, array: Array<b>) => a
|
|
614
661
|
```
|
|
615
662
|
|
|
616
663
|
Combines all elements of an array using a reducer function,
|
|
@@ -624,17 +671,17 @@ starts with value `initial`.
|
|
|
624
671
|
|
|
625
672
|
Parameters:
|
|
626
673
|
|
|
627
|
-
|param|type|description|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
674
|
+
| param | type | description |
|
|
675
|
+
| --------- | --------------------- | --------------------------------------------------------------------------------------------------------- |
|
|
676
|
+
| `fn` | `(a, b, Number) => a` | The reducer function to call on each element, where the value returned will be the next accumulator value |
|
|
677
|
+
| `initial` | `a` | The initial value to use for the accumulator on the first iteration |
|
|
678
|
+
| `array` | `Array<b>` | The array to iterate |
|
|
632
679
|
|
|
633
680
|
Returns:
|
|
634
681
|
|
|
635
|
-
|type|description|
|
|
636
|
-
|
|
637
|
-
|
|
682
|
+
| type | description |
|
|
683
|
+
| ---- | ---------------------------------------- |
|
|
684
|
+
| `a` | The final accumulator returned from `fn` |
|
|
638
685
|
|
|
639
686
|
Examples:
|
|
640
687
|
|
|
@@ -657,7 +704,7 @@ No other changes yet.
|
|
|
657
704
|
</details>
|
|
658
705
|
|
|
659
706
|
```grain
|
|
660
|
-
flatMap
|
|
707
|
+
flatMap: (fn: (b => Array<a>), array: Array<b>) => Array<a>
|
|
661
708
|
```
|
|
662
709
|
|
|
663
710
|
Produces a new array by calling a function on each element
|
|
@@ -667,16 +714,16 @@ of all results.
|
|
|
667
714
|
|
|
668
715
|
Parameters:
|
|
669
716
|
|
|
670
|
-
|param|type|description|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
717
|
+
| param | type | description |
|
|
718
|
+
| ------- | --------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
719
|
+
| `fn` | `b => Array<a>` | The function to be called on each element, where the value returned will be an array that gets appended to the new array |
|
|
720
|
+
| `array` | `Array<b>` | The array to iterate |
|
|
674
721
|
|
|
675
722
|
Returns:
|
|
676
723
|
|
|
677
|
-
|type|description|
|
|
678
|
-
|
|
679
|
-
|
|
724
|
+
| type | description |
|
|
725
|
+
| ---------- | ------------- |
|
|
726
|
+
| `Array<a>` | The new array |
|
|
680
727
|
|
|
681
728
|
Throws:
|
|
682
729
|
|
|
@@ -698,7 +745,7 @@ No other changes yet.
|
|
|
698
745
|
</details>
|
|
699
746
|
|
|
700
747
|
```grain
|
|
701
|
-
every
|
|
748
|
+
every: (fn: (a => Bool), array: Array<a>) => Bool
|
|
702
749
|
```
|
|
703
750
|
|
|
704
751
|
Checks that the given condition is satisfied for all
|
|
@@ -706,16 +753,16 @@ elements in the input array.
|
|
|
706
753
|
|
|
707
754
|
Parameters:
|
|
708
755
|
|
|
709
|
-
|param|type|description|
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
756
|
+
| param | type | description |
|
|
757
|
+
| ------- | ----------- | --------------------------------------------------------------------------------------------------------------- |
|
|
758
|
+
| `fn` | `a => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
759
|
+
| `array` | `Array<a>` | The array to check |
|
|
713
760
|
|
|
714
761
|
Returns:
|
|
715
762
|
|
|
716
|
-
|type|description|
|
|
717
|
-
|
|
718
|
-
|
|
763
|
+
| type | description |
|
|
764
|
+
| ------ | ----------------------------------------------------------------- |
|
|
765
|
+
| `Bool` | `true` if all elements satisfy the condition or `false` otherwise |
|
|
719
766
|
|
|
720
767
|
Examples:
|
|
721
768
|
|
|
@@ -735,7 +782,7 @@ No other changes yet.
|
|
|
735
782
|
</details>
|
|
736
783
|
|
|
737
784
|
```grain
|
|
738
|
-
some
|
|
785
|
+
some: (fn: (a => Bool), array: Array<a>) => Bool
|
|
739
786
|
```
|
|
740
787
|
|
|
741
788
|
Checks that the given condition is satisfied **at least
|
|
@@ -743,16 +790,16 @@ once** by an element in the input array.
|
|
|
743
790
|
|
|
744
791
|
Parameters:
|
|
745
792
|
|
|
746
|
-
|param|type|description|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
793
|
+
| param | type | description |
|
|
794
|
+
| ------- | ----------- | --------------------------------------------------------------------------------------------------------------- |
|
|
795
|
+
| `fn` | `a => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
796
|
+
| `array` | `Array<a>` | The array to iterate |
|
|
750
797
|
|
|
751
798
|
Returns:
|
|
752
799
|
|
|
753
|
-
|type|description|
|
|
754
|
-
|
|
755
|
-
|
|
800
|
+
| type | description |
|
|
801
|
+
| ------ | ------------------------------------------------------------------------- |
|
|
802
|
+
| `Bool` | `true` if one or more elements satisfy the condition or `false` otherwise |
|
|
756
803
|
|
|
757
804
|
Examples:
|
|
758
805
|
|
|
@@ -776,17 +823,17 @@ No other changes yet.
|
|
|
776
823
|
</details>
|
|
777
824
|
|
|
778
825
|
```grain
|
|
779
|
-
fill
|
|
826
|
+
fill: (value: a, array: Array<a>) => Void
|
|
780
827
|
```
|
|
781
828
|
|
|
782
829
|
Replaces all elements in an array with the new value provided.
|
|
783
830
|
|
|
784
831
|
Parameters:
|
|
785
832
|
|
|
786
|
-
|param|type|description|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
833
|
+
| param | type | description |
|
|
834
|
+
| ------- | ---------- | -------------------------------- |
|
|
835
|
+
| `value` | `a` | The value replacing each element |
|
|
836
|
+
| `array` | `Array<a>` | The array to update |
|
|
790
837
|
|
|
791
838
|
Examples:
|
|
792
839
|
|
|
@@ -804,7 +851,7 @@ No other changes yet.
|
|
|
804
851
|
</details>
|
|
805
852
|
|
|
806
853
|
```grain
|
|
807
|
-
fillRange
|
|
854
|
+
fillRange: (value: a, start: Number, stop: Number, array: Array<a>) => Void
|
|
808
855
|
```
|
|
809
856
|
|
|
810
857
|
Replaces all elements in the provided index range in the array
|
|
@@ -812,12 +859,12 @@ with the new value provided. Fails if the index is out-of-bounds.
|
|
|
812
859
|
|
|
813
860
|
Parameters:
|
|
814
861
|
|
|
815
|
-
|param|type|description|
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
862
|
+
| param | type | description |
|
|
863
|
+
| ------- | ---------- | ---------------------------------------------------- |
|
|
864
|
+
| `value` | `a` | The value replacing each element between the indexes |
|
|
865
|
+
| `start` | `Number` | The index to begin replacement |
|
|
866
|
+
| `stop` | `Number` | The (exclusive) index to end replacement |
|
|
867
|
+
| `array` | `Array<a>` | The array to update |
|
|
821
868
|
|
|
822
869
|
Throws:
|
|
823
870
|
|
|
@@ -842,22 +889,22 @@ No other changes yet.
|
|
|
842
889
|
</details>
|
|
843
890
|
|
|
844
891
|
```grain
|
|
845
|
-
reverse
|
|
892
|
+
reverse: (array: Array<a>) => Array<a>
|
|
846
893
|
```
|
|
847
894
|
|
|
848
895
|
Creates a new array with all elements in reverse order.
|
|
849
896
|
|
|
850
897
|
Parameters:
|
|
851
898
|
|
|
852
|
-
|param|type|description|
|
|
853
|
-
|
|
854
|
-
|
|
899
|
+
| param | type | description |
|
|
900
|
+
| ------- | ---------- | -------------------- |
|
|
901
|
+
| `array` | `Array<a>` | The array to reverse |
|
|
855
902
|
|
|
856
903
|
Returns:
|
|
857
904
|
|
|
858
|
-
|type|description|
|
|
859
|
-
|
|
860
|
-
|
|
905
|
+
| type | description |
|
|
906
|
+
| ---------- | ------------- |
|
|
907
|
+
| `Array<a>` | The new array |
|
|
861
908
|
|
|
862
909
|
Examples:
|
|
863
910
|
|
|
@@ -873,22 +920,22 @@ No other changes yet.
|
|
|
873
920
|
</details>
|
|
874
921
|
|
|
875
922
|
```grain
|
|
876
|
-
toList
|
|
923
|
+
toList: (array: Array<a>) => List<a>
|
|
877
924
|
```
|
|
878
925
|
|
|
879
926
|
Converts the input array to a list.
|
|
880
927
|
|
|
881
928
|
Parameters:
|
|
882
929
|
|
|
883
|
-
|param|type|description|
|
|
884
|
-
|
|
885
|
-
|
|
930
|
+
| param | type | description |
|
|
931
|
+
| ------- | ---------- | -------------------- |
|
|
932
|
+
| `array` | `Array<a>` | The array to convert |
|
|
886
933
|
|
|
887
934
|
Returns:
|
|
888
935
|
|
|
889
|
-
|type|description|
|
|
890
|
-
|
|
891
|
-
|
|
936
|
+
| type | description |
|
|
937
|
+
| --------- | ----------------------------------------------- |
|
|
938
|
+
| `List<a>` | The list containing all elements from the array |
|
|
892
939
|
|
|
893
940
|
Examples:
|
|
894
941
|
|
|
@@ -904,22 +951,22 @@ No other changes yet.
|
|
|
904
951
|
</details>
|
|
905
952
|
|
|
906
953
|
```grain
|
|
907
|
-
fromList
|
|
954
|
+
fromList: (list: List<a>) => Array<a>
|
|
908
955
|
```
|
|
909
956
|
|
|
910
957
|
Converts the input list to an array.
|
|
911
958
|
|
|
912
959
|
Parameters:
|
|
913
960
|
|
|
914
|
-
|param|type|description|
|
|
915
|
-
|
|
916
|
-
|
|
961
|
+
| param | type | description |
|
|
962
|
+
| ------ | --------- | ------------------- |
|
|
963
|
+
| `list` | `List<a>` | The list to convert |
|
|
917
964
|
|
|
918
965
|
Returns:
|
|
919
966
|
|
|
920
|
-
|type|description|
|
|
921
|
-
|
|
922
|
-
|
|
967
|
+
| type | description |
|
|
968
|
+
| ---------- | ----------------------------------------------- |
|
|
969
|
+
| `Array<a>` | The array containing all elements from the list |
|
|
923
970
|
|
|
924
971
|
Examples:
|
|
925
972
|
|
|
@@ -935,7 +982,7 @@ No other changes yet.
|
|
|
935
982
|
</details>
|
|
936
983
|
|
|
937
984
|
```grain
|
|
938
|
-
contains
|
|
985
|
+
contains: (search: a, array: Array<a>) => Bool
|
|
939
986
|
```
|
|
940
987
|
|
|
941
988
|
Checks if the value is an element of the input array.
|
|
@@ -943,16 +990,16 @@ Uses the generic `==` structural equality operator.
|
|
|
943
990
|
|
|
944
991
|
Parameters:
|
|
945
992
|
|
|
946
|
-
|param|type|description|
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
993
|
+
| param | type | description |
|
|
994
|
+
| -------- | ---------- | -------------------- |
|
|
995
|
+
| `search` | `a` | The value to compare |
|
|
996
|
+
| `array` | `Array<a>` | The array to inspect |
|
|
950
997
|
|
|
951
998
|
Returns:
|
|
952
999
|
|
|
953
|
-
|type|description|
|
|
954
|
-
|
|
955
|
-
|
|
1000
|
+
| type | description |
|
|
1001
|
+
| ------ | ------------------------------------------------------------ |
|
|
1002
|
+
| `Bool` | `true` if the value exists in the array or `false` otherwise |
|
|
956
1003
|
|
|
957
1004
|
Examples:
|
|
958
1005
|
|
|
@@ -972,23 +1019,23 @@ No other changes yet.
|
|
|
972
1019
|
</details>
|
|
973
1020
|
|
|
974
1021
|
```grain
|
|
975
|
-
find
|
|
1022
|
+
find: (fn: (a => Bool), array: Array<a>) => Option<a>
|
|
976
1023
|
```
|
|
977
1024
|
|
|
978
1025
|
Finds the first element in an array that satisfies the given condition.
|
|
979
1026
|
|
|
980
1027
|
Parameters:
|
|
981
1028
|
|
|
982
|
-
|param|type|description|
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1029
|
+
| param | type | description |
|
|
1030
|
+
| ------- | ----------- | --------------------------------------------------------------------------------------------------------------- |
|
|
1031
|
+
| `fn` | `a => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
1032
|
+
| `array` | `Array<a>` | The array to search |
|
|
986
1033
|
|
|
987
1034
|
Returns:
|
|
988
1035
|
|
|
989
|
-
|type|description|
|
|
990
|
-
|
|
991
|
-
|
|
1036
|
+
| type | description |
|
|
1037
|
+
| ----------- | -------------------------------------------------------------------- |
|
|
1038
|
+
| `Option<a>` | `Some(element)` containing the first value found or `None` otherwise |
|
|
992
1039
|
|
|
993
1040
|
Examples:
|
|
994
1041
|
|
|
@@ -1012,23 +1059,23 @@ No other changes yet.
|
|
|
1012
1059
|
</details>
|
|
1013
1060
|
|
|
1014
1061
|
```grain
|
|
1015
|
-
findIndex
|
|
1062
|
+
findIndex: (fn: (a => Bool), array: Array<a>) => Option<Number>
|
|
1016
1063
|
```
|
|
1017
1064
|
|
|
1018
1065
|
Finds the first index in an array where the element satisfies the given condition.
|
|
1019
1066
|
|
|
1020
1067
|
Parameters:
|
|
1021
1068
|
|
|
1022
|
-
|param|type|description|
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1069
|
+
| param | type | description |
|
|
1070
|
+
| ------- | ----------- | --------------------------------------------------------------------------------------------------------------- |
|
|
1071
|
+
| `fn` | `a => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
1072
|
+
| `array` | `Array<a>` | The array to search |
|
|
1026
1073
|
|
|
1027
1074
|
Returns:
|
|
1028
1075
|
|
|
1029
|
-
|type|description|
|
|
1030
|
-
|
|
1031
|
-
|
|
1076
|
+
| type | description |
|
|
1077
|
+
| ---------------- | --------------------------------------------------------------------------------- |
|
|
1078
|
+
| `Option<Number>` | `Some(index)` containing the index of the first element found or `None` otherwise |
|
|
1032
1079
|
|
|
1033
1080
|
Examples:
|
|
1034
1081
|
|
|
@@ -1052,7 +1099,7 @@ No other changes yet.
|
|
|
1052
1099
|
</details>
|
|
1053
1100
|
|
|
1054
1101
|
```grain
|
|
1055
|
-
product
|
|
1102
|
+
product: (array1: Array<a>, array2: Array<b>) => Array<(a, b)>
|
|
1056
1103
|
```
|
|
1057
1104
|
|
|
1058
1105
|
Combines two arrays into a Cartesian product of tuples containing
|
|
@@ -1060,16 +1107,16 @@ all ordered pairs `(a, b)`.
|
|
|
1060
1107
|
|
|
1061
1108
|
Parameters:
|
|
1062
1109
|
|
|
1063
|
-
|param|type|description|
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1110
|
+
| param | type | description |
|
|
1111
|
+
| -------- | ---------- | -------------------------------------------------------- |
|
|
1112
|
+
| `array1` | `Array<a>` | The array to provide values for the first tuple element |
|
|
1113
|
+
| `array2` | `Array<b>` | The array to provide values for the second tuple element |
|
|
1067
1114
|
|
|
1068
1115
|
Returns:
|
|
1069
1116
|
|
|
1070
|
-
|type|description|
|
|
1071
|
-
|
|
1072
|
-
|
|
1117
|
+
| type | description |
|
|
1118
|
+
| --------------- | ---------------------------------------------- |
|
|
1119
|
+
| `Array<(a, b)>` | The new array containing all pairs of `(a, b)` |
|
|
1073
1120
|
|
|
1074
1121
|
Throws:
|
|
1075
1122
|
|
|
@@ -1091,23 +1138,23 @@ No other changes yet.
|
|
|
1091
1138
|
</details>
|
|
1092
1139
|
|
|
1093
1140
|
```grain
|
|
1094
|
-
count
|
|
1141
|
+
count: (fn: (a => Bool), array: Array<a>) => Number
|
|
1095
1142
|
```
|
|
1096
1143
|
|
|
1097
1144
|
Counts the number of elements in an array that satisfy the given condition.
|
|
1098
1145
|
|
|
1099
1146
|
Parameters:
|
|
1100
1147
|
|
|
1101
|
-
|param|type|description|
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1148
|
+
| param | type | description |
|
|
1149
|
+
| ------- | ----------- | --------------------------------------------------------------------------------------------------------------- |
|
|
1150
|
+
| `fn` | `a => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
1151
|
+
| `array` | `Array<a>` | The array to iterate |
|
|
1105
1152
|
|
|
1106
1153
|
Returns:
|
|
1107
1154
|
|
|
1108
|
-
|type|description|
|
|
1109
|
-
|
|
1110
|
-
|
|
1155
|
+
| type | description |
|
|
1156
|
+
| -------- | ------------------------------------------------------- |
|
|
1157
|
+
| `Number` | The total number of elements that satisfy the condition |
|
|
1111
1158
|
|
|
1112
1159
|
Examples:
|
|
1113
1160
|
|
|
@@ -1123,7 +1170,7 @@ No other changes yet.
|
|
|
1123
1170
|
</details>
|
|
1124
1171
|
|
|
1125
1172
|
```grain
|
|
1126
|
-
counti
|
|
1173
|
+
counti: (fn: ((a, Number) => Bool), array: Array<a>) => Number
|
|
1127
1174
|
```
|
|
1128
1175
|
|
|
1129
1176
|
Counts the number of elements in an array that satisfy the
|
|
@@ -1131,16 +1178,16 @@ given condition. Also passes the index to the function.
|
|
|
1131
1178
|
|
|
1132
1179
|
Parameters:
|
|
1133
1180
|
|
|
1134
|
-
|param|type|description|
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1181
|
+
| param | type | description |
|
|
1182
|
+
| ------- | --------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
1183
|
+
| `fn` | `(a, Number) => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
1184
|
+
| `array` | `Array<a>` | The array to iterate |
|
|
1138
1185
|
|
|
1139
1186
|
Returns:
|
|
1140
1187
|
|
|
1141
|
-
|type|description|
|
|
1142
|
-
|
|
1143
|
-
|
|
1188
|
+
| type | description |
|
|
1189
|
+
| -------- | ------------------------------------------------------- |
|
|
1190
|
+
| `Number` | The total number of elements that satisfy the condition |
|
|
1144
1191
|
|
|
1145
1192
|
Examples:
|
|
1146
1193
|
|
|
@@ -1160,7 +1207,7 @@ No other changes yet.
|
|
|
1160
1207
|
</details>
|
|
1161
1208
|
|
|
1162
1209
|
```grain
|
|
1163
|
-
filter
|
|
1210
|
+
filter: (fn: (a => Bool), array: Array<a>) => Array<a>
|
|
1164
1211
|
```
|
|
1165
1212
|
|
|
1166
1213
|
Produces a new array by calling a function on each element of
|
|
@@ -1169,16 +1216,16 @@ the condition.
|
|
|
1169
1216
|
|
|
1170
1217
|
Parameters:
|
|
1171
1218
|
|
|
1172
|
-
|param|type|description|
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1219
|
+
| param | type | description |
|
|
1220
|
+
| ------- | ----------- | --------------------------------------------------------------------------------------------------------------- |
|
|
1221
|
+
| `fn` | `a => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
1222
|
+
| `array` | `Array<a>` | The array to iterate |
|
|
1176
1223
|
|
|
1177
1224
|
Returns:
|
|
1178
1225
|
|
|
1179
|
-
|type|description|
|
|
1180
|
-
|
|
1181
|
-
|
|
1226
|
+
| type | description |
|
|
1227
|
+
| ---------- | ------------------------------------------------------------ |
|
|
1228
|
+
| `Array<a>` | The new array containing elements where `fn` returned `true` |
|
|
1182
1229
|
|
|
1183
1230
|
Examples:
|
|
1184
1231
|
|
|
@@ -1194,7 +1241,7 @@ No other changes yet.
|
|
|
1194
1241
|
</details>
|
|
1195
1242
|
|
|
1196
1243
|
```grain
|
|
1197
|
-
filteri
|
|
1244
|
+
filteri: (fn: ((a, Number) => Bool), array: Array<a>) => Array<a>
|
|
1198
1245
|
```
|
|
1199
1246
|
|
|
1200
1247
|
Produces a new array by calling a function on each element of
|
|
@@ -1203,16 +1250,16 @@ the condition. Also passes the index to the function.
|
|
|
1203
1250
|
|
|
1204
1251
|
Parameters:
|
|
1205
1252
|
|
|
1206
|
-
|param|type|description|
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1253
|
+
| param | type | description |
|
|
1254
|
+
| ------- | --------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
1255
|
+
| `fn` | `(a, Number) => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
1256
|
+
| `array` | `Array<a>` | The array to iterate |
|
|
1210
1257
|
|
|
1211
1258
|
Returns:
|
|
1212
1259
|
|
|
1213
|
-
|type|description|
|
|
1214
|
-
|
|
1215
|
-
|
|
1260
|
+
| type | description |
|
|
1261
|
+
| ---------- | ------------------------------------------------------------ |
|
|
1262
|
+
| `Array<a>` | The new array containing elements where `fn` returned `true` |
|
|
1216
1263
|
|
|
1217
1264
|
Examples:
|
|
1218
1265
|
|
|
@@ -1232,7 +1279,7 @@ No other changes yet.
|
|
|
1232
1279
|
</details>
|
|
1233
1280
|
|
|
1234
1281
|
```grain
|
|
1235
|
-
unique
|
|
1282
|
+
unique: (array: Array<a>) => Array<a>
|
|
1236
1283
|
```
|
|
1237
1284
|
|
|
1238
1285
|
Produces a new array with any duplicates removed.
|
|
@@ -1240,15 +1287,15 @@ Uses the generic `==` structural equality operator.
|
|
|
1240
1287
|
|
|
1241
1288
|
Parameters:
|
|
1242
1289
|
|
|
1243
|
-
|param|type|description|
|
|
1244
|
-
|
|
1245
|
-
|
|
1290
|
+
| param | type | description |
|
|
1291
|
+
| ------- | ---------- | ------------------- |
|
|
1292
|
+
| `array` | `Array<a>` | The array to filter |
|
|
1246
1293
|
|
|
1247
1294
|
Returns:
|
|
1248
1295
|
|
|
1249
|
-
|type|description|
|
|
1250
|
-
|
|
1251
|
-
|
|
1296
|
+
| type | description |
|
|
1297
|
+
| ---------- | ------------------------------------- |
|
|
1298
|
+
| `Array<a>` | The new array with only unique values |
|
|
1252
1299
|
|
|
1253
1300
|
Examples:
|
|
1254
1301
|
|
|
@@ -1271,7 +1318,7 @@ Array.unique([> 1, 2, 1, 2, 3, 1]) == [> 1, 2, 3]
|
|
|
1271
1318
|
</details>
|
|
1272
1319
|
|
|
1273
1320
|
```grain
|
|
1274
|
-
zip
|
|
1321
|
+
zip: (array1: Array<a>, array2: Array<b>) => Array<(a, b)>
|
|
1275
1322
|
```
|
|
1276
1323
|
|
|
1277
1324
|
Produces a new array filled with tuples of elements from both given arrays.
|
|
@@ -1280,16 +1327,16 @@ will contain the second item of each array, and so on.
|
|
|
1280
1327
|
|
|
1281
1328
|
Parameters:
|
|
1282
1329
|
|
|
1283
|
-
|param|type|description|
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1330
|
+
| param | type | description |
|
|
1331
|
+
| -------- | ---------- | -------------------------------------------------------- |
|
|
1332
|
+
| `array1` | `Array<a>` | The array to provide values for the first tuple element |
|
|
1333
|
+
| `array2` | `Array<b>` | The array to provide values for the second tuple element |
|
|
1287
1334
|
|
|
1288
1335
|
Returns:
|
|
1289
1336
|
|
|
1290
|
-
|type|description|
|
|
1291
|
-
|
|
1292
|
-
|
|
1337
|
+
| type | description |
|
|
1338
|
+
| --------------- | -------------------------------------------------- |
|
|
1339
|
+
| `Array<(a, b)>` | The new array containing indexed pairs of `(a, b)` |
|
|
1293
1340
|
|
|
1294
1341
|
Throws:
|
|
1295
1342
|
|
|
@@ -1311,7 +1358,7 @@ No other changes yet.
|
|
|
1311
1358
|
</details>
|
|
1312
1359
|
|
|
1313
1360
|
```grain
|
|
1314
|
-
zipWith
|
|
1361
|
+
zipWith: (fn: ((a, b) => c), array1: Array<a>, array2: Array<b>) => Array<c>
|
|
1315
1362
|
```
|
|
1316
1363
|
|
|
1317
1364
|
Produces a new array filled with elements defined by applying a function on
|
|
@@ -1325,17 +1372,17 @@ array to have the length of the smaller array.
|
|
|
1325
1372
|
|
|
1326
1373
|
Parameters:
|
|
1327
1374
|
|
|
1328
|
-
|param|type|description|
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1375
|
+
| param | type | description |
|
|
1376
|
+
| -------- | ------------- | ----------------------------------------------------------------------------------- |
|
|
1377
|
+
| `fn` | `(a, b) => c` | The function to apply to pairs of elements |
|
|
1378
|
+
| `array1` | `Array<a>` | The array whose elements will each be passed to the function as the first argument |
|
|
1379
|
+
| `array2` | `Array<b>` | The array whose elements will each be passed to the function as the second argument |
|
|
1333
1380
|
|
|
1334
1381
|
Returns:
|
|
1335
1382
|
|
|
1336
|
-
|type|description|
|
|
1337
|
-
|
|
1338
|
-
|
|
1383
|
+
| type | description |
|
|
1384
|
+
| ---------- | ----------------------------------------------------------------------------------------------------- |
|
|
1385
|
+
| `Array<c>` | The new array containing elements derived from applying the function to pairs of input array elements |
|
|
1339
1386
|
|
|
1340
1387
|
Throws:
|
|
1341
1388
|
|
|
@@ -1361,22 +1408,22 @@ No other changes yet.
|
|
|
1361
1408
|
</details>
|
|
1362
1409
|
|
|
1363
1410
|
```grain
|
|
1364
|
-
unzip
|
|
1411
|
+
unzip: (array: Array<(a, b)>) => (Array<a>, Array<b>)
|
|
1365
1412
|
```
|
|
1366
1413
|
|
|
1367
1414
|
Produces two arrays by splitting apart an array of tuples.
|
|
1368
1415
|
|
|
1369
1416
|
Parameters:
|
|
1370
1417
|
|
|
1371
|
-
|param|type|description|
|
|
1372
|
-
|
|
1373
|
-
|
|
1418
|
+
| param | type | description |
|
|
1419
|
+
| ------- | --------------- | ---------------------------- |
|
|
1420
|
+
| `array` | `Array<(a, b)>` | The array of tuples to split |
|
|
1374
1421
|
|
|
1375
1422
|
Returns:
|
|
1376
1423
|
|
|
1377
|
-
|type|description|
|
|
1378
|
-
|
|
1379
|
-
|
|
1424
|
+
| type | description |
|
|
1425
|
+
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
1426
|
+
| `(Array<a>, Array<b>)` | An array containing all elements from the first tuple element, and an array containing all elements from the second tuple element |
|
|
1380
1427
|
|
|
1381
1428
|
Examples:
|
|
1382
1429
|
|
|
@@ -1392,23 +1439,23 @@ No other changes yet.
|
|
|
1392
1439
|
</details>
|
|
1393
1440
|
|
|
1394
1441
|
```grain
|
|
1395
|
-
join
|
|
1442
|
+
join: (separator: String, items: Array<String>) => String
|
|
1396
1443
|
```
|
|
1397
1444
|
|
|
1398
1445
|
Concatenates an array of strings into a single string, separated by a separator string.
|
|
1399
1446
|
|
|
1400
1447
|
Parameters:
|
|
1401
1448
|
|
|
1402
|
-
|param|type|description|
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1449
|
+
| param | type | description |
|
|
1450
|
+
| ----------- | --------------- | --------------------------------------------------- |
|
|
1451
|
+
| `separator` | `String` | The separator to insert between items in the string |
|
|
1452
|
+
| `items` | `Array<String>` | The input strings |
|
|
1406
1453
|
|
|
1407
1454
|
Returns:
|
|
1408
1455
|
|
|
1409
|
-
|type|description|
|
|
1410
|
-
|
|
1411
|
-
|
|
1456
|
+
| type | description |
|
|
1457
|
+
| -------- | ----------------------- |
|
|
1458
|
+
| `String` | The concatenated string |
|
|
1412
1459
|
|
|
1413
1460
|
Examples:
|
|
1414
1461
|
|
|
@@ -1431,7 +1478,7 @@ Array.join(", ", [> "a", "b", "c"]) == "a, b, c"
|
|
|
1431
1478
|
</details>
|
|
1432
1479
|
|
|
1433
1480
|
```grain
|
|
1434
|
-
slice
|
|
1481
|
+
slice: (start: Number, ?end: Number, array: Array<a>) => Array<a>
|
|
1435
1482
|
```
|
|
1436
1483
|
|
|
1437
1484
|
Slices an array given zero-based start and end indexes. The value
|
|
@@ -1442,17 +1489,17 @@ the end of the array. e.g. `slice(1, -1, [> 'a', 'b', 'c']) == [> 'b']`.
|
|
|
1442
1489
|
|
|
1443
1490
|
Parameters:
|
|
1444
1491
|
|
|
1445
|
-
|param|type|description|
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1492
|
+
| param | type | description |
|
|
1493
|
+
| ------- | ---------- | ------------------------------------------------------------- |
|
|
1494
|
+
| `start` | `Number` | The index of the array where the slice will begin (inclusive) |
|
|
1495
|
+
| `?end` | `Number` | The index of the array where the slice will end (exclusive) |
|
|
1496
|
+
| `array` | `Array<a>` | The array to be sliced |
|
|
1450
1497
|
|
|
1451
1498
|
Returns:
|
|
1452
1499
|
|
|
1453
|
-
|type|description|
|
|
1454
|
-
|
|
1455
|
-
|
|
1500
|
+
| type | description |
|
|
1501
|
+
| ---------- | --------------------------------------- |
|
|
1502
|
+
| `Array<a>` | The subset of the array that was sliced |
|
|
1456
1503
|
|
|
1457
1504
|
Examples:
|
|
1458
1505
|
|
|
@@ -1479,7 +1526,7 @@ Array.slice(1, [> 1, 2, 3, 4]) == [> 2, 3, 4]
|
|
|
1479
1526
|
</details>
|
|
1480
1527
|
|
|
1481
1528
|
```grain
|
|
1482
|
-
sort
|
|
1529
|
+
sort: (?compare: ((num1: a, num2: a) => Number), array: Array<a>) => Void
|
|
1483
1530
|
```
|
|
1484
1531
|
|
|
1485
1532
|
Sorts an array in-place.
|
|
@@ -1488,10 +1535,10 @@ Ordering is calculated using a comparator function which takes two array element
|
|
|
1488
1535
|
|
|
1489
1536
|
Parameters:
|
|
1490
1537
|
|
|
1491
|
-
|param|type|description|
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1538
|
+
| param | type | description |
|
|
1539
|
+
| ---------- | ------------------------------ | --------------------------------------------------- |
|
|
1540
|
+
| `?compare` | `(num1: a, num2: a) => Number` | The comparator function used to indicate sort order |
|
|
1541
|
+
| `array` | `Array<a>` | The array to be sorted |
|
|
1495
1542
|
|
|
1496
1543
|
Examples:
|
|
1497
1544
|
|
|
@@ -1516,7 +1563,7 @@ assert arr == [> 1, 2, 3, 4]
|
|
|
1516
1563
|
</details>
|
|
1517
1564
|
|
|
1518
1565
|
```grain
|
|
1519
|
-
rotate
|
|
1566
|
+
rotate: (n: Number, arr: Array<a>) => Void
|
|
1520
1567
|
```
|
|
1521
1568
|
|
|
1522
1569
|
Rotates array elements in place by the specified amount to the left, such
|
|
@@ -1527,10 +1574,10 @@ specified amount to the right. See examples.
|
|
|
1527
1574
|
|
|
1528
1575
|
Parameters:
|
|
1529
1576
|
|
|
1530
|
-
|param|type|description|
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1577
|
+
| param | type | description |
|
|
1578
|
+
| ----- | ---------- | ----------------------------------- |
|
|
1579
|
+
| `n` | `Number` | The number of elements to rotate by |
|
|
1580
|
+
| `arr` | `Array<a>` | The array to be rotated |
|
|
1534
1581
|
|
|
1535
1582
|
Examples:
|
|
1536
1583
|
|
|
@@ -1554,7 +1601,7 @@ No other changes yet.
|
|
|
1554
1601
|
</details>
|
|
1555
1602
|
|
|
1556
1603
|
```grain
|
|
1557
|
-
chunk
|
|
1604
|
+
chunk: (chunkSize: Number, arr: Array<a>) => Array<Array<a>>
|
|
1558
1605
|
```
|
|
1559
1606
|
|
|
1560
1607
|
Splits the given array into chunks of the provided size.
|
|
@@ -1562,16 +1609,16 @@ If the array cannot be split evenly, the final chunk will contain the remaining
|
|
|
1562
1609
|
|
|
1563
1610
|
Parameters:
|
|
1564
1611
|
|
|
1565
|
-
|param|type|description|
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1612
|
+
| param | type | description |
|
|
1613
|
+
| ----------- | ---------- | ------------------------------ |
|
|
1614
|
+
| `chunkSize` | `Number` | The maximum size of each chunk |
|
|
1615
|
+
| `arr` | `Array<a>` | The array to chunk |
|
|
1569
1616
|
|
|
1570
1617
|
Returns:
|
|
1571
1618
|
|
|
1572
|
-
|type|description|
|
|
1573
|
-
|
|
1574
|
-
|
|
1619
|
+
| type | description |
|
|
1620
|
+
| ----------------- | ------------------ |
|
|
1621
|
+
| `Array<Array<a>>` | An array of chunks |
|
|
1575
1622
|
|
|
1576
1623
|
Throws:
|
|
1577
1624
|
|
|
@@ -1647,7 +1694,7 @@ Functions and constants included in the Array.Immutable module.
|
|
|
1647
1694
|
</details>
|
|
1648
1695
|
|
|
1649
1696
|
```grain
|
|
1650
|
-
empty
|
|
1697
|
+
empty: ImmutableArray<a>
|
|
1651
1698
|
```
|
|
1652
1699
|
|
|
1653
1700
|
An empty array.
|
|
@@ -1673,22 +1720,22 @@ Array.Immutable.empty == Array.Immutable.fromList([])
|
|
|
1673
1720
|
</details>
|
|
1674
1721
|
|
|
1675
1722
|
```grain
|
|
1676
|
-
isEmpty
|
|
1723
|
+
isEmpty: (array: ImmutableArray<a>) => Bool
|
|
1677
1724
|
```
|
|
1678
1725
|
|
|
1679
1726
|
Determines if the array contains no elements.
|
|
1680
1727
|
|
|
1681
1728
|
Parameters:
|
|
1682
1729
|
|
|
1683
|
-
|param|type|description|
|
|
1684
|
-
|
|
1685
|
-
|
|
1730
|
+
| param | type | description |
|
|
1731
|
+
| ------- | ------------------- | ------------------ |
|
|
1732
|
+
| `array` | `ImmutableArray<a>` | The array to check |
|
|
1686
1733
|
|
|
1687
1734
|
Returns:
|
|
1688
1735
|
|
|
1689
|
-
|type|description|
|
|
1690
|
-
|
|
1691
|
-
|
|
1736
|
+
| type | description |
|
|
1737
|
+
| ------ | -------------------------------------------------- |
|
|
1738
|
+
| `Bool` | `true` if the array is empty and `false` otherwise |
|
|
1692
1739
|
|
|
1693
1740
|
Examples:
|
|
1694
1741
|
|
|
@@ -1717,22 +1764,22 @@ assert Immutable.isEmpty(Immutable.fromList([])) == true
|
|
|
1717
1764
|
</details>
|
|
1718
1765
|
|
|
1719
1766
|
```grain
|
|
1720
|
-
length
|
|
1767
|
+
length: (array: ImmutableArray<a>) => Number
|
|
1721
1768
|
```
|
|
1722
1769
|
|
|
1723
1770
|
Provides the length of the input array.
|
|
1724
1771
|
|
|
1725
1772
|
Parameters:
|
|
1726
1773
|
|
|
1727
|
-
|param|type|description|
|
|
1728
|
-
|
|
1729
|
-
|
|
1774
|
+
| param | type | description |
|
|
1775
|
+
| ------- | ------------------- | -------------------- |
|
|
1776
|
+
| `array` | `ImmutableArray<a>` | The array to inspect |
|
|
1730
1777
|
|
|
1731
1778
|
Returns:
|
|
1732
1779
|
|
|
1733
|
-
|type|description|
|
|
1734
|
-
|
|
1735
|
-
|
|
1780
|
+
| type | description |
|
|
1781
|
+
| -------- | ----------------------------------- |
|
|
1782
|
+
| `Number` | The number of elements in the array |
|
|
1736
1783
|
|
|
1737
1784
|
Examples:
|
|
1738
1785
|
|
|
@@ -1756,7 +1803,7 @@ assert Immutable.length(Immutable.fromList([1, 2, 3, 4, 5])) == 5
|
|
|
1756
1803
|
</details>
|
|
1757
1804
|
|
|
1758
1805
|
```grain
|
|
1759
|
-
get
|
|
1806
|
+
get: (index: Number, array: ImmutableArray<a>) => a
|
|
1760
1807
|
```
|
|
1761
1808
|
|
|
1762
1809
|
Retrieves the element from the array at the specified index.
|
|
@@ -1764,16 +1811,16 @@ A negative index is treated as an offset from the end of the array.
|
|
|
1764
1811
|
|
|
1765
1812
|
Parameters:
|
|
1766
1813
|
|
|
1767
|
-
|param|type|description|
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1814
|
+
| param | type | description |
|
|
1815
|
+
| ------- | ------------------- | ------------------- |
|
|
1816
|
+
| `index` | `Number` | The index to access |
|
|
1817
|
+
| `array` | `ImmutableArray<a>` | The array to access |
|
|
1771
1818
|
|
|
1772
1819
|
Returns:
|
|
1773
1820
|
|
|
1774
|
-
|type|description|
|
|
1775
|
-
|
|
1776
|
-
|
|
1821
|
+
| type | description |
|
|
1822
|
+
| ---- | -------------------------- |
|
|
1823
|
+
| `a` | The element from the array |
|
|
1777
1824
|
|
|
1778
1825
|
Throws:
|
|
1779
1826
|
|
|
@@ -1808,8 +1855,7 @@ assert Immutable.get(-1, Immutable.fromList([1, 2, 3, 4])) == 4
|
|
|
1808
1855
|
</details>
|
|
1809
1856
|
|
|
1810
1857
|
```grain
|
|
1811
|
-
set :
|
|
1812
|
-
(index: Number, value: a, array: ImmutableArray<a>) => ImmutableArray<a>
|
|
1858
|
+
set: (index: Number, value: a, array: ImmutableArray<a>) => ImmutableArray<a>
|
|
1813
1859
|
```
|
|
1814
1860
|
|
|
1815
1861
|
Creates a new array in which the element at the specified index is set to a
|
|
@@ -1817,17 +1863,17 @@ new value. A negative index is treated as an offset from the end of the array.
|
|
|
1817
1863
|
|
|
1818
1864
|
Parameters:
|
|
1819
1865
|
|
|
1820
|
-
|param|type|description|
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1866
|
+
| param | type | description |
|
|
1867
|
+
| ------- | ------------------- | ------------------- |
|
|
1868
|
+
| `index` | `Number` | The index to update |
|
|
1869
|
+
| `value` | `a` | The value to store |
|
|
1870
|
+
| `array` | `ImmutableArray<a>` | The array to update |
|
|
1825
1871
|
|
|
1826
1872
|
Returns:
|
|
1827
1873
|
|
|
1828
|
-
|type|description|
|
|
1829
|
-
|
|
1830
|
-
|
|
1874
|
+
| type | description |
|
|
1875
|
+
| ------------------- | --------------------------------------------------------- |
|
|
1876
|
+
| `ImmutableArray<a>` | A new array containing the new element at the given index |
|
|
1831
1877
|
|
|
1832
1878
|
Throws:
|
|
1833
1879
|
|
|
@@ -1860,7 +1906,7 @@ assert array == Immutable.fromList([1, 9, 3, 4, 5])
|
|
|
1860
1906
|
</details>
|
|
1861
1907
|
|
|
1862
1908
|
```grain
|
|
1863
|
-
append
|
|
1909
|
+
append:
|
|
1864
1910
|
(array1: ImmutableArray<a>, array2: ImmutableArray<a>) => ImmutableArray<a>
|
|
1865
1911
|
```
|
|
1866
1912
|
|
|
@@ -1869,16 +1915,16 @@ the elements of the second array.
|
|
|
1869
1915
|
|
|
1870
1916
|
Parameters:
|
|
1871
1917
|
|
|
1872
|
-
|param|type|description|
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1918
|
+
| param | type | description |
|
|
1919
|
+
| -------- | ------------------- | ---------------------------------------------- |
|
|
1920
|
+
| `array1` | `ImmutableArray<a>` | The array containing elements to appear first |
|
|
1921
|
+
| `array2` | `ImmutableArray<a>` | The array containing elements to appear second |
|
|
1876
1922
|
|
|
1877
1923
|
Returns:
|
|
1878
1924
|
|
|
1879
|
-
|type|description|
|
|
1880
|
-
|
|
1881
|
-
|
|
1925
|
+
| type | description |
|
|
1926
|
+
| ------------------- | ---------------------------------------------------------------------------------- |
|
|
1927
|
+
| `ImmutableArray<a>` | The new array containing elements from `array1` followed by elements from `array2` |
|
|
1882
1928
|
|
|
1883
1929
|
Examples:
|
|
1884
1930
|
|
|
@@ -1906,7 +1952,7 @@ assert arr2 == Immutable.fromList([3, 4, 5])
|
|
|
1906
1952
|
</details>
|
|
1907
1953
|
|
|
1908
1954
|
```grain
|
|
1909
|
-
concat
|
|
1955
|
+
concat: (arrays: List<ImmutableArray<a>>) => ImmutableArray<a>
|
|
1910
1956
|
```
|
|
1911
1957
|
|
|
1912
1958
|
Creates a single array containing the elements of all arrays in the
|
|
@@ -1914,15 +1960,15 @@ provided list.
|
|
|
1914
1960
|
|
|
1915
1961
|
Parameters:
|
|
1916
1962
|
|
|
1917
|
-
|param|type|description|
|
|
1918
|
-
|
|
1919
|
-
|
|
1963
|
+
| param | type | description |
|
|
1964
|
+
| -------- | ------------------------- | --------------------------------------- |
|
|
1965
|
+
| `arrays` | `List<ImmutableArray<a>>` | A list containing all arrays to combine |
|
|
1920
1966
|
|
|
1921
1967
|
Returns:
|
|
1922
1968
|
|
|
1923
|
-
|type|description|
|
|
1924
|
-
|
|
1925
|
-
|
|
1969
|
+
| type | description |
|
|
1970
|
+
| ------------------- | ------------- |
|
|
1971
|
+
| `ImmutableArray<a>` | The new array |
|
|
1926
1972
|
|
|
1927
1973
|
Examples:
|
|
1928
1974
|
|
|
@@ -1949,7 +1995,7 @@ assert Immutable.concat([arr1, arr2, arr3]) == Immutable.fromList([1, 2, 3, 4, 5
|
|
|
1949
1995
|
</details>
|
|
1950
1996
|
|
|
1951
1997
|
```grain
|
|
1952
|
-
init
|
|
1998
|
+
init: (length: Number, fn: (Number => a)) => ImmutableArray<a>
|
|
1953
1999
|
```
|
|
1954
2000
|
|
|
1955
2001
|
Creates a new array of the specified length where each element is
|
|
@@ -1958,16 +2004,16 @@ is called with the index of each array element.
|
|
|
1958
2004
|
|
|
1959
2005
|
Parameters:
|
|
1960
2006
|
|
|
1961
|
-
|param|type|description|
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
2007
|
+
| param | type | description |
|
|
2008
|
+
| -------- | ------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
2009
|
+
| `length` | `Number` | The length of the new array |
|
|
2010
|
+
| `fn` | `Number => a` | The initializer function to call with each index, where the value returned will be used to initialize the element |
|
|
1965
2011
|
|
|
1966
2012
|
Returns:
|
|
1967
2013
|
|
|
1968
|
-
|type|description|
|
|
1969
|
-
|
|
1970
|
-
|
|
2014
|
+
| type | description |
|
|
2015
|
+
| ------------------- | ------------- |
|
|
2016
|
+
| `ImmutableArray<a>` | The new array |
|
|
1971
2017
|
|
|
1972
2018
|
Examples:
|
|
1973
2019
|
|
|
@@ -1996,7 +2042,7 @@ assert Immutable.init(5, i => i + 3) == Immutable.fromList([3, 4, 5, 6, 7])
|
|
|
1996
2042
|
</details>
|
|
1997
2043
|
|
|
1998
2044
|
```grain
|
|
1999
|
-
make
|
|
2045
|
+
make: (length: Number, value: a) => ImmutableArray<a>
|
|
2000
2046
|
```
|
|
2001
2047
|
|
|
2002
2048
|
Creates a new array of the specified length with each element being
|
|
@@ -2004,16 +2050,16 @@ initialized with the given value.
|
|
|
2004
2050
|
|
|
2005
2051
|
Parameters:
|
|
2006
2052
|
|
|
2007
|
-
|param|type|description|
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2053
|
+
| param | type | description |
|
|
2054
|
+
| -------- | -------- | -------------------------------- |
|
|
2055
|
+
| `length` | `Number` | The length of the new array |
|
|
2056
|
+
| `value` | `a` | The value to store at each index |
|
|
2011
2057
|
|
|
2012
2058
|
Returns:
|
|
2013
2059
|
|
|
2014
|
-
|type|description|
|
|
2015
|
-
|
|
2016
|
-
|
|
2060
|
+
| type | description |
|
|
2061
|
+
| ------------------- | ------------- |
|
|
2062
|
+
| `ImmutableArray<a>` | The new array |
|
|
2017
2063
|
|
|
2018
2064
|
Examples:
|
|
2019
2065
|
|
|
@@ -2037,17 +2083,17 @@ assert Immutable.make(5, "🌾") == Immutable.fromList(["🌾", "🌾", "🌾",
|
|
|
2037
2083
|
</details>
|
|
2038
2084
|
|
|
2039
2085
|
```grain
|
|
2040
|
-
forEach
|
|
2086
|
+
forEach: (fn: (a => Void), array: ImmutableArray<a>) => Void
|
|
2041
2087
|
```
|
|
2042
2088
|
|
|
2043
2089
|
Iterates an array, calling an iterator function on each element.
|
|
2044
2090
|
|
|
2045
2091
|
Parameters:
|
|
2046
2092
|
|
|
2047
|
-
|param|type|description|
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2093
|
+
| param | type | description |
|
|
2094
|
+
| ------- | ------------------- | ----------------------------------------------- |
|
|
2095
|
+
| `fn` | `a => Void` | The iterator function to call with each element |
|
|
2096
|
+
| `array` | `ImmutableArray<a>` | The array to iterate |
|
|
2051
2097
|
|
|
2052
2098
|
Examples:
|
|
2053
2099
|
|
|
@@ -2074,18 +2120,18 @@ assert str == "foobarbaz"
|
|
|
2074
2120
|
</details>
|
|
2075
2121
|
|
|
2076
2122
|
```grain
|
|
2077
|
-
cycle
|
|
2123
|
+
cycle: (fn: (a => Void), n: Number, array: ImmutableArray<a>) => Void
|
|
2078
2124
|
```
|
|
2079
2125
|
|
|
2080
2126
|
Iterates an array a given number of times, calling an iterator function on each element.
|
|
2081
2127
|
|
|
2082
2128
|
Parameters:
|
|
2083
2129
|
|
|
2084
|
-
|param|type|description|
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2130
|
+
| param | type | description |
|
|
2131
|
+
| ------- | ------------------- | ----------------------------------------------- |
|
|
2132
|
+
| `fn` | `a => Void` | The iterator function to call with each element |
|
|
2133
|
+
| `n` | `Number` | The number of times to iterate the given array |
|
|
2134
|
+
| `array` | `ImmutableArray<a>` | The array to iterate |
|
|
2089
2135
|
|
|
2090
2136
|
Examples:
|
|
2091
2137
|
|
|
@@ -2112,7 +2158,7 @@ assert str == "abcabc"
|
|
|
2112
2158
|
</details>
|
|
2113
2159
|
|
|
2114
2160
|
```grain
|
|
2115
|
-
map
|
|
2161
|
+
map: (fn: (a => b), array: ImmutableArray<a>) => ImmutableArray<b>
|
|
2116
2162
|
```
|
|
2117
2163
|
|
|
2118
2164
|
Produces a new array initialized with the results of a mapper function
|
|
@@ -2120,16 +2166,16 @@ called on each element of the input array.
|
|
|
2120
2166
|
|
|
2121
2167
|
Parameters:
|
|
2122
2168
|
|
|
2123
|
-
|param|type|description|
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2169
|
+
| param | type | description |
|
|
2170
|
+
| ------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
2171
|
+
| `fn` | `a => b` | The mapper function to call on each element, where the value returned will be used to initialize the element in the new array |
|
|
2172
|
+
| `array` | `ImmutableArray<a>` | The array to iterate |
|
|
2127
2173
|
|
|
2128
2174
|
Returns:
|
|
2129
2175
|
|
|
2130
|
-
|type|description|
|
|
2131
|
-
|
|
2132
|
-
|
|
2176
|
+
| type | description |
|
|
2177
|
+
| ------------------- | -------------------------------- |
|
|
2178
|
+
| `ImmutableArray<b>` | The new array with mapped values |
|
|
2133
2179
|
|
|
2134
2180
|
Examples:
|
|
2135
2181
|
|
|
@@ -2155,7 +2201,7 @@ assert arr == Immutable.fromList(["foo_", "bar_", "baz_"])
|
|
|
2155
2201
|
</details>
|
|
2156
2202
|
|
|
2157
2203
|
```grain
|
|
2158
|
-
reduce
|
|
2204
|
+
reduce: (fn: ((a, b) => a), initial: a, array: ImmutableArray<b>) => a
|
|
2159
2205
|
```
|
|
2160
2206
|
|
|
2161
2207
|
Combines all elements of an array using a reducer function,
|
|
@@ -2168,17 +2214,17 @@ returned. The accumulator starts with value `initial`.
|
|
|
2168
2214
|
|
|
2169
2215
|
Parameters:
|
|
2170
2216
|
|
|
2171
|
-
|param|type|description|
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2217
|
+
| param | type | description |
|
|
2218
|
+
| --------- | ------------------- | --------------------------------------------------------------------------------------------------------- |
|
|
2219
|
+
| `fn` | `(a, b) => a` | The reducer function to call on each element, where the value returned will be the next accumulator value |
|
|
2220
|
+
| `initial` | `a` | The initial value to use for the accumulator on the first iteration |
|
|
2221
|
+
| `array` | `ImmutableArray<b>` | The array to iterate |
|
|
2176
2222
|
|
|
2177
2223
|
Returns:
|
|
2178
2224
|
|
|
2179
|
-
|type|description|
|
|
2180
|
-
|
|
2181
|
-
|
|
2225
|
+
| type | description |
|
|
2226
|
+
| ---- | ---------------------------------------- |
|
|
2227
|
+
| `a` | The final accumulator returned from `fn` |
|
|
2182
2228
|
|
|
2183
2229
|
Examples:
|
|
2184
2230
|
|
|
@@ -2203,7 +2249,7 @@ assert Immutable.reduce((acc, x) => acc + x, 0, arr) == 6
|
|
|
2203
2249
|
</details>
|
|
2204
2250
|
|
|
2205
2251
|
```grain
|
|
2206
|
-
reduceRight
|
|
2252
|
+
reduceRight: (fn: ((a, b) => b), initial: b, array: ImmutableArray<a>) => b
|
|
2207
2253
|
```
|
|
2208
2254
|
|
|
2209
2255
|
Combines all elements of an array using a reducer function,
|
|
@@ -2216,17 +2262,17 @@ returned. The accumulator starts with value `initial`.
|
|
|
2216
2262
|
|
|
2217
2263
|
Parameters:
|
|
2218
2264
|
|
|
2219
|
-
|param|type|description|
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2265
|
+
| param | type | description |
|
|
2266
|
+
| --------- | ------------------- | --------------------------------------------------------------------------------------------------------- |
|
|
2267
|
+
| `fn` | `(a, b) => b` | The reducer function to call on each element, where the value returned will be the next accumulator value |
|
|
2268
|
+
| `initial` | `b` | The initial value to use for the accumulator on the first iteration |
|
|
2269
|
+
| `array` | `ImmutableArray<a>` | The array to iterate |
|
|
2224
2270
|
|
|
2225
2271
|
Returns:
|
|
2226
2272
|
|
|
2227
|
-
|type|description|
|
|
2228
|
-
|
|
2229
|
-
|
|
2273
|
+
| type | description |
|
|
2274
|
+
| ---- | ---------------------------------------- |
|
|
2275
|
+
| `b` | The final accumulator returned from `fn` |
|
|
2230
2276
|
|
|
2231
2277
|
Examples:
|
|
2232
2278
|
|
|
@@ -2251,7 +2297,7 @@ assert Immutable.reduceRight((x, acc) => acc ++ x, "", arr) == "foobarbaz"
|
|
|
2251
2297
|
</details>
|
|
2252
2298
|
|
|
2253
2299
|
```grain
|
|
2254
|
-
flatMap
|
|
2300
|
+
flatMap:
|
|
2255
2301
|
(fn: (a => ImmutableArray<b>), array: ImmutableArray<a>) =>
|
|
2256
2302
|
ImmutableArray<b>
|
|
2257
2303
|
```
|
|
@@ -2263,16 +2309,16 @@ of all results.
|
|
|
2263
2309
|
|
|
2264
2310
|
Parameters:
|
|
2265
2311
|
|
|
2266
|
-
|param|type|description|
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2312
|
+
| param | type | description |
|
|
2313
|
+
| ------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------ |
|
|
2314
|
+
| `fn` | `a => ImmutableArray<b>` | The function to be called on each element, where the value returned will be an array that gets appended to the new array |
|
|
2315
|
+
| `array` | `ImmutableArray<a>` | The array to iterate |
|
|
2270
2316
|
|
|
2271
2317
|
Returns:
|
|
2272
2318
|
|
|
2273
|
-
|type|description|
|
|
2274
|
-
|
|
2275
|
-
|
|
2319
|
+
| type | description |
|
|
2320
|
+
| ------------------- | ------------- |
|
|
2321
|
+
| `ImmutableArray<b>` | The new array |
|
|
2276
2322
|
|
|
2277
2323
|
Examples:
|
|
2278
2324
|
|
|
@@ -2298,22 +2344,22 @@ assert arr == Immutable.fromList([1, 2, 3, 4, 5, 6])
|
|
|
2298
2344
|
</details>
|
|
2299
2345
|
|
|
2300
2346
|
```grain
|
|
2301
|
-
fromList
|
|
2347
|
+
fromList: (list: List<a>) => ImmutableArray<a>
|
|
2302
2348
|
```
|
|
2303
2349
|
|
|
2304
2350
|
Converts the input list to an array.
|
|
2305
2351
|
|
|
2306
2352
|
Parameters:
|
|
2307
2353
|
|
|
2308
|
-
|param|type|description|
|
|
2309
|
-
|
|
2310
|
-
|
|
2354
|
+
| param | type | description |
|
|
2355
|
+
| ------ | --------- | ------------------- |
|
|
2356
|
+
| `list` | `List<a>` | The list to convert |
|
|
2311
2357
|
|
|
2312
2358
|
Returns:
|
|
2313
2359
|
|
|
2314
|
-
|type|description|
|
|
2315
|
-
|
|
2316
|
-
|
|
2360
|
+
| type | description |
|
|
2361
|
+
| ------------------- | ----------------------------------------------- |
|
|
2362
|
+
| `ImmutableArray<a>` | The array containing all elements from the list |
|
|
2317
2363
|
|
|
2318
2364
|
Examples:
|
|
2319
2365
|
|
|
@@ -2338,22 +2384,22 @@ assert Immutable.get(1, arr) == 2
|
|
|
2338
2384
|
</details>
|
|
2339
2385
|
|
|
2340
2386
|
```grain
|
|
2341
|
-
toList
|
|
2387
|
+
toList: (array: ImmutableArray<a>) => List<a>
|
|
2342
2388
|
```
|
|
2343
2389
|
|
|
2344
2390
|
Converts the input array to a list.
|
|
2345
2391
|
|
|
2346
2392
|
Parameters:
|
|
2347
2393
|
|
|
2348
|
-
|param|type|description|
|
|
2349
|
-
|
|
2350
|
-
|
|
2394
|
+
| param | type | description |
|
|
2395
|
+
| ------- | ------------------- | -------------------- |
|
|
2396
|
+
| `array` | `ImmutableArray<a>` | The array to convert |
|
|
2351
2397
|
|
|
2352
2398
|
Returns:
|
|
2353
2399
|
|
|
2354
|
-
|type|description|
|
|
2355
|
-
|
|
2356
|
-
|
|
2400
|
+
| type | description |
|
|
2401
|
+
| --------- | ----------------------------------------------- |
|
|
2402
|
+
| `List<a>` | The list containing all elements from the array |
|
|
2357
2403
|
|
|
2358
2404
|
Examples:
|
|
2359
2405
|
|
|
@@ -2379,7 +2425,7 @@ assert Immutable.toList(arr) == ['d', 'b', 'c']
|
|
|
2379
2425
|
</details>
|
|
2380
2426
|
|
|
2381
2427
|
```grain
|
|
2382
|
-
filter
|
|
2428
|
+
filter: (fn: (a => Bool), array: ImmutableArray<a>) => ImmutableArray<a>
|
|
2383
2429
|
```
|
|
2384
2430
|
|
|
2385
2431
|
Produces a new array by calling a function on each element of
|
|
@@ -2388,16 +2434,16 @@ the condition.
|
|
|
2388
2434
|
|
|
2389
2435
|
Parameters:
|
|
2390
2436
|
|
|
2391
|
-
|param|type|description|
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2437
|
+
| param | type | description |
|
|
2438
|
+
| ------- | ------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
2439
|
+
| `fn` | `a => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
2440
|
+
| `array` | `ImmutableArray<a>` | The array to iterate |
|
|
2395
2441
|
|
|
2396
2442
|
Returns:
|
|
2397
2443
|
|
|
2398
|
-
|type|description|
|
|
2399
|
-
|
|
2400
|
-
|
|
2444
|
+
| type | description |
|
|
2445
|
+
| ------------------- | ------------------------------------------------------------ |
|
|
2446
|
+
| `ImmutableArray<a>` | The new array containing elements where `fn` returned `true` |
|
|
2401
2447
|
|
|
2402
2448
|
Examples:
|
|
2403
2449
|
|
|
@@ -2423,7 +2469,7 @@ assert Immutable.toList(arr) == ['a', 'a']
|
|
|
2423
2469
|
</details>
|
|
2424
2470
|
|
|
2425
2471
|
```grain
|
|
2426
|
-
every
|
|
2472
|
+
every: (fn: (a => Bool), array: ImmutableArray<a>) => Bool
|
|
2427
2473
|
```
|
|
2428
2474
|
|
|
2429
2475
|
Checks that the given condition is satisfied for all
|
|
@@ -2431,16 +2477,16 @@ elements in the input array.
|
|
|
2431
2477
|
|
|
2432
2478
|
Parameters:
|
|
2433
2479
|
|
|
2434
|
-
|param|type|description|
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2480
|
+
| param | type | description |
|
|
2481
|
+
| ------- | ------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
2482
|
+
| `fn` | `a => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
2483
|
+
| `array` | `ImmutableArray<a>` | The array to check |
|
|
2438
2484
|
|
|
2439
2485
|
Returns:
|
|
2440
2486
|
|
|
2441
|
-
|type|description|
|
|
2442
|
-
|
|
2443
|
-
|
|
2487
|
+
| type | description |
|
|
2488
|
+
| ------ | ----------------------------------------------------------------- |
|
|
2489
|
+
| `Bool` | `true` if all elements satisfy the condition or `false` otherwise |
|
|
2444
2490
|
|
|
2445
2491
|
Examples:
|
|
2446
2492
|
|
|
@@ -2471,7 +2517,7 @@ assert Immutable.every(e => e == 'a', arr) == false
|
|
|
2471
2517
|
</details>
|
|
2472
2518
|
|
|
2473
2519
|
```grain
|
|
2474
|
-
some
|
|
2520
|
+
some: (fn: (a => Bool), array: ImmutableArray<a>) => Bool
|
|
2475
2521
|
```
|
|
2476
2522
|
|
|
2477
2523
|
Checks that the given condition is satisfied **at least
|
|
@@ -2479,16 +2525,16 @@ once** by an element in the input array.
|
|
|
2479
2525
|
|
|
2480
2526
|
Parameters:
|
|
2481
2527
|
|
|
2482
|
-
|param|type|description|
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2528
|
+
| param | type | description |
|
|
2529
|
+
| ------- | ------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
2530
|
+
| `fn` | `a => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
2531
|
+
| `array` | `ImmutableArray<a>` | The array to iterate |
|
|
2486
2532
|
|
|
2487
2533
|
Returns:
|
|
2488
2534
|
|
|
2489
|
-
|type|description|
|
|
2490
|
-
|
|
2491
|
-
|
|
2535
|
+
| type | description |
|
|
2536
|
+
| ------ | ------------------------------------------------------------------------- |
|
|
2537
|
+
| `Bool` | `true` if one or more elements satisfy the condition or `false` otherwise |
|
|
2492
2538
|
|
|
2493
2539
|
Examples:
|
|
2494
2540
|
|
|
@@ -2519,22 +2565,22 @@ assert Immutable.some(e => e == 'a', arr) == false
|
|
|
2519
2565
|
</details>
|
|
2520
2566
|
|
|
2521
2567
|
```grain
|
|
2522
|
-
reverse
|
|
2568
|
+
reverse: (array: ImmutableArray<a>) => ImmutableArray<a>
|
|
2523
2569
|
```
|
|
2524
2570
|
|
|
2525
2571
|
Creates a new array with all elements in reverse order.
|
|
2526
2572
|
|
|
2527
2573
|
Parameters:
|
|
2528
2574
|
|
|
2529
|
-
|param|type|description|
|
|
2530
|
-
|
|
2531
|
-
|
|
2575
|
+
| param | type | description |
|
|
2576
|
+
| ------- | ------------------- | -------------------- |
|
|
2577
|
+
| `array` | `ImmutableArray<a>` | The array to reverse |
|
|
2532
2578
|
|
|
2533
2579
|
Returns:
|
|
2534
2580
|
|
|
2535
|
-
|type|description|
|
|
2536
|
-
|
|
2537
|
-
|
|
2581
|
+
| type | description |
|
|
2582
|
+
| ------------------- | ------------- |
|
|
2583
|
+
| `ImmutableArray<a>` | The new array |
|
|
2538
2584
|
|
|
2539
2585
|
Examples:
|
|
2540
2586
|
|
|
@@ -2560,7 +2606,7 @@ assert Immutable.toList(arr) == ['c', 'b', 'a']
|
|
|
2560
2606
|
</details>
|
|
2561
2607
|
|
|
2562
2608
|
```grain
|
|
2563
|
-
contains
|
|
2609
|
+
contains: (search: a, array: ImmutableArray<a>) => Bool
|
|
2564
2610
|
```
|
|
2565
2611
|
|
|
2566
2612
|
Checks if the value is an element of the input array.
|
|
@@ -2568,16 +2614,16 @@ Uses the generic `==` structural equality operator.
|
|
|
2568
2614
|
|
|
2569
2615
|
Parameters:
|
|
2570
2616
|
|
|
2571
|
-
|param|type|description|
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2617
|
+
| param | type | description |
|
|
2618
|
+
| -------- | ------------------- | -------------------- |
|
|
2619
|
+
| `search` | `a` | The value to compare |
|
|
2620
|
+
| `array` | `ImmutableArray<a>` | The array to inspect |
|
|
2575
2621
|
|
|
2576
2622
|
Returns:
|
|
2577
2623
|
|
|
2578
|
-
|type|description|
|
|
2579
|
-
|
|
2580
|
-
|
|
2624
|
+
| type | description |
|
|
2625
|
+
| ------ | ------------------------------------------------------------ |
|
|
2626
|
+
| `Bool` | `true` if the value exists in the array or `false` otherwise |
|
|
2581
2627
|
|
|
2582
2628
|
Examples:
|
|
2583
2629
|
|
|
@@ -2608,23 +2654,23 @@ assert Immutable.contains('a', arr) == false
|
|
|
2608
2654
|
</details>
|
|
2609
2655
|
|
|
2610
2656
|
```grain
|
|
2611
|
-
find
|
|
2657
|
+
find: (fn: (a => Bool), array: ImmutableArray<a>) => Option<a>
|
|
2612
2658
|
```
|
|
2613
2659
|
|
|
2614
2660
|
Finds the first element in an array that satisfies the given condition.
|
|
2615
2661
|
|
|
2616
2662
|
Parameters:
|
|
2617
2663
|
|
|
2618
|
-
|param|type|description|
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2664
|
+
| param | type | description |
|
|
2665
|
+
| ------- | ------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
2666
|
+
| `fn` | `a => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
2667
|
+
| `array` | `ImmutableArray<a>` | The array to search |
|
|
2622
2668
|
|
|
2623
2669
|
Returns:
|
|
2624
2670
|
|
|
2625
|
-
|type|description|
|
|
2626
|
-
|
|
2627
|
-
|
|
2671
|
+
| type | description |
|
|
2672
|
+
| ----------- | -------------------------------------------------------------------- |
|
|
2673
|
+
| `Option<a>` | `Some(element)` containing the first value found or `None` otherwise |
|
|
2628
2674
|
|
|
2629
2675
|
Examples:
|
|
2630
2676
|
|
|
@@ -2655,23 +2701,23 @@ assert Immutable.find(e => e == 2, arr) == None
|
|
|
2655
2701
|
</details>
|
|
2656
2702
|
|
|
2657
2703
|
```grain
|
|
2658
|
-
findIndex
|
|
2704
|
+
findIndex: (fn: (a => Bool), array: ImmutableArray<a>) => Option<Number>
|
|
2659
2705
|
```
|
|
2660
2706
|
|
|
2661
2707
|
Finds the first index in an array where the element satisfies the given condition.
|
|
2662
2708
|
|
|
2663
2709
|
Parameters:
|
|
2664
2710
|
|
|
2665
|
-
|param|type|description|
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2711
|
+
| param | type | description |
|
|
2712
|
+
| ------- | ------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
2713
|
+
| `fn` | `a => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
2714
|
+
| `array` | `ImmutableArray<a>` | The array to search |
|
|
2669
2715
|
|
|
2670
2716
|
Returns:
|
|
2671
2717
|
|
|
2672
|
-
|type|description|
|
|
2673
|
-
|
|
2674
|
-
|
|
2718
|
+
| type | description |
|
|
2719
|
+
| ---------------- | --------------------------------------------------------------------------------- |
|
|
2720
|
+
| `Option<Number>` | `Some(index)` containing the index of the first element found or `None` otherwise |
|
|
2675
2721
|
|
|
2676
2722
|
Examples:
|
|
2677
2723
|
|
|
@@ -2702,7 +2748,7 @@ assert Immutable.findIndex(e => e == 2, arr) == None
|
|
|
2702
2748
|
</details>
|
|
2703
2749
|
|
|
2704
2750
|
```grain
|
|
2705
|
-
product
|
|
2751
|
+
product:
|
|
2706
2752
|
(array1: ImmutableArray<a>, array2: ImmutableArray<b>) =>
|
|
2707
2753
|
ImmutableArray<(a, b)>
|
|
2708
2754
|
```
|
|
@@ -2712,16 +2758,16 @@ all ordered pairs `(a, b)`.
|
|
|
2712
2758
|
|
|
2713
2759
|
Parameters:
|
|
2714
2760
|
|
|
2715
|
-
|param|type|description|
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2761
|
+
| param | type | description |
|
|
2762
|
+
| -------- | ------------------- | -------------------------------------------------------- |
|
|
2763
|
+
| `array1` | `ImmutableArray<a>` | The array to provide values for the first tuple element |
|
|
2764
|
+
| `array2` | `ImmutableArray<b>` | The array to provide values for the second tuple element |
|
|
2719
2765
|
|
|
2720
2766
|
Returns:
|
|
2721
2767
|
|
|
2722
|
-
|type|description|
|
|
2723
|
-
|
|
2724
|
-
|
|
2768
|
+
| type | description |
|
|
2769
|
+
| ------------------------ | ---------------------------------------------- |
|
|
2770
|
+
| `ImmutableArray<(a, b)>` | The new array containing all pairs of `(a, b)` |
|
|
2725
2771
|
|
|
2726
2772
|
Examples:
|
|
2727
2773
|
|
|
@@ -2747,23 +2793,23 @@ assert Immutable.product(arr1, arr2) == Immutable.fromList([(1, 3), (1, 4), (2,
|
|
|
2747
2793
|
</details>
|
|
2748
2794
|
|
|
2749
2795
|
```grain
|
|
2750
|
-
count
|
|
2796
|
+
count: (fn: (a => Bool), array: ImmutableArray<a>) => Number
|
|
2751
2797
|
```
|
|
2752
2798
|
|
|
2753
2799
|
Counts the number of elements in an array that satisfy the given condition.
|
|
2754
2800
|
|
|
2755
2801
|
Parameters:
|
|
2756
2802
|
|
|
2757
|
-
|param|type|description|
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2803
|
+
| param | type | description |
|
|
2804
|
+
| ------- | ------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
2805
|
+
| `fn` | `a => Bool` | The function to call on each element, where the returned value indicates if the element satisfies the condition |
|
|
2806
|
+
| `array` | `ImmutableArray<a>` | The array to iterate |
|
|
2761
2807
|
|
|
2762
2808
|
Returns:
|
|
2763
2809
|
|
|
2764
|
-
|type|description|
|
|
2765
|
-
|
|
2766
|
-
|
|
2810
|
+
| type | description |
|
|
2811
|
+
| -------- | ------------------------------------------------------- |
|
|
2812
|
+
| `Number` | The total number of elements that satisfy the condition |
|
|
2767
2813
|
|
|
2768
2814
|
Examples:
|
|
2769
2815
|
|
|
@@ -2788,7 +2834,7 @@ assert Immutable.count(e => e == 1, arr) == 2
|
|
|
2788
2834
|
</details>
|
|
2789
2835
|
|
|
2790
2836
|
```grain
|
|
2791
|
-
unique
|
|
2837
|
+
unique: (array: ImmutableArray<a>) => ImmutableArray<a>
|
|
2792
2838
|
```
|
|
2793
2839
|
|
|
2794
2840
|
Produces a new array with any duplicates removed.
|
|
@@ -2796,15 +2842,15 @@ Uses the generic `==` structural equality operator.
|
|
|
2796
2842
|
|
|
2797
2843
|
Parameters:
|
|
2798
2844
|
|
|
2799
|
-
|param|type|description|
|
|
2800
|
-
|
|
2801
|
-
|
|
2845
|
+
| param | type | description |
|
|
2846
|
+
| ------- | ------------------- | ------------------- |
|
|
2847
|
+
| `array` | `ImmutableArray<a>` | The array to filter |
|
|
2802
2848
|
|
|
2803
2849
|
Returns:
|
|
2804
2850
|
|
|
2805
|
-
|type|description|
|
|
2806
|
-
|
|
2807
|
-
|
|
2851
|
+
| type | description |
|
|
2852
|
+
| ------------------- | ------------------------------------- |
|
|
2853
|
+
| `ImmutableArray<a>` | The new array with only unique values |
|
|
2808
2854
|
|
|
2809
2855
|
Examples:
|
|
2810
2856
|
|
|
@@ -2829,7 +2875,7 @@ assert Immutable.unique(arr) == Immutable.fromList([1, 2, 3, 4])
|
|
|
2829
2875
|
</details>
|
|
2830
2876
|
|
|
2831
2877
|
```grain
|
|
2832
|
-
zip
|
|
2878
|
+
zip:
|
|
2833
2879
|
(array1: ImmutableArray<a>, array2: ImmutableArray<b>) =>
|
|
2834
2880
|
ImmutableArray<(a, b)>
|
|
2835
2881
|
```
|
|
@@ -2843,16 +2889,16 @@ array to have the length of the smaller array.
|
|
|
2843
2889
|
|
|
2844
2890
|
Parameters:
|
|
2845
2891
|
|
|
2846
|
-
|param|type|description|
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2892
|
+
| param | type | description |
|
|
2893
|
+
| -------- | ------------------- | -------------------------------------------------------- |
|
|
2894
|
+
| `array1` | `ImmutableArray<a>` | The array to provide values for the first tuple element |
|
|
2895
|
+
| `array2` | `ImmutableArray<b>` | The array to provide values for the second tuple element |
|
|
2850
2896
|
|
|
2851
2897
|
Returns:
|
|
2852
2898
|
|
|
2853
|
-
|type|description|
|
|
2854
|
-
|
|
2855
|
-
|
|
2899
|
+
| type | description |
|
|
2900
|
+
| ------------------------ | -------------------------------------------------- |
|
|
2901
|
+
| `ImmutableArray<(a, b)>` | The new array containing indexed pairs of `(a, b)` |
|
|
2856
2902
|
|
|
2857
2903
|
Examples:
|
|
2858
2904
|
|
|
@@ -2878,7 +2924,7 @@ assert Immutable.zip(arr1, arr2) == Immutable.fromList([(1, 4), (2, 5), (3, 6)])
|
|
|
2878
2924
|
</details>
|
|
2879
2925
|
|
|
2880
2926
|
```grain
|
|
2881
|
-
zipWith
|
|
2927
|
+
zipWith:
|
|
2882
2928
|
(fn: ((a, b) => c), array1: ImmutableArray<a>, array2: ImmutableArray<b>) =>
|
|
2883
2929
|
ImmutableArray<c>
|
|
2884
2930
|
```
|
|
@@ -2894,17 +2940,17 @@ array to have the length of the smaller array.
|
|
|
2894
2940
|
|
|
2895
2941
|
Parameters:
|
|
2896
2942
|
|
|
2897
|
-
|param|type|description|
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2943
|
+
| param | type | description |
|
|
2944
|
+
| -------- | ------------------- | ----------------------------------------------------------------------------------- |
|
|
2945
|
+
| `fn` | `(a, b) => c` | The function to apply to pairs of elements |
|
|
2946
|
+
| `array1` | `ImmutableArray<a>` | The array whose elements will each be passed to the function as the first argument |
|
|
2947
|
+
| `array2` | `ImmutableArray<b>` | The array whose elements will each be passed to the function as the second argument |
|
|
2902
2948
|
|
|
2903
2949
|
Returns:
|
|
2904
2950
|
|
|
2905
|
-
|type|description|
|
|
2906
|
-
|
|
2907
|
-
|
|
2951
|
+
| type | description |
|
|
2952
|
+
| ------------------- | ----------------------------------------------------------------------------------------------------- |
|
|
2953
|
+
| `ImmutableArray<c>` | The new array containing elements derived from applying the function to pairs of input array elements |
|
|
2908
2954
|
|
|
2909
2955
|
Examples:
|
|
2910
2956
|
|
|
@@ -2937,7 +2983,7 @@ assert Immutable.zipWith((a, b) => a * b, arr1, arr2) == Immutable.fromList([4,
|
|
|
2937
2983
|
</details>
|
|
2938
2984
|
|
|
2939
2985
|
```grain
|
|
2940
|
-
unzip
|
|
2986
|
+
unzip:
|
|
2941
2987
|
(array: ImmutableArray<(a, b)>) => (ImmutableArray<a>, ImmutableArray<b>)
|
|
2942
2988
|
```
|
|
2943
2989
|
|
|
@@ -2945,15 +2991,15 @@ Produces two arrays by splitting apart an array of tuples.
|
|
|
2945
2991
|
|
|
2946
2992
|
Parameters:
|
|
2947
2993
|
|
|
2948
|
-
|param|type|description|
|
|
2949
|
-
|
|
2950
|
-
|
|
2994
|
+
| param | type | description |
|
|
2995
|
+
| ------- | ------------------------ | ---------------------------- |
|
|
2996
|
+
| `array` | `ImmutableArray<(a, b)>` | The array of tuples to split |
|
|
2951
2997
|
|
|
2952
2998
|
Returns:
|
|
2953
2999
|
|
|
2954
|
-
|type|description|
|
|
2955
|
-
|
|
2956
|
-
|
|
3000
|
+
| type | description |
|
|
3001
|
+
| ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
3002
|
+
| `(ImmutableArray<a>, ImmutableArray<b>)` | An array containing all elements from the first tuple element and an array containing all elements from the second tuple element |
|
|
2957
3003
|
|
|
2958
3004
|
Examples:
|
|
2959
3005
|
|
|
@@ -2980,23 +3026,23 @@ assert Immutable.unzip(arr1) == (arr2, arr3)
|
|
|
2980
3026
|
</details>
|
|
2981
3027
|
|
|
2982
3028
|
```grain
|
|
2983
|
-
join
|
|
3029
|
+
join: (separator: String, array: ImmutableArray<String>) => String
|
|
2984
3030
|
```
|
|
2985
3031
|
|
|
2986
3032
|
Concatenates an array of strings into a single string, separated by a separator string.
|
|
2987
3033
|
|
|
2988
3034
|
Parameters:
|
|
2989
3035
|
|
|
2990
|
-
|param|type|description|
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
3036
|
+
| param | type | description |
|
|
3037
|
+
| ----------- | ------------------------ | --------------------------------------------------- |
|
|
3038
|
+
| `separator` | `String` | The separator to insert between items in the string |
|
|
3039
|
+
| `array` | `ImmutableArray<String>` | The input strings |
|
|
2994
3040
|
|
|
2995
3041
|
Returns:
|
|
2996
3042
|
|
|
2997
|
-
|type|description|
|
|
2998
|
-
|
|
2999
|
-
|
|
3043
|
+
| type | description |
|
|
3044
|
+
| -------- | ----------------------- |
|
|
3045
|
+
| `String` | The concatenated string |
|
|
3000
3046
|
|
|
3001
3047
|
Examples:
|
|
3002
3048
|
|
|
@@ -3022,7 +3068,7 @@ assert Immutable.join(", ", arr) == "a, b, c"
|
|
|
3022
3068
|
</details>
|
|
3023
3069
|
|
|
3024
3070
|
```grain
|
|
3025
|
-
slice
|
|
3071
|
+
slice:
|
|
3026
3072
|
(start: Number, ?end: Number, array: ImmutableArray<a>) =>
|
|
3027
3073
|
ImmutableArray<a>
|
|
3028
3074
|
```
|
|
@@ -3035,17 +3081,17 @@ the end of the array.
|
|
|
3035
3081
|
|
|
3036
3082
|
Parameters:
|
|
3037
3083
|
|
|
3038
|
-
|param|type|description|
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3084
|
+
| param | type | description |
|
|
3085
|
+
| ------- | ------------------- | ------------------------------------------------------------- |
|
|
3086
|
+
| `start` | `Number` | The index of the array where the slice will begin (inclusive) |
|
|
3087
|
+
| `?end` | `Number` | The index of the array where the slice will end (exclusive) |
|
|
3088
|
+
| `array` | `ImmutableArray<a>` | The array to be sliced |
|
|
3043
3089
|
|
|
3044
3090
|
Returns:
|
|
3045
3091
|
|
|
3046
|
-
|type|description|
|
|
3047
|
-
|
|
3048
|
-
|
|
3092
|
+
| type | description |
|
|
3093
|
+
| ------------------- | --------------------------------------- |
|
|
3094
|
+
| `ImmutableArray<a>` | The subset of the array that was sliced |
|
|
3049
3095
|
|
|
3050
3096
|
Examples:
|
|
3051
3097
|
|
|
@@ -3076,7 +3122,7 @@ assert Immutable.slice(1, end=-1, arr) == Immutable.fromList(['b'])
|
|
|
3076
3122
|
</details>
|
|
3077
3123
|
|
|
3078
3124
|
```grain
|
|
3079
|
-
sort
|
|
3125
|
+
sort:
|
|
3080
3126
|
(?compare: ((num1: a, num2: a) => Number), array: ImmutableArray<a>) =>
|
|
3081
3127
|
ImmutableArray<a>
|
|
3082
3128
|
```
|
|
@@ -3087,16 +3133,16 @@ Ordering is calculated using a comparator function which takes two array element
|
|
|
3087
3133
|
|
|
3088
3134
|
Parameters:
|
|
3089
3135
|
|
|
3090
|
-
|param|type|description|
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3136
|
+
| param | type | description |
|
|
3137
|
+
| ---------- | ------------------------------ | --------------------------------------------------- |
|
|
3138
|
+
| `?compare` | `(num1: a, num2: a) => Number` | The comparator function used to indicate sort order |
|
|
3139
|
+
| `array` | `ImmutableArray<a>` | The array to be sorted |
|
|
3094
3140
|
|
|
3095
3141
|
Returns:
|
|
3096
3142
|
|
|
3097
|
-
|type|description|
|
|
3098
|
-
|
|
3099
|
-
|
|
3143
|
+
| type | description |
|
|
3144
|
+
| ------------------- | ---------------- |
|
|
3145
|
+
| `ImmutableArray<a>` | The sorted array |
|
|
3100
3146
|
|
|
3101
3147
|
Examples:
|
|
3102
3148
|
|
|
@@ -3121,7 +3167,7 @@ assert Immutable.sort(compare=(a, b) => a - b, arr) == Immutable.fromList([1, 2,
|
|
|
3121
3167
|
</details>
|
|
3122
3168
|
|
|
3123
3169
|
```grain
|
|
3124
|
-
rotate
|
|
3170
|
+
rotate: (n: Number, array: ImmutableArray<a>) => ImmutableArray<a>
|
|
3125
3171
|
```
|
|
3126
3172
|
|
|
3127
3173
|
Rotates array elements by the specified amount to the left, such that the
|
|
@@ -3132,10 +3178,10 @@ specified amount to the right. See examples.
|
|
|
3132
3178
|
|
|
3133
3179
|
Parameters:
|
|
3134
3180
|
|
|
3135
|
-
|param|type|description|
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3181
|
+
| param | type | description |
|
|
3182
|
+
| ------- | ------------------- | ----------------------------------- |
|
|
3183
|
+
| `n` | `Number` | The number of elements to rotate by |
|
|
3184
|
+
| `array` | `ImmutableArray<a>` | The array to be rotated |
|
|
3139
3185
|
|
|
3140
3186
|
Examples:
|
|
3141
3187
|
|