@grain/stdlib 0.5.13 → 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 +193 -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/char.md CHANGED
@@ -12,7 +12,19 @@ No other changes yet.
12
12
  </details>
13
13
 
14
14
  ```grain
15
- import Char from "char"
15
+ from "char" include Char
16
+ ```
17
+
18
+ ```grain
19
+ 'a'
20
+ ```
21
+
22
+ ```grain
23
+ '1'
24
+ ```
25
+
26
+ ```grain
27
+ '🌾'
16
28
  ```
17
29
 
18
30
  ## Values
@@ -53,7 +65,7 @@ No other changes yet.
53
65
  </details>
54
66
 
55
67
  ```grain
56
- isValid : Number -> Bool
68
+ isValid : (charCode: Number) => Bool
57
69
  ```
58
70
 
59
71
  Determines whether the given character code is a valid Unicode scalar value.
@@ -70,6 +82,16 @@ Returns:
70
82
  |----|-----------|
71
83
  |`Bool`|`true` if the number refers to a valid Unicode scalar value or `false` otherwise|
72
84
 
85
+ Examples:
86
+
87
+ ```grain
88
+ Char.isValid(0) == true
89
+ ```
90
+
91
+ ```grain
92
+ Char.isValid(-1) == false
93
+ ```
94
+
73
95
  ### Char.**code**
74
96
 
75
97
  <details disabled>
@@ -78,7 +100,7 @@ No other changes yet.
78
100
  </details>
79
101
 
80
102
  ```grain
81
- code : Char -> Number
103
+ code : (char: Char) => Number
82
104
  ```
83
105
 
84
106
  Determines the Unicode scalar value for a character.
@@ -95,6 +117,16 @@ Returns:
95
117
  |----|-----------|
96
118
  |`Number`|The Unicode scalar value for the given character|
97
119
 
120
+ Examples:
121
+
122
+ ```grain
123
+ Char.code('a') == 97
124
+ ```
125
+
126
+ ```grain
127
+ Char.code('🌾') == 127806
128
+ ```
129
+
98
130
  ### Char.**fromCode**
99
131
 
100
132
  <details disabled>
@@ -103,7 +135,7 @@ No other changes yet.
103
135
  </details>
104
136
 
105
137
  ```grain
106
- fromCode : Number -> Char
138
+ fromCode : (usv: Number) => Char
107
139
  ```
108
140
 
109
141
  Creates a character from the given Unicode scalar value.
@@ -126,6 +158,16 @@ Throws:
126
158
 
127
159
  * When the Unicode scalar value is invalid
128
160
 
161
+ Examples:
162
+
163
+ ```grain
164
+ Char.fromCode(97) == 'a'
165
+ ```
166
+
167
+ ```grain
168
+ Char.fromCode(127806) == '🌾'
169
+ ```
170
+
129
171
  ### Char.**succ**
130
172
 
131
173
  <details disabled>
@@ -134,7 +176,7 @@ No other changes yet.
134
176
  </details>
135
177
 
136
178
  ```grain
137
- succ : Char -> Char
179
+ succ : (char: Char) => Char
138
180
  ```
139
181
 
140
182
  Returns the next valid character by Unicode scalar value.
@@ -157,6 +199,16 @@ Throws:
157
199
 
158
200
  * When the input character is the maximum valid Unicode scalar value
159
201
 
202
+ Examples:
203
+
204
+ ```grain
205
+ Char.succ('a') == 'b'
206
+ ```
207
+
208
+ ```grain
209
+ Char.succ('1') == '2'
210
+ ```
211
+
160
212
  ### Char.**pred**
161
213
 
162
214
  <details disabled>
@@ -165,7 +217,7 @@ No other changes yet.
165
217
  </details>
166
218
 
167
219
  ```grain
168
- pred : Char -> Char
220
+ pred : (char: Char) => Char
169
221
  ```
170
222
 
171
223
  Returns the previous valid character by Unicode scalar value.
@@ -188,6 +240,16 @@ Throws:
188
240
 
189
241
  * When the input character is the minimum valid Unicode scalar value
190
242
 
243
+ Examples:
244
+
245
+ ```grain
246
+ Char.pred('b') == 'a'
247
+ ```
248
+
249
+ ```grain
250
+ Char.pred('2') == '1'
251
+ ```
252
+
191
253
  ### Char.**toString**
192
254
 
193
255
  <details disabled>
@@ -196,7 +258,7 @@ No other changes yet.
196
258
  </details>
197
259
 
198
260
  ```grain
199
- toString : Char -> String
261
+ toString : (char: Char) => String
200
262
  ```
201
263
 
202
264
  Converts the given character to a string.
@@ -213,3 +275,307 @@ Returns:
213
275
  |----|-----------|
214
276
  |`String`|A string containing the given character|
215
277
 
278
+ Examples:
279
+
280
+ ```grain
281
+ Char.toString('a') == "a"
282
+ ```
283
+
284
+ ```grain
285
+ Char.toString('🌾') == "🌾"
286
+ ```
287
+
288
+ ### Char.**(<)**
289
+
290
+ <details disabled>
291
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
292
+ No other changes yet.
293
+ </details>
294
+
295
+ ```grain
296
+ (<) : (x: Char, y: Char) => Bool
297
+ ```
298
+
299
+ Checks if the first character is less than the second character by Unicode scalar value.
300
+
301
+ Parameters:
302
+
303
+ |param|type|description|
304
+ |-----|----|-----------|
305
+ |`x`|`Char`|The first character|
306
+ |`y`|`Char`|The second character|
307
+
308
+ Returns:
309
+
310
+ |type|description|
311
+ |----|-----------|
312
+ |`Bool`|`true` if the first character is less than the second character or `false` otherwise|
313
+
314
+ Examples:
315
+
316
+ ```grain
317
+ use Char.{ (<) }
318
+ assert 'a' < 'b'
319
+ ```
320
+
321
+ ```grain
322
+ use Char.{ (<) }
323
+ assert '1' < '2'
324
+ ```
325
+
326
+ ### Char.**(<=)**
327
+
328
+ <details disabled>
329
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
330
+ No other changes yet.
331
+ </details>
332
+
333
+ ```grain
334
+ (<=) : (x: Char, y: Char) => Bool
335
+ ```
336
+
337
+ Checks if the first character is less than or equal to the second character by Unicode scalar value.
338
+
339
+ Parameters:
340
+
341
+ |param|type|description|
342
+ |-----|----|-----------|
343
+ |`x`|`Char`|The first character|
344
+ |`y`|`Char`|The second character|
345
+
346
+ Returns:
347
+
348
+ |type|description|
349
+ |----|-----------|
350
+ |`Bool`|`true` if the first character is less than or equal to the second character or `false` otherwise|
351
+
352
+ Examples:
353
+
354
+ ```grain
355
+ use Char.{ (<=) }
356
+ assert 'a' <= 'b'
357
+ ```
358
+
359
+ ```grain
360
+ use Char.{ (<=) }
361
+ assert '1' <= '2'
362
+ ```
363
+
364
+ ```grain
365
+ use Char.{ (<=) }
366
+ assert 'a' <= 'a'
367
+ ```
368
+
369
+ ### Char.**(>)**
370
+
371
+ <details disabled>
372
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
373
+ No other changes yet.
374
+ </details>
375
+
376
+ ```grain
377
+ (>) : (x: Char, y: Char) => Bool
378
+ ```
379
+
380
+ Checks if the first character is greater than the second character by Unicode scalar value.
381
+
382
+ Parameters:
383
+
384
+ |param|type|description|
385
+ |-----|----|-----------|
386
+ |`x`|`Char`|The first character|
387
+ |`y`|`Char`|The second character|
388
+
389
+ Returns:
390
+
391
+ |type|description|
392
+ |----|-----------|
393
+ |`Bool`|`true` if the first character is greater than the second character or `false` otherwise|
394
+
395
+ Examples:
396
+
397
+ ```grain
398
+ use Char.{ (>) }
399
+ assert 'b' > 'a'
400
+ ```
401
+
402
+ ```grain
403
+ use Char.{ (>) }
404
+ assert '2' > '1'
405
+ ```
406
+
407
+ ### Char.**(>=)**
408
+
409
+ <details disabled>
410
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
411
+ No other changes yet.
412
+ </details>
413
+
414
+ ```grain
415
+ (>=) : (x: Char, y: Char) => Bool
416
+ ```
417
+
418
+ Checks if the first character is greater than or equal to the second character by Unicode scalar value.
419
+
420
+ Parameters:
421
+
422
+ |param|type|description|
423
+ |-----|----|-----------|
424
+ |`x`|`Char`|The first character|
425
+ |`y`|`Char`|The second character|
426
+
427
+ Returns:
428
+
429
+ |type|description|
430
+ |----|-----------|
431
+ |`Bool`|`true` if the first character is greater than or equal to the second character or `false` otherwise|
432
+
433
+ Examples:
434
+
435
+ ```grain
436
+ use Char.{ (>=) }
437
+ assert 'b' >= 'a'
438
+ ```
439
+
440
+ ```grain
441
+ use Char.{ (>=) }
442
+ assert '2' >= '1'
443
+ ```
444
+
445
+ ```grain
446
+ use Char.{ (>=) }
447
+ assert 'a' >= 'a'
448
+ ```
449
+
450
+ ### Char.**isAsciiDigit**
451
+
452
+ <details disabled>
453
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
454
+ No other changes yet.
455
+ </details>
456
+
457
+ ```grain
458
+ isAsciiDigit : (char: Char) => Bool
459
+ ```
460
+
461
+ Checks if the character is an ASCII digit.
462
+
463
+ Parameters:
464
+
465
+ |param|type|description|
466
+ |-----|----|-----------|
467
+ |`char`|`Char`|The character to check|
468
+
469
+ Returns:
470
+
471
+ |type|description|
472
+ |----|-----------|
473
+ |`Bool`|`true` if the character is an ASCII digit or `false` otherwise|
474
+
475
+ Examples:
476
+
477
+ ```grain
478
+ assert Char.isAsciiDigit('1')
479
+ ```
480
+
481
+ ```grain
482
+ assert !Char.isAsciiDigit('a')
483
+ ```
484
+
485
+ ### Char.**isAsciiAlpha**
486
+
487
+ <details disabled>
488
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
489
+ No other changes yet.
490
+ </details>
491
+
492
+ ```grain
493
+ isAsciiAlpha : (char: Char) => Bool
494
+ ```
495
+
496
+ Checks if the character is an ASCII alphabetical character.
497
+
498
+ Parameters:
499
+
500
+ |param|type|description|
501
+ |-----|----|-----------|
502
+ |`char`|`Char`|The character to check|
503
+
504
+ Returns:
505
+
506
+ |type|description|
507
+ |----|-----------|
508
+ |`Bool`|`true` if the character is an ASCII alphabetical or `false` otherwise|
509
+
510
+ Examples:
511
+
512
+ ```grain
513
+ assert Char.isAsciiAlpha('a')
514
+ ```
515
+
516
+ ```grain
517
+ assert !Char.isAsciiAlpha('1')
518
+ ```
519
+
520
+ ### Char.**toAsciiLowercase**
521
+
522
+ <details disabled>
523
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
524
+ No other changes yet.
525
+ </details>
526
+
527
+ ```grain
528
+ toAsciiLowercase : (char: Char) => Char
529
+ ```
530
+
531
+ Converts the character to ASCII lowercase if it is an ASCII uppercase character.
532
+
533
+ Parameters:
534
+
535
+ |param|type|description|
536
+ |-----|----|-----------|
537
+ |`char`|`Char`|The character to convert|
538
+
539
+ Returns:
540
+
541
+ |type|description|
542
+ |----|-----------|
543
+ |`Char`|The lowercased character|
544
+
545
+ Examples:
546
+
547
+ ```grain
548
+ assert Char.toAsciiLowercase('B') == 'b'
549
+ ```
550
+
551
+ ### Char.**toAsciiUppercase**
552
+
553
+ <details disabled>
554
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
555
+ No other changes yet.
556
+ </details>
557
+
558
+ ```grain
559
+ toAsciiUppercase : (char: Char) => Char
560
+ ```
561
+
562
+ Converts the character to ASCII uppercase if it is an ASCII lowercase character.
563
+
564
+ Parameters:
565
+
566
+ |param|type|description|
567
+ |-----|----|-----------|
568
+ |`char`|`Char`|The character to convert|
569
+
570
+ Returns:
571
+
572
+ |type|description|
573
+ |----|-----------|
574
+ |`Char`|The uppercased character|
575
+
576
+ Examples:
577
+
578
+ ```grain
579
+ assert Char.toAsciiUppercase('b') == 'B'
580
+ ```
581
+
package/exception.gr CHANGED
@@ -1,20 +1,20 @@
1
1
  /**
2
- * @module Exception: Utilities for working with the Exception type.
2
+ * Utilities for working with the Exception type.
3
3
  *
4
- * The Exception type represents an error that has occured during computation.
4
+ * The Exception type represents an error that has occurred during computation.
5
5
  *
6
- * @example import Exception from "exception"
6
+ * @example from "exception" include Exception
7
7
  *
8
- * @since 0.3.0
8
+ * @example exception ExampleError(Number)
9
+ * @example exception ExampleError
10
+ *
11
+ * @since v0.3.0
9
12
  */
13
+ module Exception
10
14
 
11
- import WasmI32 from "runtime/unsafe/wasmi32"
12
- import Memory from "runtime/unsafe/memory"
13
- import Exception from "runtime/exception"
14
-
15
- /**
16
- * @section Values: Functions included in the Exception module.
17
- */
15
+ from "runtime/unsafe/wasmi32" include WasmI32
16
+ from "runtime/unsafe/memory" include Memory
17
+ from "runtime/exception" include Exception
18
18
 
19
19
  /**
20
20
  * Registers an exception printer. When an exception is thrown, all registered
@@ -23,10 +23,24 @@ import Exception from "runtime/exception"
23
23
  * used as the exception's string value.
24
24
  *
25
25
  * @param printer: The exception printer to register
26
+ *
27
+ * @example
28
+ * exception ExampleError(Number)
29
+ *
30
+ * Exception.registerPrinter(e => {
31
+ * match (e) {
32
+ * ExampleError(lineNumber) =>
33
+ * Some("Error found on line: " ++ toString(lineNumber)),
34
+ * _ => None,
35
+ * }
36
+ * })
37
+ *
38
+ * throw ExampleError(1) // Error found on line: 1
39
+ *
26
40
  * @since v0.3.0
27
41
  */
28
42
  @disableGC
29
- export let rec registerPrinter = (printer: Exception -> Option<String>) => {
43
+ provide let rec registerPrinter = (printer: Exception => Option<String>) => {
30
44
  // This function _must_ be @disableGC because the printer list uses
31
45
  // unsafe types. Not really a memory leak as this list is never collected
32
46
 
package/exception.md CHANGED
@@ -4,7 +4,7 @@ title: Exception
4
4
 
5
5
  Utilities for working with the Exception type.
6
6
 
7
- The Exception type represents an error that has occured during computation.
7
+ The Exception type represents an error that has occurred during computation.
8
8
 
9
9
  <details disabled>
10
10
  <summary tabindex="-1">Added in <code>0.3.0</code></summary>
@@ -12,12 +12,20 @@ No other changes yet.
12
12
  </details>
13
13
 
14
14
  ```grain
15
- import Exception from "exception"
15
+ from "exception" include Exception
16
+ ```
17
+
18
+ ```grain
19
+ exception ExampleError(Number)
20
+ ```
21
+
22
+ ```grain
23
+ exception ExampleError
16
24
  ```
17
25
 
18
26
  ## Values
19
27
 
20
- Functions included in the Exception module.
28
+ Functions and constants included in the Exception module.
21
29
 
22
30
  ### Exception.**registerPrinter**
23
31
 
@@ -27,7 +35,7 @@ No other changes yet.
27
35
  </details>
28
36
 
29
37
  ```grain
30
- registerPrinter : (Exception -> Option<String>) -> Void
38
+ registerPrinter : (printer: (Exception => Option<String>)) => Void
31
39
  ```
32
40
 
33
41
  Registers an exception printer. When an exception is thrown, all registered
@@ -39,5 +47,21 @@ Parameters:
39
47
 
40
48
  |param|type|description|
41
49
  |-----|----|-----------|
42
- |`printer`|`Exception -> Option<String>`|The exception printer to register|
50
+ |`printer`|`Exception => Option<String>`|The exception printer to register|
51
+
52
+ Examples:
53
+
54
+ ```grain
55
+ exception ExampleError(Number)
56
+
57
+ Exception.registerPrinter(e => {
58
+ match (e) {
59
+ ExampleError(lineNumber) =>
60
+ Some("Error found on line: " ++ toString(lineNumber)),
61
+ _ => None,
62
+ }
63
+ })
64
+
65
+ throw ExampleError(1) // Error found on line: 1
66
+ ```
43
67