@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/rational.md ADDED
@@ -0,0 +1,545 @@
1
+ ---
2
+ title: Rational
3
+ ---
4
+
5
+ Utilities for working with the Rational type.
6
+
7
+ <details disabled>
8
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
9
+ No other changes yet.
10
+ </details>
11
+
12
+ ```grain
13
+ from "rational" include Rational
14
+ ```
15
+
16
+ ```grain
17
+ 1/2r
18
+ ```
19
+
20
+ ```grain
21
+ 3/4r
22
+ ```
23
+
24
+ ## Values
25
+
26
+ Functions and constants included in the Rational module.
27
+
28
+ ### Rational.**fromNumber**
29
+
30
+ <details disabled>
31
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
32
+ No other changes yet.
33
+ </details>
34
+
35
+ ```grain
36
+ fromNumber : (number: Number) => Rational
37
+ ```
38
+
39
+ Converts a Number to a Rational.
40
+
41
+ Parameters:
42
+
43
+ |param|type|description|
44
+ |-----|----|-----------|
45
+ |`number`|`Number`|The value to convert|
46
+
47
+ Returns:
48
+
49
+ |type|description|
50
+ |----|-----------|
51
+ |`Rational`|The Number represented as a Rational|
52
+
53
+ ### Rational.**toNumber**
54
+
55
+ <details disabled>
56
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
57
+ No other changes yet.
58
+ </details>
59
+
60
+ ```grain
61
+ toNumber : (rational: Rational) => Number
62
+ ```
63
+
64
+ Converts a Rational to a Number.
65
+
66
+ Parameters:
67
+
68
+ |param|type|description|
69
+ |-----|----|-----------|
70
+ |`rational`|`Rational`|The value to convert|
71
+
72
+ Returns:
73
+
74
+ |type|description|
75
+ |----|-----------|
76
+ |`Number`|The Rational represented as a Number|
77
+
78
+ ### Rational.**numerator**
79
+
80
+ <details disabled>
81
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
82
+ No other changes yet.
83
+ </details>
84
+
85
+ ```grain
86
+ numerator : (x: Rational) => Number
87
+ ```
88
+
89
+ Finds the numerator of the rational number.
90
+
91
+ Parameters:
92
+
93
+ |param|type|description|
94
+ |-----|----|-----------|
95
+ |`x`|`Rational`|The rational number to inspect|
96
+
97
+ Returns:
98
+
99
+ |type|description|
100
+ |----|-----------|
101
+ |`Number`|The numerator of the rational number|
102
+
103
+ ### Rational.**denominator**
104
+
105
+ <details disabled>
106
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
107
+ No other changes yet.
108
+ </details>
109
+
110
+ ```grain
111
+ denominator : (x: Rational) => Number
112
+ ```
113
+
114
+ Finds the denominator of the rational number.
115
+
116
+ Parameters:
117
+
118
+ |param|type|description|
119
+ |-----|----|-----------|
120
+ |`x`|`Rational`|The rational number to inspect|
121
+
122
+ Returns:
123
+
124
+ |type|description|
125
+ |----|-----------|
126
+ |`Number`|The denominator of the rational number|
127
+
128
+ ### Rational.**toIntegerRatio**
129
+
130
+ <details disabled>
131
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
132
+ No other changes yet.
133
+ </details>
134
+
135
+ ```grain
136
+ toIntegerRatio : (x: Rational) => (Number, Number)
137
+ ```
138
+
139
+ Gets the numerator and denominator of the rational.
140
+
141
+ Parameters:
142
+
143
+ |param|type|description|
144
+ |-----|----|-----------|
145
+ |`x`|`Rational`|The rational to split|
146
+
147
+ Returns:
148
+
149
+ |type|description|
150
+ |----|-----------|
151
+ |`(Number, Number)`|The numerator and denominator of the rational|
152
+
153
+ Examples:
154
+
155
+ ```grain
156
+ Rational.toIntegerRatio(1/2r) == (1, 2)
157
+ ```
158
+
159
+ ```grain
160
+ Rational.toIntegerRatio(2/8r) == (1, 4)
161
+ ```
162
+
163
+ ### Rational.**fromIntegerRatio**
164
+
165
+ <details disabled>
166
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
167
+ No other changes yet.
168
+ </details>
169
+
170
+ ```grain
171
+ fromIntegerRatio : (numerator: Number, denominator: Number) => Rational
172
+ ```
173
+
174
+ Creates a rational from a numerator and denominator.
175
+
176
+ Parameters:
177
+
178
+ |param|type|description|
179
+ |-----|----|-----------|
180
+ |`numerator`|`Number`|The numerator|
181
+ |`denominator`|`Number`|The denominator|
182
+
183
+ Returns:
184
+
185
+ |type|description|
186
+ |----|-----------|
187
+ |`Rational`|The reduced rational|
188
+
189
+ Throws:
190
+
191
+ `InvalidArgument(String)`
192
+
193
+ * If the numerator is not an integer
194
+ * If the denominator is not an integer
195
+
196
+ Examples:
197
+
198
+ ```grain
199
+ Rational.fromIntegerRatio(1, 2) == 1/2r
200
+ ```
201
+
202
+ ```grain
203
+ Rational.fromIntegerRatio(2, 8) == 1/4r
204
+ ```
205
+
206
+ ### Rational.**(+)**
207
+
208
+ <details disabled>
209
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
210
+ No other changes yet.
211
+ </details>
212
+
213
+ ```grain
214
+ (+) : (x: Rational, y: Rational) => Rational
215
+ ```
216
+
217
+ Computes the sum of its operands.
218
+
219
+ Parameters:
220
+
221
+ |param|type|description|
222
+ |-----|----|-----------|
223
+ |`x`|`Rational`|The first operand|
224
+ |`y`|`Rational`|The second operand|
225
+
226
+ Returns:
227
+
228
+ |type|description|
229
+ |----|-----------|
230
+ |`Rational`|The sum of the two operands|
231
+
232
+ Examples:
233
+
234
+ ```grain
235
+ use Rational.{ (+) }
236
+ assert 1/2r + 1/4r == 3/4r
237
+ ```
238
+
239
+ ### Rational.**(-)**
240
+
241
+ <details disabled>
242
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
243
+ No other changes yet.
244
+ </details>
245
+
246
+ ```grain
247
+ (-) : (x: Rational, y: Rational) => Rational
248
+ ```
249
+
250
+ Computes the difference of its operands.
251
+
252
+ Parameters:
253
+
254
+ |param|type|description|
255
+ |-----|----|-----------|
256
+ |`x`|`Rational`|The first operand|
257
+ |`y`|`Rational`|The second operand|
258
+
259
+ Returns:
260
+
261
+ |type|description|
262
+ |----|-----------|
263
+ |`Rational`|The difference of the two operands|
264
+
265
+ Examples:
266
+
267
+ ```grain
268
+ use Rational.{ (-) }
269
+ assert 1/2r - 1/4r == 1/4r
270
+ ```
271
+
272
+ ### Rational.**(*)**
273
+
274
+ <details disabled>
275
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
276
+ No other changes yet.
277
+ </details>
278
+
279
+ ```grain
280
+ (*) : (x: Rational, y: Rational) => Rational
281
+ ```
282
+
283
+ Computes the product of its operands.
284
+
285
+ Parameters:
286
+
287
+ |param|type|description|
288
+ |-----|----|-----------|
289
+ |`x`|`Rational`|The first operand|
290
+ |`y`|`Rational`|The second operand|
291
+
292
+ Returns:
293
+
294
+ |type|description|
295
+ |----|-----------|
296
+ |`Rational`|The product of the two operands|
297
+
298
+ Examples:
299
+
300
+ ```grain
301
+ use Rational.{ (*) }
302
+ assert 1/2r * 1/4r == 1/8r
303
+ ```
304
+
305
+ ### Rational.**(/)**
306
+
307
+ <details disabled>
308
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
309
+ No other changes yet.
310
+ </details>
311
+
312
+ ```grain
313
+ (/) : (x: Rational, y: Rational) => Rational
314
+ ```
315
+
316
+ Computes the quotient of its operands.
317
+
318
+ Parameters:
319
+
320
+ |param|type|description|
321
+ |-----|----|-----------|
322
+ |`x`|`Rational`|The first operand|
323
+ |`y`|`Rational`|The second operand|
324
+
325
+ Returns:
326
+
327
+ |type|description|
328
+ |----|-----------|
329
+ |`Rational`|The quotient of the two operands|
330
+
331
+ Examples:
332
+
333
+ ```grain
334
+ use Rational.{ (/) }
335
+ assert 1/2r / 1/4r == 2/1r
336
+ ```
337
+
338
+ ### Rational.**(==)**
339
+
340
+ <details disabled>
341
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
342
+ No other changes yet.
343
+ </details>
344
+
345
+ ```grain
346
+ (==) : (x: Rational, y: Rational) => Bool
347
+ ```
348
+
349
+ Checks if the first value is equal to the second value.
350
+
351
+ Parameters:
352
+
353
+ |param|type|description|
354
+ |-----|----|-----------|
355
+ |`x`|`Rational`|The first value|
356
+ |`y`|`Rational`|The second value|
357
+
358
+ Returns:
359
+
360
+ |type|description|
361
+ |----|-----------|
362
+ |`Bool`|`true` if the first value is equal to the second value or `false` otherwise|
363
+
364
+ Examples:
365
+
366
+ ```grain
367
+ use Rational.{ (==) }
368
+ assert 1/2r == 1/2r
369
+ ```
370
+
371
+ ### Rational.**(!=)**
372
+
373
+ <details disabled>
374
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
375
+ No other changes yet.
376
+ </details>
377
+
378
+ ```grain
379
+ (!=) : (x: Rational, y: Rational) => Bool
380
+ ```
381
+
382
+ Checks if the first value is not equal to the second value.
383
+
384
+ Parameters:
385
+
386
+ |param|type|description|
387
+ |-----|----|-----------|
388
+ |`x`|`Rational`|The first value|
389
+ |`y`|`Rational`|The second value|
390
+
391
+ Returns:
392
+
393
+ |type|description|
394
+ |----|-----------|
395
+ |`Bool`|`true` if the first value is not equal to the second value or `false` otherwise|
396
+
397
+ Examples:
398
+
399
+ ```grain
400
+ use Rational.{ (!=) }
401
+ assert 1/2r != 1/4r
402
+ ```
403
+
404
+ ### Rational.**(<)**
405
+
406
+ <details disabled>
407
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
408
+ No other changes yet.
409
+ </details>
410
+
411
+ ```grain
412
+ (<) : (x: Rational, y: Rational) => Bool
413
+ ```
414
+
415
+ Checks if the first value is less than the second value.
416
+
417
+ Parameters:
418
+
419
+ |param|type|description|
420
+ |-----|----|-----------|
421
+ |`x`|`Rational`|The first value|
422
+ |`y`|`Rational`|The second value|
423
+
424
+ Returns:
425
+
426
+ |type|description|
427
+ |----|-----------|
428
+ |`Bool`|`true` if the first value is less than the second value or `false` otherwise|
429
+
430
+ Examples:
431
+
432
+ ```grain
433
+ use Rational.{ (<) }
434
+ assert 1/4r < 1/2r
435
+ ```
436
+
437
+ ### Rational.**(>)**
438
+
439
+ <details disabled>
440
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
441
+ No other changes yet.
442
+ </details>
443
+
444
+ ```grain
445
+ (>) : (x: Rational, y: Rational) => Bool
446
+ ```
447
+
448
+ Checks if the first value is greater than the second value.
449
+
450
+ Parameters:
451
+
452
+ |param|type|description|
453
+ |-----|----|-----------|
454
+ |`x`|`Rational`|The first value|
455
+ |`y`|`Rational`|The second value|
456
+
457
+ Returns:
458
+
459
+ |type|description|
460
+ |----|-----------|
461
+ |`Bool`|`true` if the first value is greater than the second value or `false` otherwise|
462
+
463
+ Examples:
464
+
465
+ ```grain
466
+ use Rational.{ (>) }
467
+ assert 1/2r > 1/4r
468
+ ```
469
+
470
+ ### Rational.**(<=)**
471
+
472
+ <details disabled>
473
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
474
+ No other changes yet.
475
+ </details>
476
+
477
+ ```grain
478
+ (<=) : (x: Rational, y: Rational) => Bool
479
+ ```
480
+
481
+ Checks if the first value is less than or equal to the second value.
482
+
483
+ Parameters:
484
+
485
+ |param|type|description|
486
+ |-----|----|-----------|
487
+ |`x`|`Rational`|The first value|
488
+ |`y`|`Rational`|The second value|
489
+
490
+ Returns:
491
+
492
+ |type|description|
493
+ |----|-----------|
494
+ |`Bool`|`true` if the first value is less than or equal to the second value or `false` otherwise|
495
+
496
+ Examples:
497
+
498
+ ```grain
499
+ use Rational.{ (<=) }
500
+ assert 1/4r <= 1/2r
501
+ ```
502
+
503
+ ```grain
504
+ use Rational.{ (<=) }
505
+ assert 1/2r <= 1/2r
506
+ ```
507
+
508
+ ### Rational.**(>=)**
509
+
510
+ <details disabled>
511
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
512
+ No other changes yet.
513
+ </details>
514
+
515
+ ```grain
516
+ (>=) : (x: Rational, y: Rational) => Bool
517
+ ```
518
+
519
+ Checks if the first value is greater than or equal to the second value.
520
+
521
+ Parameters:
522
+
523
+ |param|type|description|
524
+ |-----|----|-----------|
525
+ |`x`|`Rational`|The first value|
526
+ |`y`|`Rational`|The second value|
527
+
528
+ Returns:
529
+
530
+ |type|description|
531
+ |----|-----------|
532
+ |`Bool`|`true` if the first value is greater than or equal to the second value or `false` otherwise|
533
+
534
+ Examples:
535
+
536
+ ```grain
537
+ use Rational.{ (>=) }
538
+ assert 1/2r >= 1/4r
539
+ ```
540
+
541
+ ```grain
542
+ use Rational.{ (>=) }
543
+ assert 1/2r >= 1/2r
544
+ ```
545
+