@grain/stdlib 0.6.5 → 0.7.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.
- package/CHANGELOG.md +64 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/array.gr +55 -7
- package/array.md +123 -77
- package/bigint.md +30 -30
- package/buffer.gr +20 -53
- package/buffer.md +47 -47
- package/bytes.gr +111 -35
- package/bytes.md +111 -32
- package/char.gr +201 -99
- package/char.md +361 -34
- package/exception.gr +11 -11
- package/exception.md +26 -1
- package/float32.gr +327 -3
- package/float32.md +606 -19
- package/float64.gr +320 -3
- package/float64.md +606 -19
- package/fs.gr +1082 -0
- package/fs.md +630 -0
- package/hash.gr +142 -88
- package/hash.md +102 -14
- package/int16.md +23 -23
- package/int32.gr +25 -4
- package/int32.md +65 -30
- package/int64.gr +26 -1
- package/int64.md +65 -30
- package/int8.md +23 -23
- package/json.gr +366 -51
- package/json.md +418 -2
- package/list.gr +387 -49
- package/list.md +492 -69
- package/map.gr +20 -12
- package/map.md +44 -38
- package/marshal.gr +41 -40
- package/marshal.md +2 -2
- package/number.gr +159 -30
- package/number.md +215 -38
- package/option.md +21 -21
- package/package.json +5 -3
- package/path.gr +48 -0
- package/path.md +103 -12
- package/pervasives.gr +2 -2
- package/pervasives.md +37 -37
- package/priorityqueue.gr +7 -7
- package/priorityqueue.md +19 -19
- package/queue.gr +183 -29
- package/queue.md +296 -40
- package/random.md +6 -6
- package/range.gr +4 -4
- package/range.md +6 -6
- package/rational.md +16 -16
- package/regex.gr +52 -51
- package/regex.md +11 -11
- package/result.md +16 -16
- package/runtime/atof/common.md +39 -39
- package/runtime/atof/decimal.gr +6 -6
- package/runtime/atof/decimal.md +8 -8
- package/runtime/atof/lemire.gr +5 -5
- package/runtime/atof/lemire.md +1 -1
- package/runtime/atof/parse.gr +16 -16
- package/runtime/atof/parse.md +2 -2
- package/runtime/atof/slow.md +1 -1
- package/runtime/atof/table.md +2 -2
- package/runtime/atoi/parse.gr +3 -3
- package/runtime/atoi/parse.md +1 -1
- package/runtime/bigint.gr +15 -47
- package/runtime/bigint.md +54 -60
- package/runtime/compare.gr +2 -2
- package/runtime/compare.md +1 -1
- package/runtime/dataStructures.md +33 -33
- package/runtime/debugPrint.gr +4 -1
- package/runtime/debugPrint.md +9 -9
- package/runtime/equal.gr +99 -77
- package/runtime/equal.md +1 -1
- package/runtime/exception.gr +62 -82
- package/runtime/exception.md +62 -11
- package/runtime/gc.gr +39 -45
- package/runtime/gc.md +4 -4
- package/runtime/malloc.gr +7 -7
- package/runtime/malloc.md +4 -4
- package/runtime/math/kernel/cos.gr +70 -0
- package/runtime/math/kernel/cos.md +14 -0
- package/runtime/math/kernel/sin.gr +65 -0
- package/runtime/math/kernel/sin.md +14 -0
- package/runtime/math/kernel/tan.gr +136 -0
- package/runtime/math/kernel/tan.md +14 -0
- package/runtime/math/rempio2.gr +244 -0
- package/runtime/math/rempio2.md +14 -0
- package/runtime/math/trig.gr +130 -0
- package/runtime/math/trig.md +28 -0
- package/runtime/math/umuldi.gr +26 -0
- package/runtime/math/umuldi.md +14 -0
- package/runtime/numberUtils.gr +29 -29
- package/runtime/numberUtils.md +12 -12
- package/runtime/numbers.gr +373 -381
- package/runtime/numbers.md +79 -73
- package/runtime/string.gr +37 -105
- package/runtime/string.md +3 -9
- package/runtime/unsafe/constants.md +24 -24
- package/runtime/unsafe/conv.md +13 -13
- package/runtime/unsafe/memory.gr +24 -20
- package/runtime/unsafe/memory.md +27 -7
- package/runtime/unsafe/offsets.gr +36 -0
- package/runtime/unsafe/offsets.md +88 -0
- package/runtime/unsafe/panic.gr +28 -0
- package/runtime/unsafe/panic.md +14 -0
- package/runtime/unsafe/tags.md +32 -32
- package/runtime/unsafe/wasmf32.md +28 -28
- package/runtime/unsafe/wasmf64.md +28 -28
- package/runtime/unsafe/wasmi32.md +47 -47
- package/runtime/unsafe/wasmi64.md +50 -50
- package/runtime/utf8.gr +189 -0
- package/runtime/utf8.md +117 -0
- package/runtime/wasi.gr +4 -2
- package/runtime/wasi.md +138 -138
- package/set.gr +18 -11
- package/set.md +42 -36
- package/stack.gr +171 -2
- package/stack.md +297 -15
- package/string.gr +352 -557
- package/string.md +77 -34
- package/uint16.gr +81 -0
- package/uint16.md +183 -22
- package/uint32.gr +25 -4
- package/uint32.md +63 -28
- package/uint64.gr +25 -5
- package/uint64.md +63 -28
- package/uint8.gr +81 -0
- package/uint8.md +183 -22
- package/uri.gr +57 -53
- package/uri.md +11 -12
- package/wasi/file.gr +67 -59
- package/wasi/file.md +39 -39
- package/wasi/process.md +5 -5
- package/wasi/random.md +3 -3
- package/wasi/time.md +4 -4
- package/runtime/utils/printing.gr +0 -60
- package/runtime/utils/printing.md +0 -26
package/stack.md
CHANGED
|
@@ -41,12 +41,12 @@ No other changes yet.
|
|
|
41
41
|
</details>
|
|
42
42
|
|
|
43
43
|
```grain
|
|
44
|
-
make
|
|
44
|
+
make: (?size: Number) => Stack<a>
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
Creates a new stack with an initial storage of the given size. As values are
|
|
48
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
|
|
49
|
+
won’t need to care about the storage size of your stack and can use the
|
|
50
50
|
default size.
|
|
51
51
|
|
|
52
52
|
Parameters:
|
|
@@ -69,7 +69,7 @@ No other changes yet.
|
|
|
69
69
|
</details>
|
|
70
70
|
|
|
71
71
|
```grain
|
|
72
|
-
isEmpty
|
|
72
|
+
isEmpty: (stack: Stack<a>) => Bool
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
Checks if the given stack contains no items.
|
|
@@ -94,7 +94,7 @@ No other changes yet.
|
|
|
94
94
|
</details>
|
|
95
95
|
|
|
96
96
|
```grain
|
|
97
|
-
size
|
|
97
|
+
size: (stack: Stack<a>) => Number
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
Computes the size of the input stack.
|
|
@@ -119,7 +119,7 @@ No other changes yet.
|
|
|
119
119
|
</details>
|
|
120
120
|
|
|
121
121
|
```grain
|
|
122
|
-
peek
|
|
122
|
+
peek: (stack: Stack<a>) => Option<a>
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
Provides the value at the top of the stack, if it exists.
|
|
@@ -144,7 +144,7 @@ No other changes yet.
|
|
|
144
144
|
</details>
|
|
145
145
|
|
|
146
146
|
```grain
|
|
147
|
-
push
|
|
147
|
+
push: (value: a, stack: Stack<a>) => Void
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
Adds a new item to the top of the stack.
|
|
@@ -164,7 +164,7 @@ No other changes yet.
|
|
|
164
164
|
</details>
|
|
165
165
|
|
|
166
166
|
```grain
|
|
167
|
-
pop
|
|
167
|
+
pop: (stack: Stack<a>) => Option<a>
|
|
168
168
|
```
|
|
169
169
|
|
|
170
170
|
Removes the item at the top of the stack.
|
|
@@ -189,7 +189,7 @@ No other changes yet.
|
|
|
189
189
|
</details>
|
|
190
190
|
|
|
191
191
|
```grain
|
|
192
|
-
clear
|
|
192
|
+
clear: (stack: Stack<a>) => Void
|
|
193
193
|
```
|
|
194
194
|
|
|
195
195
|
Clears the stack by removing all of its elements
|
|
@@ -208,7 +208,7 @@ No other changes yet.
|
|
|
208
208
|
</details>
|
|
209
209
|
|
|
210
210
|
```grain
|
|
211
|
-
copy
|
|
211
|
+
copy: (stack: Stack<a>) => Stack<a>
|
|
212
212
|
```
|
|
213
213
|
|
|
214
214
|
Produces a shallow copy of the input stack.
|
|
@@ -225,6 +225,144 @@ Returns:
|
|
|
225
225
|
|----|-----------|
|
|
226
226
|
|`Stack<a>`|A new stack containing the elements from the input|
|
|
227
227
|
|
|
228
|
+
### Stack.**toList**
|
|
229
|
+
|
|
230
|
+
<details disabled>
|
|
231
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
232
|
+
No other changes yet.
|
|
233
|
+
</details>
|
|
234
|
+
|
|
235
|
+
```grain
|
|
236
|
+
toList: (stack: Stack<a>) => List<a>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Creates a list containing the elements of a stack.
|
|
240
|
+
|
|
241
|
+
Parameters:
|
|
242
|
+
|
|
243
|
+
|param|type|description|
|
|
244
|
+
|-----|----|-----------|
|
|
245
|
+
|`stack`|`Stack<a>`|The stack to convert|
|
|
246
|
+
|
|
247
|
+
Returns:
|
|
248
|
+
|
|
249
|
+
|type|description|
|
|
250
|
+
|----|-----------|
|
|
251
|
+
|`List<a>`|A list containing all stack values|
|
|
252
|
+
|
|
253
|
+
Examples:
|
|
254
|
+
|
|
255
|
+
```grain
|
|
256
|
+
let stack = Stack.make()
|
|
257
|
+
Stack.push(1, stack)
|
|
258
|
+
Stack.push(2, stack)
|
|
259
|
+
assert Stack.toList(stack) == [2, 1]
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Stack.**fromList**
|
|
263
|
+
|
|
264
|
+
<details disabled>
|
|
265
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
266
|
+
No other changes yet.
|
|
267
|
+
</details>
|
|
268
|
+
|
|
269
|
+
```grain
|
|
270
|
+
fromList: (list: List<a>) => Stack<a>
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Creates a stack from a list.
|
|
274
|
+
|
|
275
|
+
Parameters:
|
|
276
|
+
|
|
277
|
+
|param|type|description|
|
|
278
|
+
|-----|----|-----------|
|
|
279
|
+
|`list`|`List<a>`|The list to convert|
|
|
280
|
+
|
|
281
|
+
Returns:
|
|
282
|
+
|
|
283
|
+
|type|description|
|
|
284
|
+
|----|-----------|
|
|
285
|
+
|`Stack<a>`|A stack containing all list values|
|
|
286
|
+
|
|
287
|
+
Examples:
|
|
288
|
+
|
|
289
|
+
```grain
|
|
290
|
+
let stack = Stack.fromList([3, 2, 1])
|
|
291
|
+
assert Stack.pop(stack) == Some(3)
|
|
292
|
+
assert Stack.pop(stack) == Some(2)
|
|
293
|
+
assert Stack.pop(stack) == Some(1)
|
|
294
|
+
assert Stack.pop(stack) == None
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Stack.**toArray**
|
|
298
|
+
|
|
299
|
+
<details disabled>
|
|
300
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
301
|
+
No other changes yet.
|
|
302
|
+
</details>
|
|
303
|
+
|
|
304
|
+
```grain
|
|
305
|
+
toArray: (stack: Stack<a>) => Array<a>
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Creates an array containing the elements of a stack.
|
|
309
|
+
|
|
310
|
+
Parameters:
|
|
311
|
+
|
|
312
|
+
|param|type|description|
|
|
313
|
+
|-----|----|-----------|
|
|
314
|
+
|`stack`|`Stack<a>`|The stack to convert|
|
|
315
|
+
|
|
316
|
+
Returns:
|
|
317
|
+
|
|
318
|
+
|type|description|
|
|
319
|
+
|----|-----------|
|
|
320
|
+
|`Array<a>`|An array containing all stack values|
|
|
321
|
+
|
|
322
|
+
Examples:
|
|
323
|
+
|
|
324
|
+
```grain
|
|
325
|
+
let stack = Stack.make()
|
|
326
|
+
Stack.push(1, stack)
|
|
327
|
+
Stack.push(2, stack)
|
|
328
|
+
assert Stack.toArray(stack) == [> 2, 1]
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Stack.**fromArray**
|
|
332
|
+
|
|
333
|
+
<details disabled>
|
|
334
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
335
|
+
No other changes yet.
|
|
336
|
+
</details>
|
|
337
|
+
|
|
338
|
+
```grain
|
|
339
|
+
fromArray: (arr: Array<a>) => Stack<a>
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Creates a stack from an array.
|
|
343
|
+
|
|
344
|
+
Parameters:
|
|
345
|
+
|
|
346
|
+
|param|type|description|
|
|
347
|
+
|-----|----|-----------|
|
|
348
|
+
|`arr`|`Array<a>`|The array to convert|
|
|
349
|
+
|
|
350
|
+
Returns:
|
|
351
|
+
|
|
352
|
+
|type|description|
|
|
353
|
+
|----|-----------|
|
|
354
|
+
|`Stack<a>`|A stack containing all array values|
|
|
355
|
+
|
|
356
|
+
Examples:
|
|
357
|
+
|
|
358
|
+
```grain
|
|
359
|
+
let s = Stack.fromArray([> 3, 2, 1])
|
|
360
|
+
assert Stack.pop(s) == Some(3)
|
|
361
|
+
assert Stack.pop(s) == Some(2)
|
|
362
|
+
assert Stack.pop(s) == Some(1)
|
|
363
|
+
assert Stack.pop(s) == None
|
|
364
|
+
```
|
|
365
|
+
|
|
228
366
|
## Stack.Immutable
|
|
229
367
|
|
|
230
368
|
An immutable stack implementation.
|
|
@@ -260,7 +398,7 @@ Functions and constants included in the Stack.Immutable module.
|
|
|
260
398
|
</details>
|
|
261
399
|
|
|
262
400
|
```grain
|
|
263
|
-
empty
|
|
401
|
+
empty: ImmutableStack<a>
|
|
264
402
|
```
|
|
265
403
|
|
|
266
404
|
An empty stack.
|
|
@@ -280,7 +418,7 @@ An empty stack.
|
|
|
280
418
|
</details>
|
|
281
419
|
|
|
282
420
|
```grain
|
|
283
|
-
isEmpty
|
|
421
|
+
isEmpty: (stack: ImmutableStack<a>) => Bool
|
|
284
422
|
```
|
|
285
423
|
|
|
286
424
|
Checks if the given stack contains no items.
|
|
@@ -313,7 +451,7 @@ Returns:
|
|
|
313
451
|
</details>
|
|
314
452
|
|
|
315
453
|
```grain
|
|
316
|
-
peek
|
|
454
|
+
peek: (stack: ImmutableStack<a>) => Option<a>
|
|
317
455
|
```
|
|
318
456
|
|
|
319
457
|
Provides the value at the top of the stack, if it exists.
|
|
@@ -345,7 +483,7 @@ Returns:
|
|
|
345
483
|
</details>
|
|
346
484
|
|
|
347
485
|
```grain
|
|
348
|
-
push
|
|
486
|
+
push: (value: a, stack: ImmutableStack<a>) => ImmutableStack<a>
|
|
349
487
|
```
|
|
350
488
|
|
|
351
489
|
Adds a new item to the top of the stack.
|
|
@@ -378,7 +516,7 @@ Returns:
|
|
|
378
516
|
</details>
|
|
379
517
|
|
|
380
518
|
```grain
|
|
381
|
-
pop
|
|
519
|
+
pop: (stack: ImmutableStack<a>) => ImmutableStack<a>
|
|
382
520
|
```
|
|
383
521
|
|
|
384
522
|
Removes the item at the top of the stack.
|
|
@@ -410,7 +548,7 @@ Returns:
|
|
|
410
548
|
</details>
|
|
411
549
|
|
|
412
550
|
```grain
|
|
413
|
-
size
|
|
551
|
+
size: (stack: ImmutableStack<a>) => Number
|
|
414
552
|
```
|
|
415
553
|
|
|
416
554
|
Computes the size of the input stack.
|
|
@@ -427,3 +565,147 @@ Returns:
|
|
|
427
565
|
|----|-----------|
|
|
428
566
|
|`Number`|The count of the items in the stack|
|
|
429
567
|
|
|
568
|
+
#### Stack.Immutable.**toList**
|
|
569
|
+
|
|
570
|
+
<details disabled>
|
|
571
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
572
|
+
No other changes yet.
|
|
573
|
+
</details>
|
|
574
|
+
|
|
575
|
+
```grain
|
|
576
|
+
toList: (stack: ImmutableStack<a>) => List<a>
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
Creates a list containing the elements of a stack.
|
|
580
|
+
|
|
581
|
+
Parameters:
|
|
582
|
+
|
|
583
|
+
|param|type|description|
|
|
584
|
+
|-----|----|-----------|
|
|
585
|
+
|`stack`|`ImmutableStack<a>`|The stack to convert|
|
|
586
|
+
|
|
587
|
+
Returns:
|
|
588
|
+
|
|
589
|
+
|type|description|
|
|
590
|
+
|----|-----------|
|
|
591
|
+
|`List<a>`|A list containing all stack values|
|
|
592
|
+
|
|
593
|
+
Examples:
|
|
594
|
+
|
|
595
|
+
```grain
|
|
596
|
+
use Stack.{ module Immutable as Stack }
|
|
597
|
+
let stack = Stack.empty
|
|
598
|
+
let stack = Stack.push(1, stack)
|
|
599
|
+
let stack = Stack.push(2, stack)
|
|
600
|
+
assert Stack.toList(stack) == [2, 1]
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
#### Stack.Immutable.**fromList**
|
|
604
|
+
|
|
605
|
+
<details disabled>
|
|
606
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
607
|
+
No other changes yet.
|
|
608
|
+
</details>
|
|
609
|
+
|
|
610
|
+
```grain
|
|
611
|
+
fromList: (list: List<a>) => ImmutableStack<a>
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
Creates a stack from a list.
|
|
615
|
+
|
|
616
|
+
Parameters:
|
|
617
|
+
|
|
618
|
+
|param|type|description|
|
|
619
|
+
|-----|----|-----------|
|
|
620
|
+
|`list`|`List<a>`|The list to convert|
|
|
621
|
+
|
|
622
|
+
Returns:
|
|
623
|
+
|
|
624
|
+
|type|description|
|
|
625
|
+
|----|-----------|
|
|
626
|
+
|`ImmutableStack<a>`|A stack containing all list values|
|
|
627
|
+
|
|
628
|
+
Examples:
|
|
629
|
+
|
|
630
|
+
```grain
|
|
631
|
+
use Stack.{ module Immutable as Stack }
|
|
632
|
+
let stack = Stack.fromList([2, 1])
|
|
633
|
+
assert Stack.peek(stack) == Some(2)
|
|
634
|
+
let stack = Stack.pop(stack)
|
|
635
|
+
assert Stack.peek(stack) == Some(1)
|
|
636
|
+
let stack = Stack.pop(stack)
|
|
637
|
+
assert Stack.isEmpty(stack)
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
#### Stack.Immutable.**toArray**
|
|
641
|
+
|
|
642
|
+
<details disabled>
|
|
643
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
644
|
+
No other changes yet.
|
|
645
|
+
</details>
|
|
646
|
+
|
|
647
|
+
```grain
|
|
648
|
+
toArray: (stack: ImmutableStack<a>) => Array<a>
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
Creates an array containing the elements of a stack.
|
|
652
|
+
|
|
653
|
+
Parameters:
|
|
654
|
+
|
|
655
|
+
|param|type|description|
|
|
656
|
+
|-----|----|-----------|
|
|
657
|
+
|`stack`|`ImmutableStack<a>`|The stack to convert|
|
|
658
|
+
|
|
659
|
+
Returns:
|
|
660
|
+
|
|
661
|
+
|type|description|
|
|
662
|
+
|----|-----------|
|
|
663
|
+
|`Array<a>`|An array containing all stack values|
|
|
664
|
+
|
|
665
|
+
Examples:
|
|
666
|
+
|
|
667
|
+
```grain
|
|
668
|
+
use Stack.{ module Immutable as Stack }
|
|
669
|
+
let stack = Stack.empty
|
|
670
|
+
let stack = Stack.push(1, stack)
|
|
671
|
+
let stack = Stack.push(2, stack)
|
|
672
|
+
assert Stack.toArray(stack) == [> 2, 1]
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
#### Stack.Immutable.**fromArray**
|
|
676
|
+
|
|
677
|
+
<details disabled>
|
|
678
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
679
|
+
No other changes yet.
|
|
680
|
+
</details>
|
|
681
|
+
|
|
682
|
+
```grain
|
|
683
|
+
fromArray: (arr: Array<a>) => ImmutableStack<a>
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
Creates a stack from an array.
|
|
687
|
+
|
|
688
|
+
Parameters:
|
|
689
|
+
|
|
690
|
+
|param|type|description|
|
|
691
|
+
|-----|----|-----------|
|
|
692
|
+
|`arr`|`Array<a>`|The array to convert|
|
|
693
|
+
|
|
694
|
+
Returns:
|
|
695
|
+
|
|
696
|
+
|type|description|
|
|
697
|
+
|----|-----------|
|
|
698
|
+
|`ImmutableStack<a>`|A stack containing all array values|
|
|
699
|
+
|
|
700
|
+
Examples:
|
|
701
|
+
|
|
702
|
+
```grain
|
|
703
|
+
use Stack.{ module Immutable as Stack }
|
|
704
|
+
let stack = Stack.fromArray([> 2, 1])
|
|
705
|
+
assert Stack.peek(stack) == Some(2)
|
|
706
|
+
let stack = Stack.pop(stack)
|
|
707
|
+
assert Stack.peek(stack) == Some(1)
|
|
708
|
+
let stack = Stack.pop(stack)
|
|
709
|
+
assert Stack.isEmpty(stack)
|
|
710
|
+
```
|
|
711
|
+
|