@grain/stdlib 0.5.2 → 0.5.4

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 (54) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/array.gr +61 -1
  3. package/array.md +113 -0
  4. package/bigint.md +30 -30
  5. package/buffer.gr +24 -22
  6. package/char.gr +2 -2
  7. package/float32.md +3 -3
  8. package/float64.md +3 -3
  9. package/immutablemap.gr +493 -0
  10. package/immutablemap.md +479 -0
  11. package/immutablepriorityqueue.gr +360 -0
  12. package/immutablepriorityqueue.md +291 -0
  13. package/immutableset.gr +498 -0
  14. package/immutableset.md +449 -0
  15. package/list.gr +75 -2
  16. package/list.md +110 -0
  17. package/map.gr +1 -2
  18. package/marshal.gr +1058 -0
  19. package/marshal.md +76 -0
  20. package/number.gr +689 -23
  21. package/number.md +362 -27
  22. package/package.json +1 -1
  23. package/pervasives.gr +16 -5
  24. package/pervasives.md +28 -0
  25. package/priorityqueue.gr +261 -0
  26. package/priorityqueue.md +309 -0
  27. package/queue.gr +14 -1
  28. package/queue.md +16 -1
  29. package/regex.gr +90 -67
  30. package/runtime/bigint.gr +4 -4
  31. package/runtime/compare.gr +179 -0
  32. package/runtime/compare.md +6 -0
  33. package/runtime/equal.gr +3 -3
  34. package/runtime/exception.gr +9 -5
  35. package/runtime/exception.md +8 -2
  36. package/runtime/gc.gr +2 -1
  37. package/runtime/malloc.gr +1 -3
  38. package/runtime/numberUtils.gr +11 -11
  39. package/runtime/numbers.gr +423 -100
  40. package/runtime/numbers.md +50 -0
  41. package/runtime/string.gr +4 -2
  42. package/set.gr +26 -27
  43. package/stack.gr +12 -0
  44. package/stack.md +15 -0
  45. package/string.gr +409 -53
  46. package/string.md +164 -1
  47. package/sys/file.gr +4 -4
  48. package/sys/file.md +3 -3
  49. package/sys/process.gr +3 -3
  50. package/sys/process.md +3 -3
  51. package/sys/random.gr +2 -2
  52. package/sys/random.md +2 -2
  53. package/sys/time.gr +2 -2
  54. package/sys/time.md +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,64 @@
1
1
  # Changelog
2
2
 
3
+ ### [0.5.4](https://github.com/grain-lang/grain/compare/stdlib-v0.5.3...stdlib-v0.5.4) (2022-11-12)
4
+
5
+
6
+ ### Features
7
+
8
+ * **stdlib:** Add `empty` constant to ImmutablePriorityQueue module ([427335f](https://github.com/grain-lang/grain/commit/427335fa5c211445f727a650ca06adacfe9c5310))
9
+ * **stdlib:** Add `empty` constant to Queue module ([427335f](https://github.com/grain-lang/grain/commit/427335fa5c211445f727a650ca06adacfe9c5310))
10
+ * **stdlib:** Add `empty` constant to Stack module ([427335f](https://github.com/grain-lang/grain/commit/427335fa5c211445f727a650ca06adacfe9c5310))
11
+ * **stdlib:** Add `exp` function to Number module ([5af9a99](https://github.com/grain-lang/grain/commit/5af9a99b2ec3b4a2d6745cb22b70defe2b366cfa))
12
+ * **stdlib:** Add `factorial` function to Number module ([5af9a99](https://github.com/grain-lang/grain/commit/5af9a99b2ec3b4a2d6745cb22b70defe2b366cfa))
13
+ * **stdlib:** Add `gamma` function to Number module ([5af9a99](https://github.com/grain-lang/grain/commit/5af9a99b2ec3b4a2d6745cb22b70defe2b366cfa))
14
+ * **stdlib:** Add `infinity` constant to the Number module ([c24f6c1](https://github.com/grain-lang/grain/commit/c24f6c1cfae87632a003c0337c29ec98a80cfda2))
15
+ * **stdlib:** Add `nan` constant to the Number module ([c24f6c1](https://github.com/grain-lang/grain/commit/c24f6c1cfae87632a003c0337c29ec98a80cfda2))
16
+ * **stdlib:** Add `pow` function to Number module ([5af9a99](https://github.com/grain-lang/grain/commit/5af9a99b2ec3b4a2d6745cb22b70defe2b366cfa))
17
+ * **stdlib:** Add `replaceAll` function to String module ([5606cd2](https://github.com/grain-lang/grain/commit/5606cd246583884175b135cbeb29024400651b34))
18
+ * **stdlib:** Add `replaceFirst` function to String module ([5606cd2](https://github.com/grain-lang/grain/commit/5606cd246583884175b135cbeb29024400651b34))
19
+ * **stdlib:** Add `replaceLast` function to String module ([5606cd2](https://github.com/grain-lang/grain/commit/5606cd246583884175b135cbeb29024400651b34))
20
+ * **stdlib:** Add `tan` function to Number module ([5af9a99](https://github.com/grain-lang/grain/commit/5af9a99b2ec3b4a2d6745cb22b70defe2b366cfa))
21
+ * **stdlib:** Add `toDegrees` function to Number module ([5af9a99](https://github.com/grain-lang/grain/commit/5af9a99b2ec3b4a2d6745cb22b70defe2b366cfa))
22
+ * **stdlib:** Add `toRadians` function to Number module ([5af9a99](https://github.com/grain-lang/grain/commit/5af9a99b2ec3b4a2d6745cb22b70defe2b366cfa))
23
+ * **stdlib:** Add additional functions to Number module ([#1443](https://github.com/grain-lang/grain/issues/1443)) ([5af9a99](https://github.com/grain-lang/grain/commit/5af9a99b2ec3b4a2d6745cb22b70defe2b366cfa))
24
+ * **stdlib:** Add replacement functions to String module ([#1441](https://github.com/grain-lang/grain/issues/1441)) ([5606cd2](https://github.com/grain-lang/grain/commit/5606cd246583884175b135cbeb29024400651b34))
25
+ * **stdlib:** Added `empty` constant to immutable data structures ([#1466](https://github.com/grain-lang/grain/issues/1466)) ([427335f](https://github.com/grain-lang/grain/commit/427335fa5c211445f727a650ca06adacfe9c5310))
26
+ * **stdlib:** Implement `fromArray` in PriorityQueue & ImmutablePriorityQueue modules ([#1451](https://github.com/grain-lang/grain/issues/1451)) ([d321f84](https://github.com/grain-lang/grain/commit/d321f84174fee2a340745a9f55994fbfa23f6c7a))
27
+ * **stdlib:** Implement ImmutableMap and ImmutableSet ([#1414](https://github.com/grain-lang/grain/issues/1414)) ([b31120d](https://github.com/grain-lang/grain/commit/b31120d41be668c48b9bca9f2b944616371a8ab4))
28
+ * **stdlib:** Improved efficiency of constructing a PriorityQueue from a List ([d321f84](https://github.com/grain-lang/grain/commit/d321f84174fee2a340745a9f55994fbfa23f6c7a))
29
+ * **stdlib:** Optimize string trimming ([#1442](https://github.com/grain-lang/grain/issues/1442)) ([0212247](https://github.com/grain-lang/grain/commit/0212247a7fbf0d54085959de2853f3fe66cd8b12))
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * **compiler:** Panic immediately when out of memory ([#1450](https://github.com/grain-lang/grain/issues/1450)) ([943d47d](https://github.com/grain-lang/grain/commit/943d47dddde2d88fd96727e9d7ed8501efec42ef))
35
+ * **grainfmt:** Handle chained value bindings properly ([#1467](https://github.com/grain-lang/grain/issues/1467)) ([07bfcd3](https://github.com/grain-lang/grain/commit/07bfcd3f15c34ef99b05531591b1473f206b7395))
36
+ * **grainfmt:** Indent lines when wrapping infix operators ([#1465](https://github.com/grain-lang/grain/issues/1465)) ([d705849](https://github.com/grain-lang/grain/commit/d705849ea8d9073e608576b77adeae834c454e0b))
37
+ * **runtime:** Handle bigint mul/div within Number correctly ([#1475](https://github.com/grain-lang/grain/issues/1475)) ([0fe8aa6](https://github.com/grain-lang/grain/commit/0fe8aa6a96a9c5ebf2f2bf2e1f28578badfb337f))
38
+ * **stdlib:** Fix anchoring behavior in Regex.replaceAll ([#1440](https://github.com/grain-lang/grain/issues/1440)) ([d513eff](https://github.com/grain-lang/grain/commit/d513effe569d0aa0d44c974596fd285f1ad8d57d))
39
+ * **stdlib:** Fix handling of `NaN` and `Infinity` in Number module ([#1457](https://github.com/grain-lang/grain/issues/1457)) ([c24f6c1](https://github.com/grain-lang/grain/commit/c24f6c1cfae87632a003c0337c29ec98a80cfda2))
40
+
41
+ ### [0.5.3](https://github.com/grain-lang/grain/compare/stdlib-v0.5.2...stdlib-v0.5.3) (2022-08-05)
42
+
43
+
44
+ ### Features
45
+
46
+ * Implement Pervasives.compare ([#1399](https://github.com/grain-lang/grain/issues/1399)) ([ebd87e4](https://github.com/grain-lang/grain/commit/ebd87e4308a8950fd95f060ebc446833b064237c))
47
+ * **stdlib:** Add `charCodeAt` function to String module ([#1376](https://github.com/grain-lang/grain/issues/1376)) ([c3abbc9](https://github.com/grain-lang/grain/commit/c3abbc991c8b05e3de20e670d2bc3e491feebf8a))
48
+ * **stdlib:** Add `lastIndexOf` function to String module ([#1372](https://github.com/grain-lang/grain/issues/1372)) ([b73d9bf](https://github.com/grain-lang/grain/commit/b73d9bf9ff3291b83e6f4263e392395d04dc9995))
49
+ * **stdlib:** Implement `isFloat`, `isInteger` & `isRational` in Number module ([#1393](https://github.com/grain-lang/grain/issues/1393)) ([0af0669](https://github.com/grain-lang/grain/commit/0af066993a2b80e417d2c625b27fd11cb1f1f55f))
50
+ * **stdlib:** Implement List.zip, List.unzip, List.zipWith, Array.reduceRight, Array.zipWith ([#1363](https://github.com/grain-lang/grain/issues/1363)) ([3e7c147](https://github.com/grain-lang/grain/commit/3e7c147fea2d2fb8b7c5a3d6b3eb1453f2861e36))
51
+ * **stdlib:** Implement mutable/immutable priority queues ([#1397](https://github.com/grain-lang/grain/issues/1397)) ([244be1b](https://github.com/grain-lang/grain/commit/244be1b7254caf0b451902ac56413382eb196747))
52
+ * **stdlib:** Marshal ([#1352](https://github.com/grain-lang/grain/issues/1352)) ([d659de2](https://github.com/grain-lang/grain/commit/d659de2d92260f7726164876827c639bfd9d0590))
53
+
54
+
55
+ ### Bug Fixes
56
+
57
+ * **compiler:** Correctly handle underscores in bigint literals ([0af0669](https://github.com/grain-lang/grain/commit/0af066993a2b80e417d2c625b27fd11cb1f1f55f))
58
+ * **graindoc:** Use defined module name throughout generated doc ([#1406](https://github.com/grain-lang/grain/issues/1406)) ([c33a777](https://github.com/grain-lang/grain/commit/c33a777a93d5e40a081991db5e6ea61ade4fbabc))
59
+ * **stdlib:** Correctly promote numbers to bigints when left-shifting ([#1354](https://github.com/grain-lang/grain/issues/1354)) ([5280e98](https://github.com/grain-lang/grain/commit/5280e98a91a57fae074299fc7bad3c41f69fa2a3))
60
+ * **stdlib:** Prevent addBytesSlice throwing error on empty buffer ([#1394](https://github.com/grain-lang/grain/issues/1394)) ([bdd4be4](https://github.com/grain-lang/grain/commit/bdd4be46730290908b7b939f41679acce7834167))
61
+
3
62
  ### [0.5.2](https://github.com/grain-lang/grain/compare/stdlib-v0.5.1...stdlib-v0.5.2) (2022-06-29)
4
63
 
5
64
 
package/array.gr CHANGED
@@ -48,6 +48,7 @@ let initLength = length => {
48
48
  * @param array: The array to inspect
49
49
  * @returns The number of elements in the array
50
50
  *
51
+ * @example Array.length([> 1, 2, 3, 4, 5]) == 5
51
52
  * @since v0.1.0
52
53
  */
53
54
  @disableGC
@@ -145,6 +146,7 @@ export let rec init /*: (Number, Number -> a) -> Array<a>*/ =
145
146
  * @param index: The index to access
146
147
  * @param array: The array to access
147
148
  * @returns The element from the array
149
+ * @example Array.get(1,[> 1, 2, 3, 4, 5]) == 2
148
150
  *
149
151
  * @since v0.1.0
150
152
  * @history v0.2.0: Argument order changed to data-last
@@ -162,6 +164,7 @@ export let get = (index, array) => {
162
164
  * @param index: The index to update
163
165
  * @param value: The value to store
164
166
  * @param array: The array to update
167
+ * @example Array.set(1, 9, [> 1, 2, 3, 4, 5]) == [> 1, 9, 3, 4, 5]
165
168
  *
166
169
  * @since v0.1.0
167
170
  * @history v0.2.0: Argument order changed to data-last
@@ -177,6 +180,7 @@ export let set = (index, value, array) => {
177
180
  * @param array1: The array containing elements to appear first
178
181
  * @param array2: The array containing elements to appear second
179
182
  * @returns The new array containing elements from `array1` followed by elements from `array2`
183
+ * @example Array.append([> 1, 2], [> 3, 4, 5]) == [> 1, 2, 3, 4, 5]
180
184
  *
181
185
  * @since v0.1.0
182
186
  */
@@ -199,6 +203,7 @@ export let append = (array1, array2) => {
199
203
  *
200
204
  * @param arrays: A list containing all arrays to combine
201
205
  * @returns The new array
206
+ * @example Array.concat([[> 1, 2], [> 3, 4], [> 5, 6]]) == [> 1, 2, 3, 4, 5, 6]
202
207
  *
203
208
  * @since v0.1.0
204
209
  */
@@ -358,6 +363,32 @@ export let reduce = (fn, initial, array) => {
358
363
  acc
359
364
  }
360
365
 
366
+ /**
367
+ * Combines all elements of an array using a reducer function,
368
+ * starting from the "end", or right side, of the array.
369
+ *
370
+ * In `Array.reduceRight(fn, initial, array)`, `fn` is called with
371
+ * each element of the array and an accumulator, and returns
372
+ * a new accumulator. The final value is the last accumulator
373
+ * returned. The accumulator starts with value `initial`.
374
+ *
375
+ * @param fn: The reducer function to call on each element, where the value returned will be the next accumulator value
376
+ * @param initial: The initial value to use for the accumulator on the first iteration
377
+ * @param array: The array to iterate
378
+ * @returns The final accumulator returned from `fn`
379
+ *
380
+ * @example Array.reduceRight((a, b) => b ++ a, "", [> "baz", "bar", "foo"]) // "foobarbaz"
381
+ *
382
+ * @since v0.5.3
383
+ */
384
+ export let reduceRight = (fn, initial, array) => {
385
+ let mut acc = initial
386
+ for (let mut i = length(array) - 1; i >= 0; i -= 1) {
387
+ acc = fn(array[i], acc)
388
+ }
389
+ acc
390
+ }
391
+
361
392
  /**
362
393
  * Combines all elements of an array using a reducer function,
363
394
  * starting from the "head", or left side, of the array.
@@ -555,7 +586,7 @@ export let fromList = list => {
555
586
  * @since v0.2.0
556
587
  */
557
588
  export let contains = (search, array) => {
558
- // TODO: This should use recursion when we can pattern match arrays
589
+ // TODO(#189): This should be rewritten to use recursion and pattern matching
559
590
  let len = length(array)
560
591
  let mut found = false
561
592
  for (let mut index = 0; !found && index < len; index += 1) {
@@ -787,6 +818,35 @@ export let zip = (array1: Array<a>, array2: Array<b>) => {
787
818
  }
788
819
  }
789
820
 
821
+ /**
822
+ * Produces a new array filled with elements defined by applying a function on
823
+ * pairs from both given arrays. The first element will contain the result of
824
+ * applying the function to the first elements of each array, the second element
825
+ * will contain the result of applying the function to the second elements of
826
+ * each array, and so on.
827
+ *
828
+ * Calling this function with arrays of different sizes will cause the returned
829
+ * array to have the length of the smaller array.
830
+ *
831
+ * @param fn: The function to apply to pairs of elements
832
+ * @param array1: The array whose elements will each be passed to the function as the first argument
833
+ * @param array2: The array whose elements will each be passed to the function as the second argument
834
+ * @returns The new array containing elements derived from applying the function to pairs of input array elements
835
+ *
836
+ * @example Array.zipWith((a, b) => a + b, [> 1, 2, 3], [> 4, 5, 6]) // [> 5, 7, 9]
837
+ * @example Array.zipWith((a, b) => a * b, [> 1, 2, 3], [> 4, 5]) // [> 4, 10]
838
+ *
839
+ * @since v0.5.3
840
+ */
841
+ export let zipWith = (fn, array1: Array<a>, array2: Array<b>) => {
842
+ let len1 = length(array1)
843
+ let len2 = length(array2)
844
+ let minLen = if (len1 > len2) len2 else len1
845
+ init(minLen, index => {
846
+ fn(array1[index], array2[index])
847
+ })
848
+ }
849
+
790
850
  /**
791
851
  * Produces two arrays by splitting apart an array of tuples.
792
852
  *
package/array.md CHANGED
@@ -50,6 +50,12 @@ Returns:
50
50
  |----|-----------|
51
51
  |`Number`|The number of elements in the array|
52
52
 
53
+ Examples:
54
+
55
+ ```grain
56
+ Array.length([> 1, 2, 3, 4, 5]) == 5
57
+ ```
58
+
53
59
  ### Array.**make**
54
60
 
55
61
  <details disabled>
@@ -153,6 +159,12 @@ Returns:
153
159
  |----|-----------|
154
160
  |`a`|The element from the array|
155
161
 
162
+ Examples:
163
+
164
+ ```grain
165
+ Array.get(1,[> 1, 2, 3, 4, 5]) == 2
166
+ ```
167
+
156
168
  ### Array.**set**
157
169
 
158
170
  <details>
@@ -184,6 +196,12 @@ Parameters:
184
196
  |`value`|`a`|The value to store|
185
197
  |`array`|`Array<a>`|The array to update|
186
198
 
199
+ Examples:
200
+
201
+ ```grain
202
+ Array.set(1, 9, [> 1, 2, 3, 4, 5]) == [> 1, 9, 3, 4, 5]
203
+ ```
204
+
187
205
  ### Array.**append**
188
206
 
189
207
  <details disabled>
@@ -211,6 +229,12 @@ Returns:
211
229
  |----|-----------|
212
230
  |`Array<a>`|The new array containing elements from `array1` followed by elements from `array2`|
213
231
 
232
+ Examples:
233
+
234
+ ```grain
235
+ Array.append([> 1, 2], [> 3, 4, 5]) == [> 1, 2, 3, 4, 5]
236
+ ```
237
+
214
238
  ### Array.**concat**
215
239
 
216
240
  <details disabled>
@@ -237,6 +261,12 @@ Returns:
237
261
  |----|-----------|
238
262
  |`Array<a>`|The new array|
239
263
 
264
+ Examples:
265
+
266
+ ```grain
267
+ Array.concat([[> 1, 2], [> 3, 4], [> 5, 6]]) == [> 1, 2, 3, 4, 5, 6]
268
+ ```
269
+
240
270
  ### Array.**copy**
241
271
 
242
272
  <details disabled>
@@ -439,6 +469,45 @@ Examples:
439
469
  Array.reduce((a, b) => a + b, 0, [> 1, 2, 3]) // 6
440
470
  ```
441
471
 
472
+ ### Array.**reduceRight**
473
+
474
+ <details disabled>
475
+ <summary tabindex="-1">Added in <code>0.5.3</code></summary>
476
+ No other changes yet.
477
+ </details>
478
+
479
+ ```grain
480
+ reduceRight : (((a, b) -> b), b, Array<a>) -> b
481
+ ```
482
+
483
+ Combines all elements of an array using a reducer function,
484
+ starting from the "end", or right side, of the array.
485
+
486
+ In `Array.reduceRight(fn, initial, array)`, `fn` is called with
487
+ each element of the array and an accumulator, and returns
488
+ a new accumulator. The final value is the last accumulator
489
+ returned. The accumulator starts with value `initial`.
490
+
491
+ Parameters:
492
+
493
+ |param|type|description|
494
+ |-----|----|-----------|
495
+ |`fn`|`(a, b) -> b`|The reducer function to call on each element, where the value returned will be the next accumulator value|
496
+ |`initial`|`b`|The initial value to use for the accumulator on the first iteration|
497
+ |`array`|`Array<a>`|The array to iterate|
498
+
499
+ Returns:
500
+
501
+ |type|description|
502
+ |----|-----------|
503
+ |`b`|The final accumulator returned from `fn`|
504
+
505
+ Examples:
506
+
507
+ ```grain
508
+ Array.reduceRight((a, b) => b ++ a, "", [> "baz", "bar", "foo"]) // "foobarbaz"
509
+ ```
510
+
442
511
  ### Array.**reducei**
443
512
 
444
513
  <details disabled>
@@ -945,6 +1014,50 @@ Returns:
945
1014
  |----|-----------|
946
1015
  |`Array<(a, b)>`|The new array containing indexed pairs of `(a, b)`|
947
1016
 
1017
+ ### Array.**zipWith**
1018
+
1019
+ <details disabled>
1020
+ <summary tabindex="-1">Added in <code>0.5.3</code></summary>
1021
+ No other changes yet.
1022
+ </details>
1023
+
1024
+ ```grain
1025
+ zipWith : (((a, b) -> c), Array<a>, Array<b>) -> Array<c>
1026
+ ```
1027
+
1028
+ Produces a new array filled with elements defined by applying a function on
1029
+ pairs from both given arrays. The first element will contain the result of
1030
+ applying the function to the first elements of each array, the second element
1031
+ will contain the result of applying the function to the second elements of
1032
+ each array, and so on.
1033
+
1034
+ Calling this function with arrays of different sizes will cause the returned
1035
+ array to have the length of the smaller array.
1036
+
1037
+ Parameters:
1038
+
1039
+ |param|type|description|
1040
+ |-----|----|-----------|
1041
+ |`fn`|`(a, b) -> c`|The function to apply to pairs of elements|
1042
+ |`array1`|`Array<a>`|The array whose elements will each be passed to the function as the first argument|
1043
+ |`array2`|`Array<b>`|The array whose elements will each be passed to the function as the second argument|
1044
+
1045
+ Returns:
1046
+
1047
+ |type|description|
1048
+ |----|-----------|
1049
+ |`Array<c>`|The new array containing elements derived from applying the function to pairs of input array elements|
1050
+
1051
+ Examples:
1052
+
1053
+ ```grain
1054
+ Array.zipWith((a, b) => a + b, [> 1, 2, 3], [> 4, 5, 6]) // [> 5, 7, 9]
1055
+ ```
1056
+
1057
+ ```grain
1058
+ Array.zipWith((a, b) => a * b, [> 1, 2, 3], [> 4, 5]) // [> 4, 10]
1059
+ ```
1060
+
948
1061
  ### Array.**unzip**
949
1062
 
950
1063
  <details disabled>
package/bigint.md CHANGED
@@ -17,7 +17,7 @@ import BigInt from "bigint"
17
17
 
18
18
  Functions for converting between Numbers and the BigInt type.
19
19
 
20
- ### Bigint.**fromNumber**
20
+ ### BigInt.**fromNumber**
21
21
 
22
22
  <details disabled>
23
23
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -42,7 +42,7 @@ Returns:
42
42
  |----|-----------|
43
43
  |`BigInt`|The Number represented as a BigInt|
44
44
 
45
- ### Bigint.**toNumber**
45
+ ### BigInt.**toNumber**
46
46
 
47
47
  <details disabled>
48
48
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -71,7 +71,7 @@ Returns:
71
71
 
72
72
  Mathematical operations for BigInt values.
73
73
 
74
- ### Bigint.**incr**
74
+ ### BigInt.**incr**
75
75
 
76
76
  <details disabled>
77
77
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -96,7 +96,7 @@ Returns:
96
96
  |----|-----------|
97
97
  |`BigInt`|The incremented value|
98
98
 
99
- ### Bigint.**decr**
99
+ ### BigInt.**decr**
100
100
 
101
101
  <details disabled>
102
102
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -121,7 +121,7 @@ Returns:
121
121
  |----|-----------|
122
122
  |`BigInt`|The decremented value|
123
123
 
124
- ### Bigint.**neg**
124
+ ### BigInt.**neg**
125
125
 
126
126
  <details disabled>
127
127
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -146,7 +146,7 @@ Returns:
146
146
  |----|-----------|
147
147
  |`BigInt`|The negated operand|
148
148
 
149
- ### Bigint.**abs**
149
+ ### BigInt.**abs**
150
150
 
151
151
  <details disabled>
152
152
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -171,7 +171,7 @@ Returns:
171
171
  |----|-----------|
172
172
  |`BigInt`|The operand's absolute value|
173
173
 
174
- ### Bigint.**add**
174
+ ### BigInt.**add**
175
175
 
176
176
  <details disabled>
177
177
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -197,7 +197,7 @@ Returns:
197
197
  |----|-----------|
198
198
  |`BigInt`|The sum of the two operands|
199
199
 
200
- ### Bigint.**sub**
200
+ ### BigInt.**sub**
201
201
 
202
202
  <details disabled>
203
203
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -223,7 +223,7 @@ Returns:
223
223
  |----|-----------|
224
224
  |`BigInt`|The difference of the two operands|
225
225
 
226
- ### Bigint.**mul**
226
+ ### BigInt.**mul**
227
227
 
228
228
  <details disabled>
229
229
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -249,7 +249,7 @@ Returns:
249
249
  |----|-----------|
250
250
  |`BigInt`|The product of the two operands|
251
251
 
252
- ### Bigint.**div**
252
+ ### BigInt.**div**
253
253
 
254
254
  <details disabled>
255
255
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -276,7 +276,7 @@ Returns:
276
276
  |----|-----------|
277
277
  |`BigInt`|The quotient of its operands|
278
278
 
279
- ### Bigint.**rem**
279
+ ### BigInt.**rem**
280
280
 
281
281
  <details disabled>
282
282
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -303,7 +303,7 @@ Returns:
303
303
  |----|-----------|
304
304
  |`BigInt`|The remainder of its operands|
305
305
 
306
- ### Bigint.**quotRem**
306
+ ### BigInt.**quotRem**
307
307
 
308
308
  <details disabled>
309
309
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -329,7 +329,7 @@ Returns:
329
329
  |----|-----------|
330
330
  |`(BigInt, BigInt)`|The quotient and remainder of its operands|
331
331
 
332
- ### Bigint.**gcd**
332
+ ### BigInt.**gcd**
333
333
 
334
334
  <details disabled>
335
335
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -359,7 +359,7 @@ Returns:
359
359
 
360
360
  Functions for operating on bits of BigInt values.
361
361
 
362
- ### Bigint.**shl**
362
+ ### BigInt.**shl**
363
363
 
364
364
  <details disabled>
365
365
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -385,7 +385,7 @@ Returns:
385
385
  |----|-----------|
386
386
  |`BigInt`|The shifted value|
387
387
 
388
- ### Bigint.**shr**
388
+ ### BigInt.**shr**
389
389
 
390
390
  <details disabled>
391
391
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -415,7 +415,7 @@ Returns:
415
415
 
416
416
  Functions for comparing BigInt values.
417
417
 
418
- ### Bigint.**eqz**
418
+ ### BigInt.**eqz**
419
419
 
420
420
  <details disabled>
421
421
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -440,7 +440,7 @@ Returns:
440
440
  |----|-----------|
441
441
  |`Bool`|`true` if the first value is equal to zero or `false` otherwise|
442
442
 
443
- ### Bigint.**eq**
443
+ ### BigInt.**eq**
444
444
 
445
445
  <details disabled>
446
446
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -466,7 +466,7 @@ Returns:
466
466
  |----|-----------|
467
467
  |`Bool`|`true` if the first value is equal to the second value or `false` otherwise|
468
468
 
469
- ### Bigint.**ne**
469
+ ### BigInt.**ne**
470
470
 
471
471
  <details disabled>
472
472
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -492,7 +492,7 @@ Returns:
492
492
  |----|-----------|
493
493
  |`Bool`|`true` if the first value is not equal to the second value or `false` otherwise|
494
494
 
495
- ### Bigint.**lt**
495
+ ### BigInt.**lt**
496
496
 
497
497
  <details disabled>
498
498
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -518,7 +518,7 @@ Returns:
518
518
  |----|-----------|
519
519
  |`Bool`|`true` if the first value is less than the second value or `false` otherwise|
520
520
 
521
- ### Bigint.**lte**
521
+ ### BigInt.**lte**
522
522
 
523
523
  <details disabled>
524
524
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -544,7 +544,7 @@ Returns:
544
544
  |----|-----------|
545
545
  |`Bool`|`true` if the first value is less than or equal to the second value or `false` otherwise|
546
546
 
547
- ### Bigint.**gt**
547
+ ### BigInt.**gt**
548
548
 
549
549
  <details disabled>
550
550
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -570,7 +570,7 @@ Returns:
570
570
  |----|-----------|
571
571
  |`Bool`|`true` if the first value is greater than the second value or `false` otherwise|
572
572
 
573
- ### Bigint.**gte**
573
+ ### BigInt.**gte**
574
574
 
575
575
  <details disabled>
576
576
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -600,7 +600,7 @@ Returns:
600
600
 
601
601
  Boolean operations on the bits of BigInt values.
602
602
 
603
- ### Bigint.**lnot**
603
+ ### BigInt.**lnot**
604
604
 
605
605
  <details disabled>
606
606
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -625,7 +625,7 @@ Returns:
625
625
  |----|-----------|
626
626
  |`BigInt`|Containing the inverted bits of the given value|
627
627
 
628
- ### Bigint.**land**
628
+ ### BigInt.**land**
629
629
 
630
630
  <details disabled>
631
631
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -651,7 +651,7 @@ Returns:
651
651
  |----|-----------|
652
652
  |`BigInt`|Containing a `1` in each bit position for which the corresponding bits of both operands are `1`|
653
653
 
654
- ### Bigint.**lor**
654
+ ### BigInt.**lor**
655
655
 
656
656
  <details disabled>
657
657
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -677,7 +677,7 @@ Returns:
677
677
  |----|-----------|
678
678
  |`BigInt`|Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1`|
679
679
 
680
- ### Bigint.**lxor**
680
+ ### BigInt.**lxor**
681
681
 
682
682
  <details disabled>
683
683
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -703,7 +703,7 @@ Returns:
703
703
  |----|-----------|
704
704
  |`BigInt`|Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1`|
705
705
 
706
- ### Bigint.**clz**
706
+ ### BigInt.**clz**
707
707
 
708
708
  <details disabled>
709
709
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -729,7 +729,7 @@ Returns:
729
729
  |----|-----------|
730
730
  |`Int32`|The amount of leading zeros|
731
731
 
732
- ### Bigint.**ctz**
732
+ ### BigInt.**ctz**
733
733
 
734
734
  <details disabled>
735
735
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -754,7 +754,7 @@ Returns:
754
754
  |----|-----------|
755
755
  |`Int64`|The amount of trailing zeros|
756
756
 
757
- ### Bigint.**popcnt**
757
+ ### BigInt.**popcnt**
758
758
 
759
759
  <details disabled>
760
760
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
@@ -784,7 +784,7 @@ Returns:
784
784
 
785
785
  Other functions on BigInts.
786
786
 
787
- ### Bigint.**toString**
787
+ ### BigInt.**toString**
788
788
 
789
789
  <details disabled>
790
790
  <summary tabindex="-1">Added in <code>0.5.0</code></summary>
package/buffer.gr CHANGED
@@ -339,32 +339,34 @@ export let addBytesSlice =
339
339
  bytes: Bytes,
340
340
  buffer: Buffer,
341
341
  ) => {
342
- let (-) = WasmI32.sub
343
- let (<) = WasmI32.ltS
344
- let (>) = WasmI32.gtS
345
- let (>=) = WasmI32.geS
346
-
347
- // bounds check start
348
- let bytelen = WasmI32.load(WasmI32.fromGrain(bytes), 4n)
349
- let srcOff = coerceNumberToWasmI32(start)
350
- if (srcOff < 0n || srcOff >= bytelen) {
351
- throw Exception.IndexOutOfBounds
352
- }
342
+ if (length != 0) {
343
+ let (-) = WasmI32.sub
344
+ let (<) = WasmI32.ltS
345
+ let (>) = WasmI32.gtS
346
+ let (>=) = WasmI32.geS
347
+
348
+ // bounds check start
349
+ let bytelen = WasmI32.load(WasmI32.fromGrain(bytes), 4n)
350
+ let srcOff = coerceNumberToWasmI32(start)
351
+ if (srcOff < 0n || srcOff >= bytelen) {
352
+ throw Exception.IndexOutOfBounds
353
+ }
353
354
 
354
- // bounds check length
355
- let len = coerceNumberToWasmI32(length)
356
- if (len < 0n || len > bytelen - srcOff) {
357
- throw Exception.IndexOutOfBounds
358
- }
355
+ // bounds check length
356
+ let len = coerceNumberToWasmI32(length)
357
+ if (len < 0n || len > bytelen - srcOff) {
358
+ throw Exception.IndexOutOfBounds
359
+ }
359
360
 
360
- autogrow(length, buffer)
361
+ autogrow(length, buffer)
361
362
 
362
- let dstOff = coerceNumberToWasmI32(buffer.len)
363
- let src = WasmI32.fromGrain(bytes)
364
- let dst = WasmI32.fromGrain(buffer.data)
365
- appendBytes(srcOff, dstOff, len, src, dst)
363
+ let dstOff = coerceNumberToWasmI32(buffer.len)
364
+ let src = WasmI32.fromGrain(bytes)
365
+ let dst = WasmI32.fromGrain(buffer.data)
366
+ appendBytes(srcOff, dstOff, len, src, dst)
366
367
 
367
- buffer.len += length
368
+ buffer.len += length
369
+ }
368
370
  }
369
371
 
370
372
  /**
package/char.gr CHANGED
@@ -47,8 +47,8 @@ export let max = 0x10FFFF
47
47
  */
48
48
  export let isValid = charCode => {
49
49
  charCode >= min &&
50
- (charCode <= 0xD7FF || charCode >= 0xE000) &&
51
- charCode <= max
50
+ (charCode <= 0xD7FF || charCode >= 0xE000) &&
51
+ charCode <= max
52
52
  }
53
53
 
54
54
  /**