@grain/stdlib 0.5.13 → 0.6.0

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.
Files changed (155) hide show
  1. package/CHANGELOG.md +193 -0
  2. package/LICENSE +1 -1
  3. package/README.md +25 -2
  4. package/array.gr +1512 -199
  5. package/array.md +2032 -94
  6. package/bigint.gr +239 -140
  7. package/bigint.md +450 -106
  8. package/buffer.gr +595 -102
  9. package/buffer.md +903 -145
  10. package/bytes.gr +401 -110
  11. package/bytes.md +551 -63
  12. package/char.gr +228 -49
  13. package/char.md +373 -7
  14. package/exception.gr +26 -12
  15. package/exception.md +29 -5
  16. package/float32.gr +130 -109
  17. package/float32.md +185 -57
  18. package/float64.gr +112 -99
  19. package/float64.md +185 -57
  20. package/hash.gr +47 -37
  21. package/hash.md +21 -3
  22. package/int16.gr +430 -0
  23. package/int16.md +618 -0
  24. package/int32.gr +200 -269
  25. package/int32.md +254 -289
  26. package/int64.gr +142 -225
  27. package/int64.md +254 -289
  28. package/int8.gr +511 -0
  29. package/int8.md +786 -0
  30. package/json.gr +2084 -0
  31. package/json.md +608 -0
  32. package/list.gr +120 -68
  33. package/list.md +125 -80
  34. package/map.gr +560 -57
  35. package/map.md +672 -56
  36. package/marshal.gr +239 -227
  37. package/marshal.md +36 -4
  38. package/number.gr +626 -676
  39. package/number.md +738 -153
  40. package/option.gr +33 -35
  41. package/option.md +58 -42
  42. package/package.json +2 -2
  43. package/path.gr +148 -187
  44. package/path.md +47 -96
  45. package/pervasives.gr +75 -416
  46. package/pervasives.md +85 -180
  47. package/priorityqueue.gr +433 -74
  48. package/priorityqueue.md +422 -54
  49. package/queue.gr +362 -80
  50. package/queue.md +433 -38
  51. package/random.gr +67 -75
  52. package/random.md +68 -40
  53. package/range.gr +135 -63
  54. package/range.md +198 -43
  55. package/rational.gr +284 -0
  56. package/rational.md +545 -0
  57. package/regex.gr +933 -1066
  58. package/regex.md +59 -60
  59. package/result.gr +23 -25
  60. package/result.md +54 -39
  61. package/runtime/atof/common.gr +78 -82
  62. package/runtime/atof/common.md +22 -10
  63. package/runtime/atof/decimal.gr +102 -127
  64. package/runtime/atof/decimal.md +28 -7
  65. package/runtime/atof/lemire.gr +56 -71
  66. package/runtime/atof/lemire.md +9 -1
  67. package/runtime/atof/parse.gr +83 -110
  68. package/runtime/atof/parse.md +12 -2
  69. package/runtime/atof/slow.gr +28 -35
  70. package/runtime/atof/slow.md +9 -1
  71. package/runtime/atof/table.gr +19 -18
  72. package/runtime/atof/table.md +10 -2
  73. package/runtime/atoi/parse.gr +153 -136
  74. package/runtime/atoi/parse.md +50 -1
  75. package/runtime/bigint.gr +410 -517
  76. package/runtime/bigint.md +71 -57
  77. package/runtime/compare.gr +176 -85
  78. package/runtime/compare.md +31 -1
  79. package/runtime/dataStructures.gr +144 -32
  80. package/runtime/dataStructures.md +267 -31
  81. package/runtime/debugPrint.gr +34 -15
  82. package/runtime/debugPrint.md +37 -5
  83. package/runtime/equal.gr +53 -52
  84. package/runtime/equal.md +30 -1
  85. package/runtime/exception.gr +38 -47
  86. package/runtime/exception.md +10 -8
  87. package/runtime/gc.gr +23 -152
  88. package/runtime/gc.md +13 -17
  89. package/runtime/malloc.gr +31 -31
  90. package/runtime/malloc.md +11 -3
  91. package/runtime/numberUtils.gr +191 -172
  92. package/runtime/numberUtils.md +17 -9
  93. package/runtime/numbers.gr +1695 -1021
  94. package/runtime/numbers.md +1098 -134
  95. package/runtime/string.gr +540 -242
  96. package/runtime/string.md +76 -6
  97. package/runtime/unsafe/constants.gr +30 -13
  98. package/runtime/unsafe/constants.md +80 -0
  99. package/runtime/unsafe/conv.gr +55 -28
  100. package/runtime/unsafe/conv.md +41 -9
  101. package/runtime/unsafe/memory.gr +10 -30
  102. package/runtime/unsafe/memory.md +15 -19
  103. package/runtime/unsafe/tags.gr +37 -21
  104. package/runtime/unsafe/tags.md +88 -8
  105. package/runtime/unsafe/wasmf32.gr +30 -36
  106. package/runtime/unsafe/wasmf32.md +64 -56
  107. package/runtime/unsafe/wasmf64.gr +30 -36
  108. package/runtime/unsafe/wasmf64.md +64 -56
  109. package/runtime/unsafe/wasmi32.gr +49 -66
  110. package/runtime/unsafe/wasmi32.md +102 -94
  111. package/runtime/unsafe/wasmi64.gr +52 -79
  112. package/runtime/unsafe/wasmi64.md +108 -100
  113. package/runtime/utils/printing.gr +13 -15
  114. package/runtime/utils/printing.md +11 -3
  115. package/runtime/wasi.gr +294 -295
  116. package/runtime/wasi.md +62 -42
  117. package/set.gr +574 -64
  118. package/set.md +634 -54
  119. package/stack.gr +181 -64
  120. package/stack.md +271 -42
  121. package/string.gr +453 -533
  122. package/string.md +241 -151
  123. package/uint16.gr +369 -0
  124. package/uint16.md +585 -0
  125. package/uint32.gr +470 -0
  126. package/uint32.md +737 -0
  127. package/uint64.gr +471 -0
  128. package/uint64.md +737 -0
  129. package/uint8.gr +369 -0
  130. package/uint8.md +585 -0
  131. package/uri.gr +1093 -0
  132. package/uri.md +477 -0
  133. package/{sys → wasi}/file.gr +914 -500
  134. package/{sys → wasi}/file.md +454 -50
  135. package/wasi/process.gr +292 -0
  136. package/{sys → wasi}/process.md +164 -6
  137. package/wasi/random.gr +77 -0
  138. package/wasi/random.md +80 -0
  139. package/{sys → wasi}/time.gr +15 -22
  140. package/{sys → wasi}/time.md +5 -5
  141. package/immutablearray.gr +0 -929
  142. package/immutablearray.md +0 -1038
  143. package/immutablemap.gr +0 -493
  144. package/immutablemap.md +0 -479
  145. package/immutablepriorityqueue.gr +0 -360
  146. package/immutablepriorityqueue.md +0 -291
  147. package/immutableset.gr +0 -498
  148. package/immutableset.md +0 -449
  149. package/runtime/debug.gr +0 -2
  150. package/runtime/debug.md +0 -6
  151. package/runtime/unsafe/errors.gr +0 -36
  152. package/runtime/unsafe/errors.md +0 -204
  153. package/sys/process.gr +0 -254
  154. package/sys/random.gr +0 -79
  155. package/sys/random.md +0 -66
package/immutablearray.md DELETED
@@ -1,1038 +0,0 @@
1
- ---
2
- title: ImmutableArray
3
- ---
4
-
5
- An immutable array implementation, providing fast arbitrary lookups and modifications.
6
-
7
- <details disabled>
8
- <summary tabindex="-1">Added in <code>next</code></summary>
9
- No other changes yet.
10
- </details>
11
-
12
- ```grain
13
- import ImmutableArray from "immutablearray"
14
- ```
15
-
16
- ## Types
17
-
18
- Type declarations included in the ImmutableArray module.
19
-
20
- ### ImmutableArray.**ImmutableArray**
21
-
22
- ```grain
23
- type ImmutableArray<a>
24
- ```
25
-
26
- ## Values
27
-
28
- Functions and constants for working with immutable arrays.
29
-
30
- ### ImmutableArray.**empty**
31
-
32
- <details disabled>
33
- <summary tabindex="-1">Added in <code>next</code></summary>
34
- No other changes yet.
35
- </details>
36
-
37
- ```grain
38
- empty : ImmutableArray<a>
39
- ```
40
-
41
- An empty array.
42
-
43
- ### ImmutableArray.**isEmpty**
44
-
45
- <details disabled>
46
- <summary tabindex="-1">Added in <code>next</code></summary>
47
- No other changes yet.
48
- </details>
49
-
50
- ```grain
51
- isEmpty : ImmutableArray<a> -> Bool
52
- ```
53
-
54
- Determines if the array contains no elements.
55
-
56
- Parameters:
57
-
58
- |param|type|description|
59
- |-----|----|-----------|
60
- |`array`|`ImmutableArray<a>`|The array to check|
61
-
62
- Returns:
63
-
64
- |type|description|
65
- |----|-----------|
66
- |`Bool`|`true` if the array is empty and `false` otherwise|
67
-
68
- ### ImmutableArray.**length**
69
-
70
- <details disabled>
71
- <summary tabindex="-1">Added in <code>next</code></summary>
72
- No other changes yet.
73
- </details>
74
-
75
- ```grain
76
- length : ImmutableArray<a> -> Number
77
- ```
78
-
79
- Provides the length of the input array.
80
-
81
- Parameters:
82
-
83
- |param|type|description|
84
- |-----|----|-----------|
85
- |`array`|`ImmutableArray<a>`|The array to inspect|
86
-
87
- Returns:
88
-
89
- |type|description|
90
- |----|-----------|
91
- |`Number`|The number of elements in the array|
92
-
93
- Examples:
94
-
95
- ```grain
96
- length(fromList([1, 2, 3, 4, 5])) == 5
97
- ```
98
-
99
- ### ImmutableArray.**get**
100
-
101
- <details disabled>
102
- <summary tabindex="-1">Added in <code>next</code></summary>
103
- No other changes yet.
104
- </details>
105
-
106
- ```grain
107
- get : (Number, ImmutableArray<a>) -> a
108
- ```
109
-
110
- Retrieves the element from the array at the specified index.
111
- A negative index is treated as an offset from the end of the array.
112
-
113
- Parameters:
114
-
115
- |param|type|description|
116
- |-----|----|-----------|
117
- |`index`|`Number`|The index to access|
118
- |`array`|`ImmutableArray<a>`|The array to access|
119
-
120
- Returns:
121
-
122
- |type|description|
123
- |----|-----------|
124
- |`a`|The element from the array|
125
-
126
- Throws:
127
-
128
- `IndexOutOfBounds`
129
-
130
- * When the index being accessed is outside the array's bounds
131
-
132
- Examples:
133
-
134
- ```grain
135
- get(1, fromList([1, 2, 3, 4])) == 2
136
- ```
137
-
138
- ```grain
139
- get(-1, fromList([1, 2, 3, 4])) == 4
140
- ```
141
-
142
- ### ImmutableArray.**set**
143
-
144
- <details disabled>
145
- <summary tabindex="-1">Added in <code>next</code></summary>
146
- No other changes yet.
147
- </details>
148
-
149
- ```grain
150
- set : (Number, a, ImmutableArray<a>) -> ImmutableArray<a>
151
- ```
152
-
153
- Creates a new array in which the element at the specified index is set to a
154
- new value. A negative index is treated as an offset from the end of the array.
155
-
156
- Parameters:
157
-
158
- |param|type|description|
159
- |-----|----|-----------|
160
- |`index`|`Number`|The index to update|
161
- |`value`|`a`|The value to store|
162
- |`array`|`ImmutableArray<a>`|The array to update|
163
-
164
- Returns:
165
-
166
- |type|description|
167
- |----|-----------|
168
- |`ImmutableArray<a>`|A new array containing the new element at the given index|
169
-
170
- Throws:
171
-
172
- `IndexOutOfBounds`
173
-
174
- * When the index being updated is outside the array's bounds
175
-
176
- Examples:
177
-
178
- ```grain
179
- set(1, 9, fromList([1, 2, 3, 4, 5])) == fromList([1, 9, 3, 4, 5])
180
- ```
181
-
182
- ### ImmutableArray.**append**
183
-
184
- <details disabled>
185
- <summary tabindex="-1">Added in <code>next</code></summary>
186
- No other changes yet.
187
- </details>
188
-
189
- ```grain
190
- append : (ImmutableArray<a>, ImmutableArray<a>) -> ImmutableArray<a>
191
- ```
192
-
193
- Creates a new array with the elements of the first array followed by
194
- the elements of the second array.
195
-
196
- Parameters:
197
-
198
- |param|type|description|
199
- |-----|----|-----------|
200
- |`array1`|`ImmutableArray<a>`|The array containing elements to appear first|
201
- |`array2`|`ImmutableArray<a>`|The array containing elements to appear second|
202
-
203
- Returns:
204
-
205
- |type|description|
206
- |----|-----------|
207
- |`ImmutableArray<a>`|The new array containing elements from `array1` followed by elements from `array2`|
208
-
209
- Examples:
210
-
211
- ```grain
212
- append(fromList([1, 2]), fromList([3, 4, 5])) == fromList([1, 2, 3, 4, 5])
213
- ```
214
-
215
- ### ImmutableArray.**concat**
216
-
217
- <details disabled>
218
- <summary tabindex="-1">Added in <code>next</code></summary>
219
- No other changes yet.
220
- </details>
221
-
222
- ```grain
223
- concat : List<ImmutableArray<a>> -> ImmutableArray<a>
224
- ```
225
-
226
- Creates a single array containing the elements of all arrays in the
227
- provided list.
228
-
229
- Parameters:
230
-
231
- |param|type|description|
232
- |-----|----|-----------|
233
- |`arrays`|`List<ImmutableArray<a>>`|A list containing all arrays to combine|
234
-
235
- Returns:
236
-
237
- |type|description|
238
- |----|-----------|
239
- |`ImmutableArray<a>`|The new array|
240
-
241
- Examples:
242
-
243
- ```grain
244
- concat([fromList([1, 2]), fromList([3, 4]), fromList([5, 6])]) == fromList([1, 2, 3, 4, 5, 6])
245
- ```
246
-
247
- ### ImmutableArray.**init**
248
-
249
- <details disabled>
250
- <summary tabindex="-1">Added in <code>next</code></summary>
251
- No other changes yet.
252
- </details>
253
-
254
- ```grain
255
- init : (Number, (Number -> a)) -> ImmutableArray<a>
256
- ```
257
-
258
- Creates a new array of the specified length where each element is
259
- initialized with the result of an initializer function. The initializer
260
- is called with the index of each array element.
261
-
262
- Parameters:
263
-
264
- |param|type|description|
265
- |-----|----|-----------|
266
- |`length`|`Number`|The length of the new array|
267
- |`fn`|`Number -> a`|The initializer function to call with each index, where the value returned will be used to initialize the element|
268
-
269
- Returns:
270
-
271
- |type|description|
272
- |----|-----------|
273
- |`ImmutableArray<a>`|The new array|
274
-
275
- Examples:
276
-
277
- ```grain
278
- init(5, i => i + 3) == fromList([3, 4, 5, 6, 7])
279
- ```
280
-
281
- ### ImmutableArray.**make**
282
-
283
- <details disabled>
284
- <summary tabindex="-1">Added in <code>next</code></summary>
285
- No other changes yet.
286
- </details>
287
-
288
- ```grain
289
- make : (Number, a) -> ImmutableArray<a>
290
- ```
291
-
292
- Creates a new array of the specified length with each element being
293
- initialized with the given value.
294
-
295
- Parameters:
296
-
297
- |param|type|description|
298
- |-----|----|-----------|
299
- |`length`|`Number`|The length of the new array|
300
- |`value`|`a`|The value to store at each index|
301
-
302
- Returns:
303
-
304
- |type|description|
305
- |----|-----------|
306
- |`ImmutableArray<a>`|The new array|
307
-
308
- Examples:
309
-
310
- ```grain
311
- make(5, "foo") == fromList(["foo", "foo", "foo", "foo", "foo"])
312
- ```
313
-
314
- ### ImmutableArray.**forEach**
315
-
316
- <details disabled>
317
- <summary tabindex="-1">Added in <code>next</code></summary>
318
- No other changes yet.
319
- </details>
320
-
321
- ```grain
322
- forEach : ((a -> Void), ImmutableArray<a>) -> Void
323
- ```
324
-
325
- Iterates an array, calling an iterator function on each element.
326
-
327
- Parameters:
328
-
329
- |param|type|description|
330
- |-----|----|-----------|
331
- |`fn`|`a -> Void`|The iterator function to call with each element|
332
- |`array`|`ImmutableArray<a>`|The array to iterate|
333
-
334
- ### ImmutableArray.**cycle**
335
-
336
- <details disabled>
337
- <summary tabindex="-1">Added in <code>next</code></summary>
338
- No other changes yet.
339
- </details>
340
-
341
- ```grain
342
- cycle : ((a -> Void), Number, ImmutableArray<a>) -> Void
343
- ```
344
-
345
- Iterates an array a given number of times, calling an iterator function on each element.
346
-
347
- Parameters:
348
-
349
- |param|type|description|
350
- |-----|----|-----------|
351
- |`fn`|`a -> Void`|The iterator function to call with each element|
352
- |`n`|`Number`|The number of times to iterate the given array|
353
- |`array`|`ImmutableArray<a>`|The array to iterate|
354
-
355
- ### ImmutableArray.**map**
356
-
357
- <details disabled>
358
- <summary tabindex="-1">Added in <code>next</code></summary>
359
- No other changes yet.
360
- </details>
361
-
362
- ```grain
363
- map : ((a -> b), ImmutableArray<a>) -> ImmutableArray<b>
364
- ```
365
-
366
- Produces a new array initialized with the results of a mapper function
367
- called on each element of the input array.
368
-
369
- Parameters:
370
-
371
- |param|type|description|
372
- |-----|----|-----------|
373
- |`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|
374
- |`array`|`ImmutableArray<a>`|The array to iterate|
375
-
376
- Returns:
377
-
378
- |type|description|
379
- |----|-----------|
380
- |`ImmutableArray<b>`|The new array with mapped values|
381
-
382
- ### ImmutableArray.**reduce**
383
-
384
- <details disabled>
385
- <summary tabindex="-1">Added in <code>next</code></summary>
386
- No other changes yet.
387
- </details>
388
-
389
- ```grain
390
- reduce : (((a, b) -> a), a, ImmutableArray<b>) -> a
391
- ```
392
-
393
- Combines all elements of an array using a reducer function,
394
- starting from the "head", or left side, of the array.
395
-
396
- In `ImmutableArray.reduce(fn, initial, array)`, `fn` is called with
397
- an accumulator and each element of the array, and returns
398
- a new accumulator. The final value is the last accumulator
399
- returned. The accumulator starts with value `initial`.
400
-
401
- Parameters:
402
-
403
- |param|type|description|
404
- |-----|----|-----------|
405
- |`fn`|`(a, b) -> a`|The reducer function to call on each element, where the value returned will be the next accumulator value|
406
- |`initial`|`a`|The initial value to use for the accumulator on the first iteration|
407
- |`array`|`ImmutableArray<b>`|The array to iterate|
408
-
409
- Returns:
410
-
411
- |type|description|
412
- |----|-----------|
413
- |`a`|The final accumulator returned from `fn`|
414
-
415
- Examples:
416
-
417
- ```grain
418
- reduce((acc, x) => acc + x, 0, fromList([1, 2, 3])) == 6
419
- ```
420
-
421
- ### ImmutableArray.**reduceRight**
422
-
423
- <details disabled>
424
- <summary tabindex="-1">Added in <code>next</code></summary>
425
- No other changes yet.
426
- </details>
427
-
428
- ```grain
429
- reduceRight : (((a, b) -> b), b, ImmutableArray<a>) -> b
430
- ```
431
-
432
- Combines all elements of an array using a reducer function,
433
- starting from the "end", or right side, of the array.
434
-
435
- In `ImmutableArray.reduceRight(fn, initial, array)`, `fn` is called with
436
- each element of the array and an accumulator, and returns
437
- a new accumulator. The final value is the last accumulator
438
- returned. The accumulator starts with value `initial`.
439
-
440
- Parameters:
441
-
442
- |param|type|description|
443
- |-----|----|-----------|
444
- |`fn`|`(a, b) -> b`|The reducer function to call on each element, where the value returned will be the next accumulator value|
445
- |`initial`|`b`|The initial value to use for the accumulator on the first iteration|
446
- |`array`|`ImmutableArray<a>`|The array to iterate|
447
-
448
- Returns:
449
-
450
- |type|description|
451
- |----|-----------|
452
- |`b`|The final accumulator returned from `fn`|
453
-
454
- Examples:
455
-
456
- ```grain
457
- reduceRight((x, acc) => acc ++ x, "", fromList(["baz", "bar", "foo"])) == "foobarbaz"
458
- ```
459
-
460
- ### ImmutableArray.**flatMap**
461
-
462
- <details disabled>
463
- <summary tabindex="-1">Added in <code>next</code></summary>
464
- No other changes yet.
465
- </details>
466
-
467
- ```grain
468
- flatMap : ((a -> ImmutableArray<b>), ImmutableArray<a>) -> ImmutableArray<b>
469
- ```
470
-
471
- Produces a new array by calling a function on each element
472
- of the input array. Each iteration produces an intermediate
473
- array, which are all appended to produce a "flattened" array
474
- of all results.
475
-
476
- Parameters:
477
-
478
- |param|type|description|
479
- |-----|----|-----------|
480
- |`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|
481
- |`array`|`ImmutableArray<a>`|The array to iterate|
482
-
483
- Returns:
484
-
485
- |type|description|
486
- |----|-----------|
487
- |`ImmutableArray<b>`|The new array|
488
-
489
- Examples:
490
-
491
- ```grain
492
- flatMap(n => fromList([n, n + 1]), fromList([1, 3, 5])) == fromList([1, 2, 3, 4, 5, 6])
493
- ```
494
-
495
- ### ImmutableArray.**fromList**
496
-
497
- <details disabled>
498
- <summary tabindex="-1">Added in <code>next</code></summary>
499
- No other changes yet.
500
- </details>
501
-
502
- ```grain
503
- fromList : List<a> -> ImmutableArray<a>
504
- ```
505
-
506
- Converts the input list to an array.
507
-
508
- Parameters:
509
-
510
- |param|type|description|
511
- |-----|----|-----------|
512
- |`list`|`List<a>`|The list to convert|
513
-
514
- Returns:
515
-
516
- |type|description|
517
- |----|-----------|
518
- |`ImmutableArray<a>`|The array containing all elements from the list|
519
-
520
- ### ImmutableArray.**toList**
521
-
522
- <details disabled>
523
- <summary tabindex="-1">Added in <code>next</code></summary>
524
- No other changes yet.
525
- </details>
526
-
527
- ```grain
528
- toList : ImmutableArray<a> -> List<a>
529
- ```
530
-
531
- Converts the input array to a list.
532
-
533
- Parameters:
534
-
535
- |param|type|description|
536
- |-----|----|-----------|
537
- |`array`|`ImmutableArray<a>`|The array to convert|
538
-
539
- Returns:
540
-
541
- |type|description|
542
- |----|-----------|
543
- |`List<a>`|The list containing all elements from the array|
544
-
545
- ### ImmutableArray.**filter**
546
-
547
- <details disabled>
548
- <summary tabindex="-1">Added in <code>next</code></summary>
549
- No other changes yet.
550
- </details>
551
-
552
- ```grain
553
- filter : ((a -> Bool), ImmutableArray<a>) -> ImmutableArray<a>
554
- ```
555
-
556
- Produces a new array by calling a function on each element of
557
- the input array and only including it in the result array if the element satisfies
558
- the condition.
559
-
560
- Parameters:
561
-
562
- |param|type|description|
563
- |-----|----|-----------|
564
- |`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
565
- |`array`|`ImmutableArray<a>`|The array to iterate|
566
-
567
- Returns:
568
-
569
- |type|description|
570
- |----|-----------|
571
- |`ImmutableArray<a>`|The new array containing elements where `fn` returned `true`|
572
-
573
- ### ImmutableArray.**every**
574
-
575
- <details disabled>
576
- <summary tabindex="-1">Added in <code>next</code></summary>
577
- No other changes yet.
578
- </details>
579
-
580
- ```grain
581
- every : ((a -> Bool), ImmutableArray<a>) -> Bool
582
- ```
583
-
584
- Checks that the given condition is satisfied for all
585
- elements in the input array.
586
-
587
- Parameters:
588
-
589
- |param|type|description|
590
- |-----|----|-----------|
591
- |`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
592
- |`array`|`ImmutableArray<a>`|The array to check|
593
-
594
- Returns:
595
-
596
- |type|description|
597
- |----|-----------|
598
- |`Bool`|`true` if all elements satify the condition or `false` otherwise|
599
-
600
- ### ImmutableArray.**some**
601
-
602
- <details disabled>
603
- <summary tabindex="-1">Added in <code>next</code></summary>
604
- No other changes yet.
605
- </details>
606
-
607
- ```grain
608
- some : ((a -> Bool), ImmutableArray<a>) -> Bool
609
- ```
610
-
611
- Checks that the given condition is satisfied **at least
612
- once** by an element in the input array.
613
-
614
- Parameters:
615
-
616
- |param|type|description|
617
- |-----|----|-----------|
618
- |`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
619
- |`array`|`ImmutableArray<a>`|The array to iterate|
620
-
621
- Returns:
622
-
623
- |type|description|
624
- |----|-----------|
625
- |`Bool`|`true` if one or more elements satify the condition or `false` otherwise|
626
-
627
- ### ImmutableArray.**reverse**
628
-
629
- <details disabled>
630
- <summary tabindex="-1">Added in <code>next</code></summary>
631
- No other changes yet.
632
- </details>
633
-
634
- ```grain
635
- reverse : ImmutableArray<a> -> ImmutableArray<a>
636
- ```
637
-
638
- Creates a new array with all elements in reverse order.
639
-
640
- Parameters:
641
-
642
- |param|type|description|
643
- |-----|----|-----------|
644
- |`array`|`ImmutableArray<a>`|The array to reverse|
645
-
646
- Returns:
647
-
648
- |type|description|
649
- |----|-----------|
650
- |`ImmutableArray<a>`|The new array|
651
-
652
- ### ImmutableArray.**contains**
653
-
654
- <details disabled>
655
- <summary tabindex="-1">Added in <code>next</code></summary>
656
- No other changes yet.
657
- </details>
658
-
659
- ```grain
660
- contains : (a, ImmutableArray<a>) -> Bool
661
- ```
662
-
663
- Checks if the value is an element of the input array.
664
- Uses the generic `==` structural equality operator.
665
-
666
- Parameters:
667
-
668
- |param|type|description|
669
- |-----|----|-----------|
670
- |`search`|`a`|The value to compare|
671
- |`array`|`ImmutableArray<a>`|The array to inspect|
672
-
673
- Returns:
674
-
675
- |type|description|
676
- |----|-----------|
677
- |`Bool`|`true` if the value exists in the array or `false` otherwise|
678
-
679
- ### ImmutableArray.**find**
680
-
681
- <details disabled>
682
- <summary tabindex="-1">Added in <code>next</code></summary>
683
- No other changes yet.
684
- </details>
685
-
686
- ```grain
687
- find : ((a -> Bool), ImmutableArray<a>) -> Option<a>
688
- ```
689
-
690
- Finds the first element in an array that satifies the given condition.
691
-
692
- Parameters:
693
-
694
- |param|type|description|
695
- |-----|----|-----------|
696
- |`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
697
- |`array`|`ImmutableArray<a>`|The array to search|
698
-
699
- Returns:
700
-
701
- |type|description|
702
- |----|-----------|
703
- |`Option<a>`|`Some(element)` containing the first value found or `None` otherwise|
704
-
705
- ### ImmutableArray.**findIndex**
706
-
707
- <details disabled>
708
- <summary tabindex="-1">Added in <code>next</code></summary>
709
- No other changes yet.
710
- </details>
711
-
712
- ```grain
713
- findIndex : ((a -> Bool), ImmutableArray<a>) -> Option<Number>
714
- ```
715
-
716
- Finds the first index in an array where the element satifies the given condition.
717
-
718
- Parameters:
719
-
720
- |param|type|description|
721
- |-----|----|-----------|
722
- |`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
723
- |`array`|`ImmutableArray<a>`|The array to search|
724
-
725
- Returns:
726
-
727
- |type|description|
728
- |----|-----------|
729
- |`Option<Number>`|`Some(index)` containing the index of the first element found or `None` otherwise|
730
-
731
- ### ImmutableArray.**product**
732
-
733
- <details disabled>
734
- <summary tabindex="-1">Added in <code>next</code></summary>
735
- No other changes yet.
736
- </details>
737
-
738
- ```grain
739
- product : (ImmutableArray<a>, ImmutableArray<b>) -> ImmutableArray<(a, b)>
740
- ```
741
-
742
- Combines two arrays into a Cartesian product of tuples containing
743
- all ordered pairs `(a, b)`.
744
-
745
- Parameters:
746
-
747
- |param|type|description|
748
- |-----|----|-----------|
749
- |`array1`|`ImmutableArray<a>`|The array to provide values for the first tuple element|
750
- |`array2`|`ImmutableArray<b>`|The array to provide values for the second tuple element|
751
-
752
- Returns:
753
-
754
- |type|description|
755
- |----|-----------|
756
- |`ImmutableArray<(a, b)>`|The new array containing all pairs of `(a, b)`|
757
-
758
- ### ImmutableArray.**count**
759
-
760
- <details disabled>
761
- <summary tabindex="-1">Added in <code>next</code></summary>
762
- No other changes yet.
763
- </details>
764
-
765
- ```grain
766
- count : ((a -> Bool), ImmutableArray<a>) -> Number
767
- ```
768
-
769
- Counts the number of elements in an array that satisfy the given condition.
770
-
771
- Parameters:
772
-
773
- |param|type|description|
774
- |-----|----|-----------|
775
- |`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
776
- |`array`|`ImmutableArray<a>`|The array to iterate|
777
-
778
- Returns:
779
-
780
- |type|description|
781
- |----|-----------|
782
- |`Number`|The total number of elements that satisfy the condition|
783
-
784
- ### ImmutableArray.**unique**
785
-
786
- <details disabled>
787
- <summary tabindex="-1">Added in <code>next</code></summary>
788
- No other changes yet.
789
- </details>
790
-
791
- ```grain
792
- unique : ImmutableArray<a> -> ImmutableArray<a>
793
- ```
794
-
795
- Produces a new array with any duplicates removed.
796
- Uses the generic `==` structural equality operator.
797
-
798
- Parameters:
799
-
800
- |param|type|description|
801
- |-----|----|-----------|
802
- |`array`|`ImmutableArray<a>`|The array to filter|
803
-
804
- Returns:
805
-
806
- |type|description|
807
- |----|-----------|
808
- |`ImmutableArray<a>`|The new array with only unique values|
809
-
810
- ### ImmutableArray.**zip**
811
-
812
- <details disabled>
813
- <summary tabindex="-1">Added in <code>next</code></summary>
814
- No other changes yet.
815
- </details>
816
-
817
- ```grain
818
- zip : (ImmutableArray<a>, ImmutableArray<b>) -> ImmutableArray<(a, b)>
819
- ```
820
-
821
- Produces a new array filled with tuples of elements from both given arrays.
822
- The first tuple will contain the first item of each array, the second tuple
823
- will contain the second item of each array, and so on.
824
-
825
- Calling this function with arrays of different sizes will cause the returned
826
- array to have the length of the smaller array.
827
-
828
- Parameters:
829
-
830
- |param|type|description|
831
- |-----|----|-----------|
832
- |`array1`|`ImmutableArray<a>`|The array to provide values for the first tuple element|
833
- |`array2`|`ImmutableArray<b>`|The array to provide values for the second tuple element|
834
-
835
- Returns:
836
-
837
- |type|description|
838
- |----|-----------|
839
- |`ImmutableArray<(a, b)>`|The new array containing indexed pairs of `(a, b)`|
840
-
841
- ### ImmutableArray.**zipWith**
842
-
843
- <details disabled>
844
- <summary tabindex="-1">Added in <code>next</code></summary>
845
- No other changes yet.
846
- </details>
847
-
848
- ```grain
849
- zipWith :
850
- (((a, b) -> c), ImmutableArray<a>, ImmutableArray<b>) -> ImmutableArray<c>
851
- ```
852
-
853
- Produces a new array filled with elements defined by applying a function on
854
- pairs from both given arrays. The first element will contain the result of
855
- applying the function to the first elements of each array, the second element
856
- will contain the result of applying the function to the second elements of
857
- each array, and so on.
858
-
859
- Calling this function with arrays of different sizes will cause the returned
860
- array to have the length of the smaller array.
861
-
862
- Parameters:
863
-
864
- |param|type|description|
865
- |-----|----|-----------|
866
- |`fn`|`(a, b) -> c`|The function to apply to pairs of elements|
867
- |`array1`|`ImmutableArray<a>`|The array whose elements will each be passed to the function as the first argument|
868
- |`array2`|`ImmutableArray<b>`|The array whose elements will each be passed to the function as the second argument|
869
-
870
- Returns:
871
-
872
- |type|description|
873
- |----|-----------|
874
- |`ImmutableArray<c>`|The new array containing elements derived from applying the function to pairs of input array elements|
875
-
876
- Examples:
877
-
878
- ```grain
879
- zipWith((a, b) => a + b, fromList([1, 2, 3]), fromList([4, 5, 6])) == fromList([5, 7, 9])
880
- ```
881
-
882
- ```grain
883
- zipWith((a, b) => a * b, fromList([1, 2, 3]), fromList([4, 5])) == fromList([4, 10])
884
- ```
885
-
886
- ### ImmutableArray.**unzip**
887
-
888
- <details disabled>
889
- <summary tabindex="-1">Added in <code>next</code></summary>
890
- No other changes yet.
891
- </details>
892
-
893
- ```grain
894
- unzip : ImmutableArray<(a, b)> -> (ImmutableArray<a>, ImmutableArray<b>)
895
- ```
896
-
897
- Produces two arrays by splitting apart an array of tuples.
898
-
899
- Parameters:
900
-
901
- |param|type|description|
902
- |-----|----|-----------|
903
- |`array`|`ImmutableArray<(a, b)>`|The array of tuples to split|
904
-
905
- Returns:
906
-
907
- |type|description|
908
- |----|-----------|
909
- |`(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|
910
-
911
- ### ImmutableArray.**join**
912
-
913
- <details disabled>
914
- <summary tabindex="-1">Added in <code>next</code></summary>
915
- No other changes yet.
916
- </details>
917
-
918
- ```grain
919
- join : (String, ImmutableArray<String>) -> String
920
- ```
921
-
922
- Concatenates an array of strings into a single string, separated by a separator string.
923
-
924
- Parameters:
925
-
926
- |param|type|description|
927
- |-----|----|-----------|
928
- |`separator`|`String`|The separator to insert between items in the string|
929
- |`array`|`ImmutableArray<String>`|The input strings|
930
-
931
- Returns:
932
-
933
- |type|description|
934
- |----|-----------|
935
- |`String`|The concatenated string|
936
-
937
- ### ImmutableArray.**slice**
938
-
939
- <details disabled>
940
- <summary tabindex="-1">Added in <code>next</code></summary>
941
- No other changes yet.
942
- </details>
943
-
944
- ```grain
945
- slice : (Number, Number, ImmutableArray<a>) -> ImmutableArray<a>
946
- ```
947
-
948
- Slices an array given zero-based start and end indexes. The value
949
- at the end index will not be included in the result.
950
-
951
- If either index is a negative number, it will be treated as a reverse index from
952
- the end of the array.
953
-
954
- Parameters:
955
-
956
- |param|type|description|
957
- |-----|----|-----------|
958
- |`start`|`Number`|The index of the array where the slice will begin (inclusive)|
959
- |`end`|`Number`|The index of the array where the slice will end (exclusive)|
960
- |`array`|`ImmutableArray<a>`|The array to be sliced|
961
-
962
- Returns:
963
-
964
- |type|description|
965
- |----|-----------|
966
- |`ImmutableArray<a>`|The subset of the array that was sliced|
967
-
968
- Examples:
969
-
970
- ```grain
971
- slice(0, 2, fromList(['a', 'b', 'c'])) == fromList(['a', 'b'])
972
- ```
973
-
974
- ```grain
975
- slice(1, -1, fromList(['a', 'b', 'c'])) == fromList(['b'])
976
- ```
977
-
978
- ### ImmutableArray.**sort**
979
-
980
- <details disabled>
981
- <summary tabindex="-1">Added in <code>next</code></summary>
982
- No other changes yet.
983
- </details>
984
-
985
- ```grain
986
- sort : (((a, a) -> Number), ImmutableArray<a>) -> ImmutableArray<a>
987
- ```
988
-
989
- Sorts the given array based on a given comparator function.
990
-
991
- Ordering is calculated using a comparator function which takes two array elements and must return 0 if both are equal, a positive number if the first is greater, and a negative number if the first is smaller.
992
-
993
- Parameters:
994
-
995
- |param|type|description|
996
- |-----|----|-----------|
997
- |`comp`|`(a, a) -> Number`|The comparator function used to indicate sort order|
998
- |`array`|`ImmutableArray<a>`|The array to be sorted|
999
-
1000
- Returns:
1001
-
1002
- |type|description|
1003
- |----|-----------|
1004
- |`ImmutableArray<a>`|The sorted array|
1005
-
1006
- ### ImmutableArray.**rotate**
1007
-
1008
- <details disabled>
1009
- <summary tabindex="-1">Added in <code>next</code></summary>
1010
- No other changes yet.
1011
- </details>
1012
-
1013
- ```grain
1014
- rotate : (Number, ImmutableArray<a>) -> ImmutableArray<a>
1015
- ```
1016
-
1017
- Rotates array elements by the specified amount to the left.
1018
-
1019
- If value is negative, array elements will be rotated by the
1020
- specified amount to the right. See examples.
1021
-
1022
- Parameters:
1023
-
1024
- |param|type|description|
1025
- |-----|----|-----------|
1026
- |`n`|`Number`|The number of elements to rotate by|
1027
- |`array`|`ImmutableArray<a>`|The array to be rotated|
1028
-
1029
- Examples:
1030
-
1031
- ```grain
1032
- rotate(2, fromList([1, 2, 3, 4, 5])) == fromList([3, 4, 5, 1, 2])
1033
- ```
1034
-
1035
- ```grain
1036
- rotate(-1, fromList([1, 2, 3, 4, 5])) == fromList([5, 1, 2, 3, 4])
1037
- ```
1038
-