@grain/stdlib 0.5.12 → 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 +200 -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/stack.md CHANGED
@@ -2,9 +2,11 @@
2
2
  title: Stack
3
3
  ---
4
4
 
5
- > **Deprecated:** This module will be renamed to ImmutableStack in the v0.6.0 release of Grain.
5
+ A stack is a LIFO (last-in-first-out) data structure where new
6
+ values are added, retrieved, and removed from the end.
6
7
 
7
- An immutable stack implementation. A stack is a LIFO (last-in-first-out) data structure where new values are added, retrieved, and removed from the end.
8
+ The default implementation is mutable, but an immutable stack
9
+ implementation is available in the `Immutable` submodule.
8
10
 
9
11
  <details disabled>
10
12
  <summary tabindex="-1">Added in <code>0.3.0</code></summary>
@@ -12,7 +14,7 @@ No other changes yet.
12
14
  </details>
13
15
 
14
16
  ```grain
15
- import Stack from "stack"
17
+ from "stack" include Stack
16
18
  ```
17
19
 
18
20
  ## Types
@@ -25,55 +27,260 @@ Type declarations included in the Stack module.
25
27
  type Stack<a>
26
28
  ```
27
29
 
28
- Stacks are immutable data structures that store their data in a List.
30
+ A mutable LIFO (last-in-first-out) data structure.
29
31
 
30
32
  ## Values
31
33
 
32
34
  Functions and constants included in the Stack module.
33
35
 
34
- ### Stack.**empty**
36
+ ### Stack.**make**
35
37
 
36
38
  <details disabled>
37
- <summary tabindex="-1">Added in <code>0.5.4</code></summary>
39
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
38
40
  No other changes yet.
39
41
  </details>
40
42
 
41
43
  ```grain
42
- empty : Stack<a>
44
+ make : (?size: Number) => Stack<a>
43
45
  ```
44
46
 
45
- An empty stack.
47
+ Creates a new stack with an initial storage of the given size. As values are
48
+ added or removed, the internal storage may grow or shrink. Generally, you
49
+ won’t need to care about the storage size of your map and can use the
50
+ default size.
46
51
 
47
- ### Stack.**make**
52
+ Parameters:
53
+
54
+ |param|type|description|
55
+ |-----|----|-----------|
56
+ |`?size`|`Number`|The initial storage size of the stack|
48
57
 
49
- > **Deprecated:** This will be removed in the v0.6.0 release of Grain.
58
+ Returns:
59
+
60
+ |type|description|
61
+ |----|-----------|
62
+ |`Stack<a>`|An empty stack|
63
+
64
+ ### Stack.**isEmpty**
50
65
 
51
66
  <details disabled>
52
- <summary tabindex="-1">Added in <code>0.3.0</code></summary>
67
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
53
68
  No other changes yet.
54
69
  </details>
55
70
 
56
71
  ```grain
57
- make : () -> Stack<a>
72
+ isEmpty : (stack: Stack<a>) => Bool
58
73
  ```
59
74
 
60
- Creates a new stack.
75
+ Checks if the given stack contains no items.
76
+
77
+ Parameters:
78
+
79
+ |param|type|description|
80
+ |-----|----|-----------|
81
+ |`stack`|`Stack<a>`|The stack to check|
61
82
 
62
83
  Returns:
63
84
 
64
85
  |type|description|
65
86
  |----|-----------|
66
- |`Stack<a>`|An empty stack|
87
+ |`Bool`|`true` if the stack has no items or `false` otherwise|
67
88
 
68
- ### Stack.**isEmpty**
89
+ ### Stack.**size**
69
90
 
70
91
  <details disabled>
71
- <summary tabindex="-1">Added in <code>0.3.0</code></summary>
92
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
93
+ No other changes yet.
94
+ </details>
95
+
96
+ ```grain
97
+ size : (stack: Stack<a>) => Number
98
+ ```
99
+
100
+ Computes the size of the input stack.
101
+
102
+ Parameters:
103
+
104
+ |param|type|description|
105
+ |-----|----|-----------|
106
+ |`stack`|`Stack<a>`|The stack to inspect|
107
+
108
+ Returns:
109
+
110
+ |type|description|
111
+ |----|-----------|
112
+ |`Number`|The count of the items in the stack|
113
+
114
+ ### Stack.**peek**
115
+
116
+ <details disabled>
117
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
118
+ No other changes yet.
119
+ </details>
120
+
121
+ ```grain
122
+ peek : (stack: Stack<a>) => Option<a>
123
+ ```
124
+
125
+ Provides the value at the top of the stack, if it exists.
126
+
127
+ Parameters:
128
+
129
+ |param|type|description|
130
+ |-----|----|-----------|
131
+ |`stack`|`Stack<a>`|The stack to inspect|
132
+
133
+ Returns:
134
+
135
+ |type|description|
136
+ |----|-----------|
137
+ |`Option<a>`|`Some(value)` containing the value at the top of the stack or `None` otherwise.|
138
+
139
+ ### Stack.**push**
140
+
141
+ <details disabled>
142
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
72
143
  No other changes yet.
73
144
  </details>
74
145
 
75
146
  ```grain
76
- isEmpty : Stack<a> -> Bool
147
+ push : (value: a, stack: Stack<a>) => Void
148
+ ```
149
+
150
+ Adds a new item to the top of the stack.
151
+
152
+ Parameters:
153
+
154
+ |param|type|description|
155
+ |-----|----|-----------|
156
+ |`value`|`a`|The item to be added|
157
+ |`stack`|`Stack<a>`|The stack being updated|
158
+
159
+ ### Stack.**pop**
160
+
161
+ <details disabled>
162
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
163
+ No other changes yet.
164
+ </details>
165
+
166
+ ```grain
167
+ pop : (stack: Stack<a>) => Option<a>
168
+ ```
169
+
170
+ Removes the item at the top of the stack.
171
+
172
+ Parameters:
173
+
174
+ |param|type|description|
175
+ |-----|----|-----------|
176
+ |`stack`|`Stack<a>`|The stack being updated|
177
+
178
+ Returns:
179
+
180
+ |type|description|
181
+ |----|-----------|
182
+ |`Option<a>`|The element removed from the stack|
183
+
184
+ ### Stack.**clear**
185
+
186
+ <details disabled>
187
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
188
+ No other changes yet.
189
+ </details>
190
+
191
+ ```grain
192
+ clear : (stack: Stack<a>) => Void
193
+ ```
194
+
195
+ Clears the stack by removing all of its elements
196
+
197
+ Parameters:
198
+
199
+ |param|type|description|
200
+ |-----|----|-----------|
201
+ |`stack`|`Stack<a>`|The stack to clear|
202
+
203
+ ### Stack.**copy**
204
+
205
+ <details disabled>
206
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
207
+ No other changes yet.
208
+ </details>
209
+
210
+ ```grain
211
+ copy : (stack: Stack<a>) => Stack<a>
212
+ ```
213
+
214
+ Produces a shallow copy of the input stack.
215
+
216
+ Parameters:
217
+
218
+ |param|type|description|
219
+ |-----|----|-----------|
220
+ |`stack`|`Stack<a>`|The stack to copy|
221
+
222
+ Returns:
223
+
224
+ |type|description|
225
+ |----|-----------|
226
+ |`Stack<a>`|A new stack containing the elements from the input|
227
+
228
+ ## Stack.Immutable
229
+
230
+ An immutable stack implementation.
231
+
232
+ ### Types
233
+
234
+ Type declarations included in the Stack.Immutable module.
235
+
236
+ #### Stack.Immutable.**ImmutableStack**
237
+
238
+ ```grain
239
+ type ImmutableStack<a>
240
+ ```
241
+
242
+ ImmutableStacks are immutable data structures that store their data in a List.
243
+
244
+ ### Values
245
+
246
+ Functions and constants included in the Stack.Immutable module.
247
+
248
+ #### Stack.Immutable.**empty**
249
+
250
+ <details>
251
+ <summary>Added in <code>0.6.0</code></summary>
252
+ <table>
253
+ <thead>
254
+ <tr><th>version</th><th>changes</th></tr>
255
+ </thead>
256
+ <tbody>
257
+ <tr><td><code>0.5.4</code></td><td>Originally a module root API</td></tr>
258
+ </tbody>
259
+ </table>
260
+ </details>
261
+
262
+ ```grain
263
+ empty : ImmutableStack<a>
264
+ ```
265
+
266
+ An empty stack.
267
+
268
+ #### Stack.Immutable.**isEmpty**
269
+
270
+ <details>
271
+ <summary>Added in <code>0.6.0</code></summary>
272
+ <table>
273
+ <thead>
274
+ <tr><th>version</th><th>changes</th></tr>
275
+ </thead>
276
+ <tbody>
277
+ <tr><td><code>0.3.0</code></td><td>Originally a module root API</td></tr>
278
+ </tbody>
279
+ </table>
280
+ </details>
281
+
282
+ ```grain
283
+ isEmpty : (stack: ImmutableStack<a>) => Bool
77
284
  ```
78
285
 
79
286
  Checks if the given stack contains no items.
@@ -82,7 +289,7 @@ Parameters:
82
289
 
83
290
  |param|type|description|
84
291
  |-----|----|-----------|
85
- |`stack`|`Stack<a>`|The stack to check|
292
+ |`stack`|`ImmutableStack<a>`|The stack to check|
86
293
 
87
294
  Returns:
88
295
 
@@ -90,22 +297,23 @@ Returns:
90
297
  |----|-----------|
91
298
  |`Bool`|`true` if the stack has no items or `false` otherwise|
92
299
 
93
- ### Stack.**peek**
300
+ #### Stack.Immutable.**peek**
94
301
 
95
302
  <details>
96
- <summary>Added in <code>0.3.0</code></summary>
303
+ <summary>Added in <code>0.6.0</code></summary>
97
304
  <table>
98
305
  <thead>
99
306
  <tr><th>version</th><th>changes</th></tr>
100
307
  </thead>
101
308
  <tbody>
309
+ <tr><td><code>0.3.0</code></td><td>Originally a module root API</td></tr>
102
310
  <tr><td><code>0.3.1</code></td><td>Rename from `head` to `peek`</td></tr>
103
311
  </tbody>
104
312
  </table>
105
313
  </details>
106
314
 
107
315
  ```grain
108
- peek : Stack<a> -> Option<a>
316
+ peek : (stack: ImmutableStack<a>) => Option<a>
109
317
  ```
110
318
 
111
319
  Provides the value at the top of the stack, if it exists.
@@ -114,7 +322,7 @@ Parameters:
114
322
 
115
323
  |param|type|description|
116
324
  |-----|----|-----------|
117
- |`stack`|`Stack<a>`|The stack to inspect|
325
+ |`stack`|`ImmutableStack<a>`|The stack to inspect|
118
326
 
119
327
  Returns:
120
328
 
@@ -122,15 +330,22 @@ Returns:
122
330
  |----|-----------|
123
331
  |`Option<a>`|`Some(value)` containing the value at the top of the stack or `None` otherwise.|
124
332
 
125
- ### Stack.**push**
333
+ #### Stack.Immutable.**push**
126
334
 
127
- <details disabled>
128
- <summary tabindex="-1">Added in <code>0.3.0</code></summary>
129
- No other changes yet.
335
+ <details>
336
+ <summary>Added in <code>0.6.0</code></summary>
337
+ <table>
338
+ <thead>
339
+ <tr><th>version</th><th>changes</th></tr>
340
+ </thead>
341
+ <tbody>
342
+ <tr><td><code>0.3.0</code></td><td>Originally a module root API</td></tr>
343
+ </tbody>
344
+ </table>
130
345
  </details>
131
346
 
132
347
  ```grain
133
- push : (a, Stack<a>) -> Stack<a>
348
+ push : (value: a, stack: ImmutableStack<a>) => ImmutableStack<a>
134
349
  ```
135
350
 
136
351
  Adds a new item to the top of the stack.
@@ -140,23 +355,30 @@ Parameters:
140
355
  |param|type|description|
141
356
  |-----|----|-----------|
142
357
  |`value`|`a`|The item to be added|
143
- |`stack`|`Stack<a>`|The stack being updated|
358
+ |`stack`|`ImmutableStack<a>`|The stack being updated|
144
359
 
145
360
  Returns:
146
361
 
147
362
  |type|description|
148
363
  |----|-----------|
149
- |`Stack<a>`|A new stack with the item added to the end|
364
+ |`ImmutableStack<a>`|A new stack with the item added to the end|
150
365
 
151
- ### Stack.**pop**
366
+ #### Stack.Immutable.**pop**
152
367
 
153
- <details disabled>
154
- <summary tabindex="-1">Added in <code>0.3.0</code></summary>
155
- No other changes yet.
368
+ <details>
369
+ <summary>Added in <code>0.6.0</code></summary>
370
+ <table>
371
+ <thead>
372
+ <tr><th>version</th><th>changes</th></tr>
373
+ </thead>
374
+ <tbody>
375
+ <tr><td><code>0.3.0</code></td><td>Originally a module root API</td></tr>
376
+ </tbody>
377
+ </table>
156
378
  </details>
157
379
 
158
380
  ```grain
159
- pop : Stack<a> -> Stack<a>
381
+ pop : (stack: ImmutableStack<a>) => ImmutableStack<a>
160
382
  ```
161
383
 
162
384
  Removes the item at the top of the stack.
@@ -165,23 +387,30 @@ Parameters:
165
387
 
166
388
  |param|type|description|
167
389
  |-----|----|-----------|
168
- |`stack`|`Stack<a>`|The stack being updated|
390
+ |`stack`|`ImmutableStack<a>`|The stack being updated|
169
391
 
170
392
  Returns:
171
393
 
172
394
  |type|description|
173
395
  |----|-----------|
174
- |`Stack<a>`|A new stack with the last item removed|
396
+ |`ImmutableStack<a>`|A new stack with the last item removed|
175
397
 
176
- ### Stack.**size**
398
+ #### Stack.Immutable.**size**
177
399
 
178
- <details disabled>
179
- <summary tabindex="-1">Added in <code>0.3.2</code></summary>
180
- No other changes yet.
400
+ <details>
401
+ <summary>Added in <code>0.6.0</code></summary>
402
+ <table>
403
+ <thead>
404
+ <tr><th>version</th><th>changes</th></tr>
405
+ </thead>
406
+ <tbody>
407
+ <tr><td><code>0.3.2</code></td><td>Originally a module root API</td></tr>
408
+ </tbody>
409
+ </table>
181
410
  </details>
182
411
 
183
412
  ```grain
184
- size : Stack<a> -> Number
413
+ size : (stack: ImmutableStack<a>) => Number
185
414
  ```
186
415
 
187
416
  Computes the size of the input stack.
@@ -190,7 +419,7 @@ Parameters:
190
419
 
191
420
  |param|type|description|
192
421
  |-----|----|-----------|
193
- |`stack`|`Stack<a>`|The stack to inspect|
422
+ |`stack`|`ImmutableStack<a>`|The stack to inspect|
194
423
 
195
424
  Returns:
196
425