@grain/stdlib 0.4.4 → 0.5.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 (97) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/LICENSE +1 -1
  3. package/array.gr +92 -73
  4. package/array.md +18 -18
  5. package/bigint.gr +497 -0
  6. package/bigint.md +811 -0
  7. package/buffer.gr +56 -217
  8. package/buffer.md +24 -17
  9. package/bytes.gr +103 -205
  10. package/bytes.md +19 -0
  11. package/char.gr +152 -166
  12. package/char.md +200 -0
  13. package/exception.md +6 -0
  14. package/float32.gr +159 -82
  15. package/float32.md +315 -0
  16. package/float64.gr +163 -82
  17. package/float64.md +315 -0
  18. package/hash.gr +53 -49
  19. package/int32.gr +479 -230
  20. package/int32.md +937 -0
  21. package/int64.gr +479 -230
  22. package/int64.md +937 -0
  23. package/list.gr +530 -116
  24. package/list.md +1141 -0
  25. package/map.gr +302 -121
  26. package/map.md +525 -0
  27. package/number.gr +51 -57
  28. package/number.md +37 -3
  29. package/option.gr +25 -25
  30. package/option.md +1 -1
  31. package/package.json +3 -3
  32. package/pervasives.gr +504 -52
  33. package/pervasives.md +1116 -0
  34. package/queue.gr +8 -1
  35. package/queue.md +10 -0
  36. package/random.gr +196 -0
  37. package/random.md +179 -0
  38. package/range.gr +26 -26
  39. package/regex.gr +1833 -842
  40. package/regex.md +11 -11
  41. package/result.md +1 -1
  42. package/runtime/bigint.gr +2045 -0
  43. package/runtime/bigint.md +326 -0
  44. package/runtime/dataStructures.gr +99 -279
  45. package/runtime/dataStructures.md +391 -0
  46. package/runtime/debug.gr +0 -1
  47. package/runtime/debug.md +6 -0
  48. package/runtime/equal.gr +40 -37
  49. package/runtime/equal.md +6 -0
  50. package/runtime/exception.gr +28 -15
  51. package/runtime/exception.md +30 -0
  52. package/runtime/gc.gr +50 -20
  53. package/runtime/gc.md +36 -0
  54. package/runtime/malloc.gr +32 -22
  55. package/runtime/malloc.md +55 -0
  56. package/runtime/numberUtils.gr +297 -142
  57. package/runtime/numberUtils.md +54 -0
  58. package/runtime/numbers.gr +1204 -453
  59. package/runtime/numbers.md +300 -0
  60. package/runtime/string.gr +193 -228
  61. package/runtime/string.md +24 -0
  62. package/runtime/stringUtils.gr +62 -38
  63. package/runtime/stringUtils.md +6 -0
  64. package/runtime/unsafe/constants.gr +17 -0
  65. package/runtime/unsafe/constants.md +72 -0
  66. package/runtime/unsafe/conv.gr +10 -10
  67. package/runtime/unsafe/conv.md +71 -0
  68. package/runtime/unsafe/errors.md +204 -0
  69. package/runtime/unsafe/memory.gr +14 -3
  70. package/runtime/unsafe/memory.md +54 -0
  71. package/runtime/unsafe/printWasm.gr +4 -4
  72. package/runtime/unsafe/printWasm.md +24 -0
  73. package/runtime/unsafe/tags.gr +11 -10
  74. package/runtime/unsafe/tags.md +120 -0
  75. package/runtime/unsafe/wasmf32.gr +9 -2
  76. package/runtime/unsafe/wasmf32.md +168 -0
  77. package/runtime/unsafe/wasmf64.gr +9 -2
  78. package/runtime/unsafe/wasmf64.md +168 -0
  79. package/runtime/unsafe/wasmi32.gr +65 -47
  80. package/runtime/unsafe/wasmi32.md +282 -0
  81. package/runtime/unsafe/wasmi64.gr +78 -50
  82. package/runtime/unsafe/wasmi64.md +300 -0
  83. package/runtime/utils/printing.gr +62 -0
  84. package/runtime/utils/printing.md +18 -0
  85. package/runtime/wasi.gr +200 -46
  86. package/runtime/wasi.md +839 -0
  87. package/set.gr +125 -121
  88. package/set.md +24 -21
  89. package/stack.gr +29 -29
  90. package/stack.md +4 -6
  91. package/string.gr +434 -415
  92. package/string.md +3 -3
  93. package/sys/file.gr +477 -482
  94. package/sys/process.gr +33 -47
  95. package/sys/random.gr +48 -20
  96. package/sys/random.md +38 -0
  97. package/sys/time.gr +12 -28
package/map.md ADDED
@@ -0,0 +1,525 @@
1
+ ---
2
+ title: Map
3
+ ---
4
+
5
+ A Map holds key-value pairs. Any value may be used as a key or value. Operations on a Map mutate the internal state, so it never needs to be re-assigned.
6
+
7
+ <details disabled>
8
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
9
+ No other changes yet.
10
+ </details>
11
+
12
+ ```grain
13
+ import Map from "map"
14
+ ```
15
+
16
+ ## Types
17
+
18
+ Type declarations included in the Map module.
19
+
20
+ ### Map.**Map**
21
+
22
+ ```grain
23
+ type Map<k, v>
24
+ ```
25
+
26
+ ## Values
27
+
28
+ Functions for working with Maps.
29
+
30
+ ### Map.**makeSized**
31
+
32
+ <details disabled>
33
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
34
+ No other changes yet.
35
+ </details>
36
+
37
+ ```grain
38
+ makeSized : Number -> Map<a, b>
39
+ ```
40
+
41
+ Creates a new empty map with an initial storage of the given size. As values are added or removed, the internal storage may grow or shrink. Generally, you won't need to care about the storage size of your map and can use `Map.make()` instead.
42
+
43
+ Parameters:
44
+
45
+ |param|type|description|
46
+ |-----|----|-----------|
47
+ |`size`|`Number`|The initial storage size of the map|
48
+
49
+ Returns:
50
+
51
+ |type|description|
52
+ |----|-----------|
53
+ |`Map<a, b>`|An empty map with the given initial storage size|
54
+
55
+ ### Map.**make**
56
+
57
+ <details disabled>
58
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
59
+ No other changes yet.
60
+ </details>
61
+
62
+ ```grain
63
+ make : () -> Map<a, b>
64
+ ```
65
+
66
+ Creates a new, empty map.
67
+
68
+ Returns:
69
+
70
+ |type|description|
71
+ |----|-----------|
72
+ |`Map<a, b>`|An empty map|
73
+
74
+ ### Map.**set**
75
+
76
+ <details disabled>
77
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
78
+ No other changes yet.
79
+ </details>
80
+
81
+ ```grain
82
+ set : (a, b, Map<a, b>) -> Void
83
+ ```
84
+
85
+ Adds a new key-value pair to the map. If the key already exists in the map, the value is replaced.
86
+
87
+ Parameters:
88
+
89
+ |param|type|description|
90
+ |-----|----|-----------|
91
+ |`key`|`a`|The unique key in the map|
92
+ |`value`|`b`|The value to store|
93
+ |`map`|`Map<a, b>`|The map to modify|
94
+
95
+ ### Map.**get**
96
+
97
+ <details disabled>
98
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
99
+ No other changes yet.
100
+ </details>
101
+
102
+ ```grain
103
+ get : (a, Map<a, b>) -> Option<b>
104
+ ```
105
+
106
+ Retrieves the value for the given key.
107
+
108
+ Parameters:
109
+
110
+ |param|type|description|
111
+ |-----|----|-----------|
112
+ |`key`|`a`|The key to access|
113
+ |`map`|`Map<a, b>`|The map to access|
114
+
115
+ Returns:
116
+
117
+ |type|description|
118
+ |----|-----------|
119
+ |`Option<b>`|`Some(value)` if the key exists in the map or `None` otherwise|
120
+
121
+ ### Map.**contains**
122
+
123
+ <details disabled>
124
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
125
+ No other changes yet.
126
+ </details>
127
+
128
+ ```grain
129
+ contains : (a, Map<a, b>) -> Bool
130
+ ```
131
+
132
+ Determines if the map contains the given key. In such a case, it will always contain a value for the given key.
133
+
134
+ Parameters:
135
+
136
+ |param|type|description|
137
+ |-----|----|-----------|
138
+ |`key`|`a`|The key to search for|
139
+ |`map`|`Map<a, b>`|The map to search|
140
+
141
+ Returns:
142
+
143
+ |type|description|
144
+ |----|-----------|
145
+ |`Bool`|`true` if the map contains the given key or `false` otherwise|
146
+
147
+ ### Map.**remove**
148
+
149
+ <details disabled>
150
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
151
+ No other changes yet.
152
+ </details>
153
+
154
+ ```grain
155
+ remove : (a, Map<a, b>) -> Void
156
+ ```
157
+
158
+ Removes the given key from the map, which also removes the value. If the key pair doesn't exist, nothing happens.
159
+
160
+ Parameters:
161
+
162
+ |param|type|description|
163
+ |-----|----|-----------|
164
+ |`key`|`a`|The key to remove|
165
+ |`map`|`Map<a, b>`|The map to update|
166
+
167
+ ### Map.**update**
168
+
169
+ <details disabled>
170
+ <summary tabindex="-1">Added in <code>0.3.0</code></summary>
171
+ No other changes yet.
172
+ </details>
173
+
174
+ ```grain
175
+ update : (a, (Option<b> -> Option<b>), Map<a, b>) -> Void
176
+ ```
177
+
178
+ Updates a value in the map by calling an updater function that receives the previously stored value as an `Option` and returns the new value to be stored as an `Option`. If the key didn't exist previously, the value will be `None`. If `None` is returned from the updater function, the key-value pair is removed.
179
+
180
+ Parameters:
181
+
182
+ |param|type|description|
183
+ |-----|----|-----------|
184
+ |`key`|`a`|The unique key in the map|
185
+ |`fn`|`Option<b> -> Option<b>`|The updater function|
186
+ |`map`|`Map<a, b>`|The map to modify|
187
+
188
+ ### Map.**size**
189
+
190
+ <details disabled>
191
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
192
+ No other changes yet.
193
+ </details>
194
+
195
+ ```grain
196
+ size : Map<a, b> -> Number
197
+ ```
198
+
199
+ Provides the count of key-value pairs stored within the map.
200
+
201
+ Parameters:
202
+
203
+ |param|type|description|
204
+ |-----|----|-----------|
205
+ |`map`|`Map<a, b>`|The map to inspect|
206
+
207
+ Returns:
208
+
209
+ |type|description|
210
+ |----|-----------|
211
+ |`Number`|The count of key-value pairs in the map|
212
+
213
+ ### Map.**isEmpty**
214
+
215
+ <details disabled>
216
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
217
+ No other changes yet.
218
+ </details>
219
+
220
+ ```grain
221
+ isEmpty : Map<a, b> -> Bool
222
+ ```
223
+
224
+ Determines if the map contains no key-value pairs.
225
+
226
+ Parameters:
227
+
228
+ |param|type|description|
229
+ |-----|----|-----------|
230
+ |`map`|`Map<a, b>`|The map to inspect|
231
+
232
+ Returns:
233
+
234
+ |type|description|
235
+ |----|-----------|
236
+ |`Bool`|`true` if the given map is empty or `false` otherwise|
237
+
238
+ ### Map.**clear**
239
+
240
+ <details disabled>
241
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
242
+ No other changes yet.
243
+ </details>
244
+
245
+ ```grain
246
+ clear : Map<a, b> -> Void
247
+ ```
248
+
249
+ Resets the map by removing all key-value pairs.
250
+
251
+ Parameters:
252
+
253
+ |param|type|description|
254
+ |-----|----|-----------|
255
+ |`map`|`Map<a, b>`|The map to reset|
256
+
257
+ ### Map.**forEach**
258
+
259
+ <details>
260
+ <summary>Added in <code>0.2.0</code></summary>
261
+ <table>
262
+ <thead>
263
+ <tr><th>version</th><th>changes</th></tr>
264
+ </thead>
265
+ <tbody>
266
+ <tr><td><code>next</code></td><td>Ensured the iterator function return type is always `Void`</td></tr>
267
+ </tbody>
268
+ </table>
269
+ </details>
270
+
271
+ ```grain
272
+ forEach : (((a, b) -> Void), Map<a, b>) -> Void
273
+ ```
274
+
275
+ Iterates the map, calling an iterator function with each key and value.
276
+
277
+ Parameters:
278
+
279
+ |param|type|description|
280
+ |-----|----|-----------|
281
+ |`fn`|`(a, b) -> Void`|The iterator function to call with each key and value|
282
+ |`map`|`Map<a, b>`|The map to iterate|
283
+
284
+ ### Map.**reduce**
285
+
286
+ <details disabled>
287
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
288
+ No other changes yet.
289
+ </details>
290
+
291
+ ```grain
292
+ reduce : (((a, b, c) -> a), a, Map<b, c>) -> a
293
+ ```
294
+
295
+ Combines all key-value pairs of a map using a reducer function.
296
+
297
+ Parameters:
298
+
299
+ |param|type|description|
300
+ |-----|----|-----------|
301
+ |`fn`|`(a, b, c) -> a`|The reducer function to call on each key and value, where the value returned will be the next accumulator value|
302
+ |`init`|`a`|The initial value to use for the accumulator on the first iteration|
303
+ |`map`|`Map<b, c>`|The map to iterate|
304
+
305
+ Returns:
306
+
307
+ |type|description|
308
+ |----|-----------|
309
+ |`a`|The final accumulator returned from `fn`|
310
+
311
+ ### Map.**keys**
312
+
313
+ <details disabled>
314
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
315
+ No other changes yet.
316
+ </details>
317
+
318
+ ```grain
319
+ keys : Map<a, b> -> List<a>
320
+ ```
321
+
322
+ Enumerates all keys in the given map.
323
+
324
+ Parameters:
325
+
326
+ |param|type|description|
327
+ |-----|----|-----------|
328
+ |`map`|`Map<a, b>`|The map to enumerate|
329
+
330
+ Returns:
331
+
332
+ |type|description|
333
+ |----|-----------|
334
+ |`List<a>`|A list containing all keys from the given map|
335
+
336
+ ### Map.**values**
337
+
338
+ <details disabled>
339
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
340
+ No other changes yet.
341
+ </details>
342
+
343
+ ```grain
344
+ values : Map<a, b> -> List<b>
345
+ ```
346
+
347
+ Enumerates all values in the given map.
348
+
349
+ Parameters:
350
+
351
+ |param|type|description|
352
+ |-----|----|-----------|
353
+ |`map`|`Map<a, b>`|The map to enumerate|
354
+
355
+ Returns:
356
+
357
+ |type|description|
358
+ |----|-----------|
359
+ |`List<b>`|A list containing all values from the given map|
360
+
361
+ ### Map.**toList**
362
+
363
+ <details disabled>
364
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
365
+ No other changes yet.
366
+ </details>
367
+
368
+ ```grain
369
+ toList : Map<a, b> -> List<(a, b)>
370
+ ```
371
+
372
+ Enumerates all key-value pairs in the given map.
373
+
374
+ Parameters:
375
+
376
+ |param|type|description|
377
+ |-----|----|-----------|
378
+ |`map`|`Map<a, b>`|The map to enumerate|
379
+
380
+ Returns:
381
+
382
+ |type|description|
383
+ |----|-----------|
384
+ |`List<(a, b)>`|A list containing all key-value pairs from the given map|
385
+
386
+ ### Map.**fromList**
387
+
388
+ <details disabled>
389
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
390
+ No other changes yet.
391
+ </details>
392
+
393
+ ```grain
394
+ fromList : List<(a, b)> -> Map<a, b>
395
+ ```
396
+
397
+ Creates a map from a list.
398
+
399
+ Parameters:
400
+
401
+ |param|type|description|
402
+ |-----|----|-----------|
403
+ |`list`|`List<(a, b)>`|The list to convert|
404
+
405
+ Returns:
406
+
407
+ |type|description|
408
+ |----|-----------|
409
+ |`Map<a, b>`|A map containing all key-value pairs from the list|
410
+
411
+ ### Map.**toArray**
412
+
413
+ <details disabled>
414
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
415
+ No other changes yet.
416
+ </details>
417
+
418
+ ```grain
419
+ toArray : Map<a, b> -> Array<(a, b)>
420
+ ```
421
+
422
+ Converts a map into an array of its key-value pairs.
423
+
424
+ Parameters:
425
+
426
+ |param|type|description|
427
+ |-----|----|-----------|
428
+ |`map`|`Map<a, b>`|The map to convert|
429
+
430
+ Returns:
431
+
432
+ |type|description|
433
+ |----|-----------|
434
+ |`Array<(a, b)>`|An array containing all key-value pairs from the given map|
435
+
436
+ ### Map.**fromArray**
437
+
438
+ <details disabled>
439
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
440
+ No other changes yet.
441
+ </details>
442
+
443
+ ```grain
444
+ fromArray : Array<(a, b)> -> Map<a, b>
445
+ ```
446
+
447
+ Creates a map from an array.
448
+
449
+ Parameters:
450
+
451
+ |param|type|description|
452
+ |-----|----|-----------|
453
+ |`array`|`Array<(a, b)>`|The array to convert|
454
+
455
+ Returns:
456
+
457
+ |type|description|
458
+ |----|-----------|
459
+ |`Map<a, b>`|A map containing all key-value pairs from the array|
460
+
461
+ ### Map.**filter**
462
+
463
+ <details disabled>
464
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
465
+ No other changes yet.
466
+ </details>
467
+
468
+ ```grain
469
+ filter : (((a, b) -> Bool), Map<a, b>) -> Void
470
+ ```
471
+
472
+ Removes key-value pairs from a map where a predicate function returns `false`.
473
+
474
+ Parameters:
475
+
476
+ |param|type|description|
477
+ |-----|----|-----------|
478
+ |`fn`|`(a, b) -> Bool`|The predicate function to indicate which key-value pairs to remove from the map, where returning `false` indicates the key-value pair should be removed|
479
+ |`map`|`Map<a, b>`|The map to iterate|
480
+
481
+ ### Map.**reject**
482
+
483
+ <details disabled>
484
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
485
+ No other changes yet.
486
+ </details>
487
+
488
+ ```grain
489
+ reject : (((a, b) -> Bool), Map<a, b>) -> Void
490
+ ```
491
+
492
+ Removes key-value pairs from a map where a predicate function returns `true`.
493
+
494
+ Parameters:
495
+
496
+ |param|type|description|
497
+ |-----|----|-----------|
498
+ |`fn`|`(a, b) -> Bool`|The predicate function to indicate which key-value pairs to remove from the map, where returning `true` indicates the key-value pair should be removed|
499
+ |`map`|`Map<a, b>`|The map to iterate|
500
+
501
+ ### Map.**getInternalStats**
502
+
503
+ <details disabled>
504
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
505
+ No other changes yet.
506
+ </details>
507
+
508
+ ```grain
509
+ getInternalStats : Map<a, b> -> (Number, Number)
510
+ ```
511
+
512
+ Provides data representing the internal state state of the map.
513
+
514
+ Parameters:
515
+
516
+ |param|type|description|
517
+ |-----|----|-----------|
518
+ |`map`|`Map<a, b>`|The map to inspect|
519
+
520
+ Returns:
521
+
522
+ |type|description|
523
+ |----|-----------|
524
+ |`(Number, Number)`|The internal state of the map|
525
+