@grain/stdlib 0.4.6 → 0.5.2

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 (85) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/array.gr +18 -18
  3. package/array.md +18 -18
  4. package/bigint.gr +497 -0
  5. package/bigint.md +811 -0
  6. package/buffer.gr +59 -223
  7. package/buffer.md +24 -17
  8. package/bytes.gr +100 -202
  9. package/bytes.md +19 -0
  10. package/char.gr +63 -133
  11. package/exception.gr +28 -2
  12. package/exception.md +43 -0
  13. package/float32.gr +76 -95
  14. package/float32.md +69 -30
  15. package/float64.gr +81 -95
  16. package/float64.md +69 -30
  17. package/hash.gr +37 -37
  18. package/int32.gr +152 -198
  19. package/int32.md +104 -0
  20. package/int64.gr +151 -197
  21. package/int64.md +104 -0
  22. package/list.gr +467 -70
  23. package/list.md +1141 -0
  24. package/map.gr +192 -7
  25. package/map.md +525 -0
  26. package/number.gr +111 -54
  27. package/number.md +100 -3
  28. package/option.md +1 -1
  29. package/package.json +3 -3
  30. package/pervasives.gr +499 -59
  31. package/pervasives.md +1116 -0
  32. package/queue.gr +4 -0
  33. package/queue.md +10 -0
  34. package/random.gr +196 -0
  35. package/random.md +179 -0
  36. package/regex.gr +1833 -842
  37. package/regex.md +11 -11
  38. package/result.md +1 -1
  39. package/runtime/bigint.gr +2045 -0
  40. package/runtime/bigint.md +326 -0
  41. package/runtime/dataStructures.gr +99 -278
  42. package/runtime/dataStructures.md +391 -0
  43. package/runtime/debug.md +6 -0
  44. package/runtime/equal.gr +5 -23
  45. package/runtime/equal.md +6 -0
  46. package/runtime/exception.md +30 -0
  47. package/runtime/gc.gr +20 -3
  48. package/runtime/gc.md +36 -0
  49. package/runtime/malloc.gr +13 -11
  50. package/runtime/malloc.md +55 -0
  51. package/runtime/numberUtils.gr +91 -41
  52. package/runtime/numberUtils.md +54 -0
  53. package/runtime/numbers.gr +1049 -391
  54. package/runtime/numbers.md +300 -0
  55. package/runtime/string.gr +136 -230
  56. package/runtime/string.md +24 -0
  57. package/runtime/stringUtils.gr +58 -38
  58. package/runtime/stringUtils.md +6 -0
  59. package/runtime/unsafe/constants.gr +17 -0
  60. package/runtime/unsafe/constants.md +72 -0
  61. package/runtime/unsafe/conv.md +71 -0
  62. package/runtime/unsafe/errors.md +204 -0
  63. package/runtime/unsafe/memory.md +54 -0
  64. package/runtime/unsafe/printWasm.md +24 -0
  65. package/runtime/unsafe/tags.gr +9 -8
  66. package/runtime/unsafe/tags.md +120 -0
  67. package/runtime/unsafe/wasmf32.md +168 -0
  68. package/runtime/unsafe/wasmf64.md +168 -0
  69. package/runtime/unsafe/wasmi32.md +282 -0
  70. package/runtime/unsafe/wasmi64.md +300 -0
  71. package/runtime/utils/printing.gr +62 -0
  72. package/runtime/utils/printing.md +18 -0
  73. package/runtime/wasi.gr +1 -1
  74. package/runtime/wasi.md +839 -0
  75. package/set.gr +17 -8
  76. package/set.md +24 -21
  77. package/stack.gr +3 -3
  78. package/stack.md +4 -6
  79. package/string.gr +194 -329
  80. package/string.md +3 -3
  81. package/sys/file.gr +245 -429
  82. package/sys/process.gr +27 -45
  83. package/sys/random.gr +47 -16
  84. package/sys/random.md +38 -0
  85. package/sys/time.gr +11 -27
package/set.gr CHANGED
@@ -13,22 +13,30 @@ record Bucket<t> {
13
13
  mut next: Option<Bucket<t>>,
14
14
  }
15
15
 
16
+ /**
17
+ * @section Types: Type declarations included in the Set module.
18
+ */
19
+
16
20
  record Set<k> {
17
21
  mut size: Number,
18
22
  mut buckets: Array<Option<Bucket<k>>>,
19
23
  }
20
24
 
25
+ /**
26
+ * @section Values: Functions for working with Sets.
27
+ */
28
+
21
29
  // TODO: This could take an `eq` function to custom comparisons
22
30
  /**
23
- * Creates a new empty set with an initial storage of the given length. As values are added or removed, the length may grow or shrink. Generally, you won't need to care about the length of your set and can use `Set.make()` instead.
31
+ * Creates a new empty set 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 set and can use `Set.make()` instead.
24
32
  *
25
- * @param storageLength: The initial storage length of the set
26
- * @returns An empty set with the given initial storage length
33
+ * @param size: The initial storage size of the set
34
+ * @returns An empty set with the given initial storage size
27
35
  *
28
36
  * @since 0.3.0
29
37
  */
30
- export let makeSized = storageLength => {
31
- let buckets = Array.make(storageLength, None)
38
+ export let makeSized = size => {
39
+ let buckets = Array.make(size, None)
32
40
  { size: 0, buckets }
33
41
  }
34
42
  /**
@@ -201,10 +209,10 @@ export let remove = (key, set) => {
201
209
  }
202
210
 
203
211
  /**
204
- * Returns the number of values within the set.
212
+ * Provides the count of values within the set.
205
213
  *
206
214
  * @param set: The set to inspect
207
- * @returns The number of elements in the set
215
+ * @returns The count of elements in the set
208
216
  *
209
217
  * @since 0.3.0
210
218
  */
@@ -243,7 +251,7 @@ let rec forEachBucket = (fn, node) => {
243
251
  match (node) {
244
252
  None => void,
245
253
  Some({ key, next }) => {
246
- fn(key)
254
+ fn(key): Void
247
255
  forEachBucket(fn, next)
248
256
  },
249
257
  }
@@ -256,6 +264,7 @@ let rec forEachBucket = (fn, node) => {
256
264
  * @param set: The set to iterate
257
265
  *
258
266
  * @since 0.3.0
267
+ * @history v0.5.0: Ensured the iterator function return type is always `Void`
259
268
  */
260
269
  export let forEach = (fn, set) => {
261
270
  let buckets = set.buckets
package/set.md CHANGED
@@ -13,24 +13,20 @@ No other changes yet.
13
13
  import Set from "set"
14
14
  ```
15
15
 
16
- ### Set.**Bucket**
16
+ ## Types
17
17
 
18
- ```grain
19
- record Bucket<t> {
20
- key: t,
21
- next: Option<Bucket<t>>,
22
- }
23
- ```
18
+ Type declarations included in the Set module.
24
19
 
25
20
  ### Set.**Set**
26
21
 
27
22
  ```grain
28
- record Set<k> {
29
- size: Number,
30
- buckets: Array<Option<Bucket<k>>>,
31
- }
23
+ type Set<k>
32
24
  ```
33
25
 
26
+ ## Values
27
+
28
+ Functions for working with Sets.
29
+
34
30
  ### Set.**makeSized**
35
31
 
36
32
  <details disabled>
@@ -42,19 +38,19 @@ No other changes yet.
42
38
  makeSized : Number -> Set<a>
43
39
  ```
44
40
 
45
- Creates a new empty set with an initial storage of the given length. As values are added or removed, the length may grow or shrink. Generally, you won't need to care about the length of your set and can use `Set.make()` instead.
41
+ Creates a new empty set 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 set and can use `Set.make()` instead.
46
42
 
47
43
  Parameters:
48
44
 
49
45
  |param|type|description|
50
46
  |-----|----|-----------|
51
- |`storageLength`|`Number`|The initial storage length of the set|
47
+ |`size`|`Number`|The initial storage size of the set|
52
48
 
53
49
  Returns:
54
50
 
55
51
  |type|description|
56
52
  |----|-----------|
57
- |`Set<a>`|An empty set with the given initial storage length|
53
+ |`Set<a>`|An empty set with the given initial storage size|
58
54
 
59
55
  ### Set.**make**
60
56
 
@@ -152,7 +148,7 @@ No other changes yet.
152
148
  size : Set<a> -> Number
153
149
  ```
154
150
 
155
- Returns the number of values within the set.
151
+ Provides the count of values within the set.
156
152
 
157
153
  Parameters:
158
154
 
@@ -164,7 +160,7 @@ Returns:
164
160
 
165
161
  |type|description|
166
162
  |----|-----------|
167
- |`Number`|The number of elements in the set|
163
+ |`Number`|The count of elements in the set|
168
164
 
169
165
  ### Set.**isEmpty**
170
166
 
@@ -212,13 +208,20 @@ Parameters:
212
208
 
213
209
  ### Set.**forEach**
214
210
 
215
- <details disabled>
216
- <summary tabindex="-1">Added in <code>0.3.0</code></summary>
217
- No other changes yet.
211
+ <details>
212
+ <summary>Added in <code>0.3.0</code></summary>
213
+ <table>
214
+ <thead>
215
+ <tr><th>version</th><th>changes</th></tr>
216
+ </thead>
217
+ <tbody>
218
+ <tr><td><code>0.5.0</code></td><td>Ensured the iterator function return type is always `Void`</td></tr>
219
+ </tbody>
220
+ </table>
218
221
  </details>
219
222
 
220
223
  ```grain
221
- forEach : ((a -> b), Set<a>) -> Void
224
+ forEach : ((a -> Void), Set<a>) -> Void
222
225
  ```
223
226
 
224
227
  Iterates the set, calling an iterator function on each element.
@@ -227,7 +230,7 @@ Parameters:
227
230
 
228
231
  |param|type|description|
229
232
  |-----|----|-----------|
230
- |`fn`|`a -> b`|The iterator function to call with each element|
233
+ |`fn`|`a -> Void`|The iterator function to call with each element|
231
234
  |`set`|`Set<a>`|The set to iterate|
232
235
 
233
236
  ### Set.**reduce**
package/stack.gr CHANGED
@@ -33,7 +33,7 @@ export let make = () => {
33
33
  * Checks if the given stack contains no items.
34
34
  *
35
35
  * @param stack: The stack to check
36
- * @returns `true` if the stack has no items, and `false` otherwise
36
+ * @returns `true` if the stack has no items or `false` otherwise
37
37
  */
38
38
  export let isEmpty = stack => {
39
39
  match (stack) {
@@ -43,10 +43,10 @@ export let isEmpty = stack => {
43
43
  }
44
44
 
45
45
  /**
46
- * Returns `Some(item)` where `item` is the value at the top of the stack, and `None` otherwise.
46
+ * Provides the value at the top of the stack, if it exists.
47
47
  *
48
48
  * @param stack: The stack to inspect
49
- * @returns The value at the top of the stack, if it exists
49
+ * @returns `Some(value)` containing the value at the top of the stack or `None` otherwise.
50
50
  */
51
51
  export let peek = stack => {
52
52
  match (stack) {
package/stack.md CHANGED
@@ -15,9 +15,7 @@ Type declarations included in the Stack module.
15
15
  ### Stack.**Stack**
16
16
 
17
17
  ```grain
18
- record Stack<a> {
19
- data: List<a>,
20
- }
18
+ type Stack<a>
21
19
  ```
22
20
 
23
21
  Stacks are immutable data structures that store their data in a List.
@@ -58,7 +56,7 @@ Returns:
58
56
 
59
57
  |type|description|
60
58
  |----|-----------|
61
- |`Bool`|`true` if the stack has no items, and `false` otherwise|
59
+ |`Bool`|`true` if the stack has no items or `false` otherwise|
62
60
 
63
61
  ### Stack.**peek**
64
62
 
@@ -66,7 +64,7 @@ Returns:
66
64
  peek : Stack<a> -> Option<a>
67
65
  ```
68
66
 
69
- Returns `Some(item)` where `item` is the value at the top of the stack, and `None` otherwise.
67
+ Provides the value at the top of the stack, if it exists.
70
68
 
71
69
  Parameters:
72
70
 
@@ -78,7 +76,7 @@ Returns:
78
76
 
79
77
  |type|description|
80
78
  |----|-----------|
81
- |`Option<a>`|The value at the top of the stack, if it exists|
79
+ |`Option<a>`|`Some(value)` containing the value at the top of the stack or `None` otherwise.|
82
80
 
83
81
  ### Stack.**push**
84
82