@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.
- package/CHANGELOG.md +93 -0
- package/array.gr +18 -18
- package/array.md +18 -18
- package/bigint.gr +497 -0
- package/bigint.md +811 -0
- package/buffer.gr +59 -223
- package/buffer.md +24 -17
- package/bytes.gr +100 -202
- package/bytes.md +19 -0
- package/char.gr +63 -133
- package/exception.gr +28 -2
- package/exception.md +43 -0
- package/float32.gr +76 -95
- package/float32.md +69 -30
- package/float64.gr +81 -95
- package/float64.md +69 -30
- package/hash.gr +37 -37
- package/int32.gr +152 -198
- package/int32.md +104 -0
- package/int64.gr +151 -197
- package/int64.md +104 -0
- package/list.gr +467 -70
- package/list.md +1141 -0
- package/map.gr +192 -7
- package/map.md +525 -0
- package/number.gr +111 -54
- package/number.md +100 -3
- package/option.md +1 -1
- package/package.json +3 -3
- package/pervasives.gr +499 -59
- package/pervasives.md +1116 -0
- package/queue.gr +4 -0
- package/queue.md +10 -0
- package/random.gr +196 -0
- package/random.md +179 -0
- package/regex.gr +1833 -842
- package/regex.md +11 -11
- package/result.md +1 -1
- package/runtime/bigint.gr +2045 -0
- package/runtime/bigint.md +326 -0
- package/runtime/dataStructures.gr +99 -278
- package/runtime/dataStructures.md +391 -0
- package/runtime/debug.md +6 -0
- package/runtime/equal.gr +5 -23
- package/runtime/equal.md +6 -0
- package/runtime/exception.md +30 -0
- package/runtime/gc.gr +20 -3
- package/runtime/gc.md +36 -0
- package/runtime/malloc.gr +13 -11
- package/runtime/malloc.md +55 -0
- package/runtime/numberUtils.gr +91 -41
- package/runtime/numberUtils.md +54 -0
- package/runtime/numbers.gr +1049 -391
- package/runtime/numbers.md +300 -0
- package/runtime/string.gr +136 -230
- package/runtime/string.md +24 -0
- package/runtime/stringUtils.gr +58 -38
- package/runtime/stringUtils.md +6 -0
- package/runtime/unsafe/constants.gr +17 -0
- package/runtime/unsafe/constants.md +72 -0
- package/runtime/unsafe/conv.md +71 -0
- package/runtime/unsafe/errors.md +204 -0
- package/runtime/unsafe/memory.md +54 -0
- package/runtime/unsafe/printWasm.md +24 -0
- package/runtime/unsafe/tags.gr +9 -8
- package/runtime/unsafe/tags.md +120 -0
- package/runtime/unsafe/wasmf32.md +168 -0
- package/runtime/unsafe/wasmf64.md +168 -0
- package/runtime/unsafe/wasmi32.md +282 -0
- package/runtime/unsafe/wasmi64.md +300 -0
- package/runtime/utils/printing.gr +62 -0
- package/runtime/utils/printing.md +18 -0
- package/runtime/wasi.gr +1 -1
- package/runtime/wasi.md +839 -0
- package/set.gr +17 -8
- package/set.md +24 -21
- package/stack.gr +3 -3
- package/stack.md +4 -6
- package/string.gr +194 -329
- package/string.md +3 -3
- package/sys/file.gr +245 -429
- package/sys/process.gr +27 -45
- package/sys/random.gr +47 -16
- package/sys/random.md +38 -0
- 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
|
|
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
|
|
26
|
-
* @returns An empty set with the given initial storage
|
|
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 =
|
|
31
|
-
let buckets = Array.make(
|
|
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
|
-
*
|
|
212
|
+
* Provides the count of values within the set.
|
|
205
213
|
*
|
|
206
214
|
* @param set: The set to inspect
|
|
207
|
-
* @returns The
|
|
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
|
-
|
|
16
|
+
## Types
|
|
17
17
|
|
|
18
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|`
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
216
|
-
<summary
|
|
217
|
-
|
|
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 ->
|
|
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 ->
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|