@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/bytes.md CHANGED
@@ -10,12 +10,20 @@ No other changes yet.
10
10
  </details>
11
11
 
12
12
  ```grain
13
- import Bytes from "bytes"
13
+ from "bytes" include Bytes
14
+ ```
15
+
16
+ ```grain
17
+ b"\x00"
18
+ ```
19
+
20
+ ```grain
21
+ Bytes.make(1)
14
22
  ```
15
23
 
16
24
  ## Values
17
25
 
18
- Functions for working with the Bytes data type.
26
+ Functions and constants included in the Bytes module.
19
27
 
20
28
  ### Bytes.**make**
21
29
 
@@ -25,7 +33,7 @@ No other changes yet.
25
33
  </details>
26
34
 
27
35
  ```grain
28
- make : Number -> Bytes
36
+ make : (size: Number) => Bytes
29
37
  ```
30
38
 
31
39
  Creates a new byte sequence of the input size.
@@ -42,6 +50,16 @@ Returns:
42
50
  |----|-----------|
43
51
  |`Bytes`|The new byte sequence|
44
52
 
53
+ Examples:
54
+
55
+ ```grain
56
+ Bytes.make(0) == b"""
57
+ ```
58
+
59
+ ```grain
60
+ Bytes.make(1) == b"\x00"
61
+ ```
62
+
45
63
  ### Bytes.**empty**
46
64
 
47
65
  <details disabled>
@@ -55,6 +73,12 @@ empty : Bytes
55
73
 
56
74
  An empty byte sequence.
57
75
 
76
+ Examples:
77
+
78
+ ```grain
79
+ Bytes.empty == b""
80
+ ```
81
+
58
82
  ### Bytes.**fromString**
59
83
 
60
84
  <details disabled>
@@ -63,7 +87,7 @@ No other changes yet.
63
87
  </details>
64
88
 
65
89
  ```grain
66
- fromString : String -> Bytes
90
+ fromString : (string: String) => Bytes
67
91
  ```
68
92
 
69
93
  Creates a new byte sequence from the input string.
@@ -80,6 +104,12 @@ Returns:
80
104
  |----|-----------|
81
105
  |`Bytes`|The new byte sequence|
82
106
 
107
+ Examples:
108
+
109
+ ```grain
110
+ Bytes.fromString("\x00\x00") == b"\x00\x00"
111
+ ```
112
+
83
113
  ### Bytes.**toString**
84
114
 
85
115
  <details disabled>
@@ -88,7 +118,7 @@ No other changes yet.
88
118
  </details>
89
119
 
90
120
  ```grain
91
- toString : Bytes -> String
121
+ toString : (bytes: Bytes) => String
92
122
  ```
93
123
 
94
124
  Creates a new string from the input bytes.
@@ -105,6 +135,16 @@ Returns:
105
135
  |----|-----------|
106
136
  |`String`|The string representation of the bytes|
107
137
 
138
+ Examples:
139
+
140
+ ```grain
141
+ Bytes.toString(b"\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64") == "Hello World"
142
+ ```
143
+
144
+ ```grain
145
+ Bytes.toString(b"Hello World") == "Hello World"
146
+ ```
147
+
108
148
  ### Bytes.**length**
109
149
 
110
150
  <details disabled>
@@ -113,7 +153,7 @@ No other changes yet.
113
153
  </details>
114
154
 
115
155
  ```grain
116
- length : Bytes -> Number
156
+ length : (bytes: Bytes) => Number
117
157
  ```
118
158
 
119
159
  Returns the length of a byte sequence.
@@ -130,6 +170,16 @@ Returns:
130
170
  |----|-----------|
131
171
  |`Number`|The number of bytes|
132
172
 
173
+ Examples:
174
+
175
+ ```grain
176
+ Bytes.length(b"") == 0
177
+ ```
178
+
179
+ ```grain
180
+ Bytes.length(b"\x48") == 1
181
+ ```
182
+
133
183
  ### Bytes.**copy**
134
184
 
135
185
  <details disabled>
@@ -138,7 +188,7 @@ No other changes yet.
138
188
  </details>
139
189
 
140
190
  ```grain
141
- copy : Bytes -> Bytes
191
+ copy : (bytes: Bytes) => Bytes
142
192
  ```
143
193
 
144
194
  Creates a new byte sequence that contains the same bytes as the input byte sequence.
@@ -155,6 +205,12 @@ Returns:
155
205
  |----|-----------|
156
206
  |`Bytes`|The new byte sequence|
157
207
 
208
+ Examples:
209
+
210
+ ```grain
211
+ Bytes.copy(b"\x48") == b"\x48"
212
+ ```
213
+
158
214
  ### Bytes.**slice**
159
215
 
160
216
  <details disabled>
@@ -163,7 +219,7 @@ No other changes yet.
163
219
  </details>
164
220
 
165
221
  ```grain
166
- slice : (Number, Number, Bytes) -> Bytes
222
+ slice : (start: Number, length: Number, bytes: Bytes) => Bytes
167
223
  ```
168
224
 
169
225
  Returns a copy of a subset of the input byte sequence.
@@ -188,6 +244,14 @@ Throws:
188
244
 
189
245
  * When `start + length` is greater than the bytes size
190
246
 
247
+ Examples:
248
+
249
+ ```grain
250
+ assert Bytes.toString(
251
+ Bytes.slice(0, 5, b"\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64")
252
+ ) == "Hello"
253
+ ```
254
+
191
255
  ### Bytes.**resize**
192
256
 
193
257
  <details disabled>
@@ -196,7 +260,7 @@ No other changes yet.
196
260
  </details>
197
261
 
198
262
  ```grain
199
- resize : (Number, Number, Bytes) -> Bytes
263
+ resize : (left: Number, right: Number, bytes: Bytes) => Bytes
200
264
  ```
201
265
 
202
266
  Returns a copy of a byte sequence with bytes added or removed from the beginning and/or end.
@@ -223,6 +287,12 @@ Throws:
223
287
 
224
288
  * When the new size is negative
225
289
 
290
+ Examples:
291
+
292
+ ```grain
293
+ Bytes.length(Bytes.resize(0, 3, b"")) == 3
294
+ ```
295
+
226
296
  ### Bytes.**move**
227
297
 
228
298
  <details disabled>
@@ -231,7 +301,9 @@ No other changes yet.
231
301
  </details>
232
302
 
233
303
  ```grain
234
- move : (Number, Number, Number, Bytes, Bytes) -> Void
304
+ move :
305
+ (srcIndex: Number, dstIndex: Number, length: Number, src: Bytes, dst: Bytes) =>
306
+ Void
235
307
  ```
236
308
 
237
309
  Copies a range of bytes from a source byte sequence to a given location
@@ -243,7 +315,7 @@ Parameters:
243
315
  |-----|----|-----------|
244
316
  |`srcIndex`|`Number`|The starting index to copy bytes from|
245
317
  |`dstIndex`|`Number`|The starting index to copy bytes into|
246
- |`length`|`Number`|The amount of bytes to copy from the source buffer|
318
+ |`length`|`Number`|The amount of bytes to copy from the source byte sequence|
247
319
  |`src`|`Bytes`|The source byte sequence|
248
320
  |`dst`|`Bytes`|The destination byte sequence|
249
321
 
@@ -254,6 +326,14 @@ Throws:
254
326
  * When `srcIndex + length` is greater than the `src` bytes size
255
327
  * When the `dstIndex + length` is greater than the `dst` bytes size
256
328
 
329
+ Examples:
330
+
331
+ ```grain
332
+ let bytes = Bytes.make(5)
333
+ Bytes.move(0, 0, 5, b"\x48\x64\x6c\x6f\x20\x57\x6f\x72\x6c\x64", bytes)
334
+ assert Bytes.toString(bytes) == "Hello"
335
+ ```
336
+
257
337
  ### Bytes.**concat**
258
338
 
259
339
  <details disabled>
@@ -262,7 +342,7 @@ No other changes yet.
262
342
  </details>
263
343
 
264
344
  ```grain
265
- concat : (Bytes, Bytes) -> Bytes
345
+ concat : (bytes1: Bytes, bytes2: Bytes) => Bytes
266
346
  ```
267
347
 
268
348
  Creates a new byte sequence that contains the bytes of both byte sequences.
@@ -280,15 +360,30 @@ Returns:
280
360
  |----|-----------|
281
361
  |`Bytes`|The new byte sequence|
282
362
 
363
+ Examples:
364
+
365
+ ```grain
366
+ let helloBytes = Bytes.fromString("Hello ")
367
+ let worldBytes = Bytes.fromString("World")
368
+ assert Bytes.toString(Bytes.concat(helloBytes, worldBytes)) == "Hello World"
369
+ ```
370
+
283
371
  ### Bytes.**fill**
284
372
 
285
- <details disabled>
286
- <summary tabindex="-1">Added in <code>0.3.2</code></summary>
287
- No other changes yet.
373
+ <details>
374
+ <summary>Added in <code>0.3.2</code></summary>
375
+ <table>
376
+ <thead>
377
+ <tr><th>version</th><th>changes</th></tr>
378
+ </thead>
379
+ <tbody>
380
+ <tr><td><code>0.6.0</code></td><td>`value` argument type changed to `Uint8`</td></tr>
381
+ </tbody>
382
+ </table>
288
383
  </details>
289
384
 
290
385
  ```grain
291
- fill : (Int32, Bytes) -> Void
386
+ fill : (value: Uint8, bytes: Bytes) => Void
292
387
  ```
293
388
 
294
389
  Replaces all bytes in a byte sequnce with the new value provided.
@@ -297,9 +392,17 @@ Parameters:
297
392
 
298
393
  |param|type|description|
299
394
  |-----|----|-----------|
300
- |`value`|`Int32`|The value replacing each byte|
395
+ |`value`|`Uint8`|The value replacing each byte|
301
396
  |`bytes`|`Bytes`|The byte sequence to update|
302
397
 
398
+ Examples:
399
+
400
+ ```grain
401
+ let bytes = Bytes.make(5)
402
+ Bytes.fill(1us, bytes)
403
+ assert bytes == b"\x01\x01\x01\x01\x01"
404
+ ```
405
+
303
406
  ### Bytes.**clear**
304
407
 
305
408
  <details disabled>
@@ -308,7 +411,7 @@ No other changes yet.
308
411
  </details>
309
412
 
310
413
  ```grain
311
- clear : Bytes -> Void
414
+ clear : (bytes: Bytes) => Void
312
415
  ```
313
416
 
314
417
  Replaces all bytes in a byte sequence with zeroes.
@@ -319,19 +422,31 @@ Parameters:
319
422
  |-----|----|-----------|
320
423
  |`bytes`|`Bytes`|The byte sequence to clear|
321
424
 
322
- ## Binary operations on integers
425
+ Examples:
323
426
 
324
- Functions for encoding and decoding integers stored in a byte sequence.
325
-
326
- ### Bytes.**getInt8S**
427
+ ```grain
428
+ let bytes = Bytes.make(5)
429
+ Bytes.fill(1us, bytes)
430
+ Bytes.clear(bytes)
431
+ assert bytes == b"\x00\x00\x00\x00\x00"
432
+ ```
327
433
 
328
- <details disabled>
329
- <summary tabindex="-1">Added in <code>0.3.2</code></summary>
330
- No other changes yet.
434
+ ### Bytes.**getInt8**
435
+
436
+ <details>
437
+ <summary>Added in <code>0.6.0</code></summary>
438
+ <table>
439
+ <thead>
440
+ <tr><th>version</th><th>changes</th></tr>
441
+ </thead>
442
+ <tbody>
443
+ <tr><td><code>0.3.2</code></td><td>Originally called `getInt8S`, returning an `Int32`</td></tr>
444
+ </tbody>
445
+ </table>
331
446
  </details>
332
447
 
333
448
  ```grain
334
- getInt8S : (Number, Bytes) -> Int32
449
+ getInt8 : (index: Number, bytes: Bytes) => Int8
335
450
  ```
336
451
 
337
452
  Gets a signed 8-bit integer starting at the given byte index.
@@ -347,7 +462,7 @@ Returns:
347
462
 
348
463
  |type|description|
349
464
  |----|-----------|
350
- |`Int32`|A 32-bit integer representing a signed 8-bit integer that starts at the given index|
465
+ |`Int8`|A signed 8-bit integer that starts at the given index|
351
466
 
352
467
  Throws:
353
468
 
@@ -356,15 +471,73 @@ Throws:
356
471
  * When `index` is negative
357
472
  * When `index + 1` is greater than the bytes size
358
473
 
359
- ### Bytes.**getInt8U**
474
+ Examples:
360
475
 
361
- <details disabled>
362
- <summary tabindex="-1">Added in <code>0.3.2</code></summary>
363
- No other changes yet.
476
+ ```grain
477
+ let bytes = Bytes.make(1)
478
+ Bytes.setInt8(0, 1s, bytes)
479
+ assert Bytes.getInt8(0, bytes) == 1s
480
+ ```
481
+
482
+ ### Bytes.**setInt8**
483
+
484
+ <details>
485
+ <summary>Added in <code>0.3.2</code></summary>
486
+ <table>
487
+ <thead>
488
+ <tr><th>version</th><th>changes</th></tr>
489
+ </thead>
490
+ <tbody>
491
+ <tr><td><code>0.6.0</code></td><td>`value` argument type changed to `Int8`</td></tr>
492
+ </tbody>
493
+ </table>
364
494
  </details>
365
495
 
366
496
  ```grain
367
- getInt8U : (Number, Bytes) -> Int32
497
+ setInt8 : (index: Number, value: Int8, bytes: Bytes) => Void
498
+ ```
499
+
500
+ Sets a signed 8-bit integer starting at the given byte index.
501
+
502
+ Parameters:
503
+
504
+ |param|type|description|
505
+ |-----|----|-----------|
506
+ |`index`|`Number`|The byte index to update|
507
+ |`value`|`Int8`|The value to set|
508
+ |`bytes`|`Bytes`|The byte sequence to mutate|
509
+
510
+ Throws:
511
+
512
+ `IndexOutOfBounds`
513
+
514
+ * When `index` is negative
515
+ * When `index + 1` is greater than the bytes size
516
+
517
+ Examples:
518
+
519
+ ```grain
520
+ let bytes = Bytes.make(1)
521
+ Bytes.setInt8(0, 2s, bytes)
522
+ assert Bytes.getInt8(0, bytes) == 2s
523
+ ```
524
+
525
+ ### Bytes.**getUint8**
526
+
527
+ <details>
528
+ <summary>Added in <code>0.6.0</code></summary>
529
+ <table>
530
+ <thead>
531
+ <tr><th>version</th><th>changes</th></tr>
532
+ </thead>
533
+ <tbody>
534
+ <tr><td><code>0.3.2</code></td><td>Originally called `getInt8U`, returning an `Int32`</td></tr>
535
+ </tbody>
536
+ </table>
537
+ </details>
538
+
539
+ ```grain
540
+ getUint8 : (index: Number, bytes: Bytes) => Uint8
368
541
  ```
369
542
 
370
543
  Gets an unsigned 8-bit integer starting at the given byte index.
@@ -380,7 +553,7 @@ Returns:
380
553
 
381
554
  |type|description|
382
555
  |----|-----------|
383
- |`Int32`|A 32-bit integer representing an unsigned 8-bit integer that starts at the given index|
556
+ |`Uint8`|An unsigned 8-bit integer that starts at the given index|
384
557
 
385
558
  Throws:
386
559
 
@@ -389,25 +562,33 @@ Throws:
389
562
  * When `index` is negative
390
563
  * When `index + 1` is greater than the bytes size
391
564
 
392
- ### Bytes.**setInt8**
565
+ Examples:
566
+
567
+ ```grain
568
+ let bytes = Bytes.make(1)
569
+ Bytes.setUint8(0, 1us, bytes)
570
+ assert Bytes.getUint8(0, bytes) == 1us
571
+ ```
572
+
573
+ ### Bytes.**setUint8**
393
574
 
394
575
  <details disabled>
395
- <summary tabindex="-1">Added in <code>0.3.2</code></summary>
576
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
396
577
  No other changes yet.
397
578
  </details>
398
579
 
399
580
  ```grain
400
- setInt8 : (Number, Int32, Bytes) -> Void
581
+ setUint8 : (index: Number, value: Uint8, bytes: Bytes) => Void
401
582
  ```
402
583
 
403
- Sets a signed 8-bit integer starting at the given byte index.
584
+ Sets an unsigned 8-bit integer starting at the given byte index.
404
585
 
405
586
  Parameters:
406
587
 
407
588
  |param|type|description|
408
589
  |-----|----|-----------|
409
590
  |`index`|`Number`|The byte index to update|
410
- |`value`|`Int32`|The value to set|
591
+ |`value`|`Uint8`|The value to set|
411
592
  |`bytes`|`Bytes`|The byte sequence to mutate|
412
593
 
413
594
  Throws:
@@ -417,15 +598,30 @@ Throws:
417
598
  * When `index` is negative
418
599
  * When `index + 1` is greater than the bytes size
419
600
 
420
- ### Bytes.**getInt16S**
601
+ Examples:
421
602
 
422
- <details disabled>
423
- <summary tabindex="-1">Added in <code>0.3.2</code></summary>
424
- No other changes yet.
603
+ ```grain
604
+ let bytes = Bytes.make(2)
605
+ Bytes.setUint8(1, 2us, bytes)
606
+ assert Bytes.getUint8(1, bytes) == 2us
607
+ ```
608
+
609
+ ### Bytes.**getInt16**
610
+
611
+ <details>
612
+ <summary>Added in <code>0.6.0</code></summary>
613
+ <table>
614
+ <thead>
615
+ <tr><th>version</th><th>changes</th></tr>
616
+ </thead>
617
+ <tbody>
618
+ <tr><td><code>0.3.2</code></td><td>Originally called `getInt16S`, returning an `Int32`</td></tr>
619
+ </tbody>
620
+ </table>
425
621
  </details>
426
622
 
427
623
  ```grain
428
- getInt16S : (Number, Bytes) -> Int32
624
+ getInt16 : (index: Number, bytes: Bytes) => Int16
429
625
  ```
430
626
 
431
627
  Gets a signed 16-bit integer starting at the given byte index.
@@ -441,7 +637,7 @@ Returns:
441
637
 
442
638
  |type|description|
443
639
  |----|-----------|
444
- |`Int32`|A 32-bit integer representing a signed 16-bit integer that starts at the given index|
640
+ |`Int16`|A signed 16-bit integer that starts at the given index|
445
641
 
446
642
  Throws:
447
643
 
@@ -450,15 +646,73 @@ Throws:
450
646
  * When `index` is negative
451
647
  * When `index + 2` is greater than the bytes size
452
648
 
453
- ### Bytes.**getInt16U**
649
+ Examples:
454
650
 
455
- <details disabled>
456
- <summary tabindex="-1">Added in <code>0.3.2</code></summary>
457
- No other changes yet.
651
+ ```grain
652
+ let bytes = Bytes.make(2)
653
+ Bytes.setInt16(0, -2S, bytes)
654
+ assert Bytes.getInt16(0, bytes) == -2S
655
+ ```
656
+
657
+ ### Bytes.**setInt16**
658
+
659
+ <details>
660
+ <summary>Added in <code>0.3.2</code></summary>
661
+ <table>
662
+ <thead>
663
+ <tr><th>version</th><th>changes</th></tr>
664
+ </thead>
665
+ <tbody>
666
+ <tr><td><code>0.6.0</code></td><td>`value` argument type changed to `Int16`</td></tr>
667
+ </tbody>
668
+ </table>
669
+ </details>
670
+
671
+ ```grain
672
+ setInt16 : (index: Number, value: Int16, bytes: Bytes) => Void
673
+ ```
674
+
675
+ Sets a signed 16-bit integer starting at the given byte index.
676
+
677
+ Parameters:
678
+
679
+ |param|type|description|
680
+ |-----|----|-----------|
681
+ |`index`|`Number`|The byte index to update|
682
+ |`value`|`Int16`|The value to set|
683
+ |`bytes`|`Bytes`|The byte sequence to mutate|
684
+
685
+ Throws:
686
+
687
+ `IndexOutOfBounds`
688
+
689
+ * When `index` is negative
690
+ * When `index + 2` is greater than the bytes size
691
+
692
+ Examples:
693
+
694
+ ```grain
695
+ let bytes = Bytes.make(2)
696
+ Bytes.setInt16(0, -1S, bytes)
697
+ assert Bytes.getInt16(0, bytes) == -1S
698
+ ```
699
+
700
+ ### Bytes.**getUint16**
701
+
702
+ <details>
703
+ <summary>Added in <code>0.6.0</code></summary>
704
+ <table>
705
+ <thead>
706
+ <tr><th>version</th><th>changes</th></tr>
707
+ </thead>
708
+ <tbody>
709
+ <tr><td><code>0.3.2</code></td><td>Originally called `getInt16U`, returning an `Int32`</td></tr>
710
+ </tbody>
711
+ </table>
458
712
  </details>
459
713
 
460
714
  ```grain
461
- getInt16U : (Number, Bytes) -> Int32
715
+ getUint16 : (index: Number, bytes: Bytes) => Uint16
462
716
  ```
463
717
 
464
718
  Gets an unsigned 16-bit integer starting at the given byte index.
@@ -474,7 +728,7 @@ Returns:
474
728
 
475
729
  |type|description|
476
730
  |----|-----------|
477
- |`Int32`|A 32-bit integer representing an unsigned 16-bit integer that starts at the given index|
731
+ |`Uint16`|An unsigned 16-bit integer that starts at the given index|
478
732
 
479
733
  Throws:
480
734
 
@@ -483,25 +737,33 @@ Throws:
483
737
  * When `index` is negative
484
738
  * When `index + 2` is greater than the bytes size
485
739
 
486
- ### Bytes.**setInt16**
740
+ Examples:
741
+
742
+ ```grain
743
+ let bytes = Bytes.make(2)
744
+ Bytes.setUint16(0, 2uS, bytes)
745
+ assert Bytes.getUint16(0, bytes) == 2uS
746
+ ```
747
+
748
+ ### Bytes.**setUint16**
487
749
 
488
750
  <details disabled>
489
- <summary tabindex="-1">Added in <code>0.3.2</code></summary>
751
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
490
752
  No other changes yet.
491
753
  </details>
492
754
 
493
755
  ```grain
494
- setInt16 : (Number, Int32, Bytes) -> Void
756
+ setUint16 : (index: Number, value: Uint16, bytes: Bytes) => Void
495
757
  ```
496
758
 
497
- Sets a signed 16-bit integer starting at the given byte index.
759
+ Sets an unsigned 16-bit integer starting at the given byte index.
498
760
 
499
761
  Parameters:
500
762
 
501
763
  |param|type|description|
502
764
  |-----|----|-----------|
503
765
  |`index`|`Number`|The byte index to update|
504
- |`value`|`Int32`|The value to set|
766
+ |`value`|`Uint16`|The value to set|
505
767
  |`bytes`|`Bytes`|The byte sequence to mutate|
506
768
 
507
769
  Throws:
@@ -511,6 +773,14 @@ Throws:
511
773
  * When `index` is negative
512
774
  * When `index + 2` is greater than the bytes size
513
775
 
776
+ Examples:
777
+
778
+ ```grain
779
+ let bytes = Bytes.make(2)
780
+ Bytes.setUint16(0, 2uS, bytes)
781
+ assert Bytes.getUint16(0, bytes) == 2uS
782
+ ```
783
+
514
784
  ### Bytes.**getInt32**
515
785
 
516
786
  <details disabled>
@@ -519,7 +789,7 @@ No other changes yet.
519
789
  </details>
520
790
 
521
791
  ```grain
522
- getInt32 : (Number, Bytes) -> Int32
792
+ getInt32 : (index: Number, bytes: Bytes) => Int32
523
793
  ```
524
794
 
525
795
  Gets a signed 32-bit integer starting at the given byte index.
@@ -544,6 +814,14 @@ Throws:
544
814
  * When `index` is negative
545
815
  * When `index + 4` is greater than the bytes size
546
816
 
817
+ Examples:
818
+
819
+ ```grain
820
+ let bytes = Bytes.make(4)
821
+ Bytes.setInt32(0, 1l, bytes)
822
+ assert Bytes.getInt32(0, bytes) == 1l
823
+ ```
824
+
547
825
  ### Bytes.**setInt32**
548
826
 
549
827
  <details disabled>
@@ -552,7 +830,7 @@ No other changes yet.
552
830
  </details>
553
831
 
554
832
  ```grain
555
- setInt32 : (Number, Int32, Bytes) -> Void
833
+ setInt32 : (index: Number, value: Int32, bytes: Bytes) => Void
556
834
  ```
557
835
 
558
836
  Sets a signed 32-bit integer starting at the given byte index.
@@ -572,6 +850,91 @@ Throws:
572
850
  * When `index` is negative
573
851
  * When `index + 4` is greater than the bytes size
574
852
 
853
+ Examples:
854
+
855
+ ```grain
856
+ let bytes = Bytes.make(4)
857
+ Bytes.setInt32(0, 1l, bytes)
858
+ assert Bytes.getInt32(0, bytes) == 1l
859
+ ```
860
+
861
+ ### Bytes.**getUint32**
862
+
863
+ <details disabled>
864
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
865
+ No other changes yet.
866
+ </details>
867
+
868
+ ```grain
869
+ getUint32 : (index: Number, bytes: Bytes) => Uint32
870
+ ```
871
+
872
+ Gets an unsigned 32-bit integer starting at the given byte index.
873
+
874
+ Parameters:
875
+
876
+ |param|type|description|
877
+ |-----|----|-----------|
878
+ |`index`|`Number`|The byte index to access|
879
+ |`bytes`|`Bytes`|The byte sequence to access|
880
+
881
+ Returns:
882
+
883
+ |type|description|
884
+ |----|-----------|
885
+ |`Uint32`|An unsigned 32-bit integer that starts at the given index|
886
+
887
+ Throws:
888
+
889
+ `IndexOutOfBounds`
890
+
891
+ * When `index` is negative
892
+ * When `index + 4` is greater than the bytes size
893
+
894
+ Examples:
895
+
896
+ ```grain
897
+ let bytes = Bytes.make(4)
898
+ Bytes.setUint32(0, 1ul, bytes)
899
+ assert Bytes.getUint32(0, bytes) == 1ul
900
+ ```
901
+
902
+ ### Bytes.**setUint32**
903
+
904
+ <details disabled>
905
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
906
+ No other changes yet.
907
+ </details>
908
+
909
+ ```grain
910
+ setUint32 : (index: Number, value: Uint32, bytes: Bytes) => Void
911
+ ```
912
+
913
+ Sets an unsigned 32-bit integer starting at the given byte index.
914
+
915
+ Parameters:
916
+
917
+ |param|type|description|
918
+ |-----|----|-----------|
919
+ |`index`|`Number`|The byte index to update|
920
+ |`value`|`Uint32`|The value to set|
921
+ |`bytes`|`Bytes`|The byte sequence to mutate|
922
+
923
+ Throws:
924
+
925
+ `IndexOutOfBounds`
926
+
927
+ * When `index` is negative
928
+ * When `index + 4` is greater than the bytes size
929
+
930
+ Examples:
931
+
932
+ ```grain
933
+ let bytes = Bytes.make(4)
934
+ Bytes.setUint32(0, 1ul, bytes)
935
+ assert Bytes.getUint32(0, bytes) == 1ul
936
+ ```
937
+
575
938
  ### Bytes.**getFloat32**
576
939
 
577
940
  <details disabled>
@@ -580,7 +943,7 @@ No other changes yet.
580
943
  </details>
581
944
 
582
945
  ```grain
583
- getFloat32 : (Number, Bytes) -> Float32
946
+ getFloat32 : (index: Number, bytes: Bytes) => Float32
584
947
  ```
585
948
 
586
949
  Gets a 32-bit float starting at the given byte index.
@@ -605,6 +968,14 @@ Throws:
605
968
  * When `index` is negative
606
969
  * When `index + 4` is greater than the bytes size
607
970
 
971
+ Examples:
972
+
973
+ ```grain
974
+ let bytes = Bytes.make(4)
975
+ Bytes.setFloat32(0, 1.0f, bytes)
976
+ assert Bytes.getFloat32(0, bytes) == 1.0f
977
+ ```
978
+
608
979
  ### Bytes.**setFloat32**
609
980
 
610
981
  <details disabled>
@@ -613,7 +984,7 @@ No other changes yet.
613
984
  </details>
614
985
 
615
986
  ```grain
616
- setFloat32 : (Number, Float32, Bytes) -> Void
987
+ setFloat32 : (index: Number, value: Float32, bytes: Bytes) => Void
617
988
  ```
618
989
 
619
990
  Sets a 32-bit float starting at the given byte index.
@@ -633,6 +1004,14 @@ Throws:
633
1004
  * When `index` is negative
634
1005
  * When `index + 4` is greater than the bytes size
635
1006
 
1007
+ Examples:
1008
+
1009
+ ```grain
1010
+ let bytes = Bytes.make(4)
1011
+ Bytes.setFloat32(0, 1.0f, bytes)
1012
+ assert Bytes.getFloat32(0, bytes) == 1.0f
1013
+ ```
1014
+
636
1015
  ### Bytes.**getInt64**
637
1016
 
638
1017
  <details disabled>
@@ -641,7 +1020,7 @@ No other changes yet.
641
1020
  </details>
642
1021
 
643
1022
  ```grain
644
- getInt64 : (Number, Bytes) -> Int64
1023
+ getInt64 : (index: Number, bytes: Bytes) => Int64
645
1024
  ```
646
1025
 
647
1026
  Gets a signed 64-bit integer starting at the given byte index.
@@ -666,6 +1045,14 @@ Throws:
666
1045
  * When `index` is negative
667
1046
  * When `index + 8` is greater than the bytes size
668
1047
 
1048
+ Examples:
1049
+
1050
+ ```grain
1051
+ let bytes = Bytes.make(8)
1052
+ Bytes.setInt64(0, 1L, bytes)
1053
+ assert Bytes.getInt64(0, bytes) == 1L
1054
+ ```
1055
+
669
1056
  ### Bytes.**setInt64**
670
1057
 
671
1058
  <details disabled>
@@ -674,7 +1061,7 @@ No other changes yet.
674
1061
  </details>
675
1062
 
676
1063
  ```grain
677
- setInt64 : (Number, Int64, Bytes) -> Void
1064
+ setInt64 : (index: Number, value: Int64, bytes: Bytes) => Void
678
1065
  ```
679
1066
 
680
1067
  Sets a signed 64-bit integer starting at the given byte index.
@@ -694,6 +1081,91 @@ Throws:
694
1081
  * When `index` is negative
695
1082
  * When `index + 8` is greater than the bytes size
696
1083
 
1084
+ Examples:
1085
+
1086
+ ```grain
1087
+ let bytes = Bytes.make(8)
1088
+ Bytes.setInt64(0, 1L, bytes)
1089
+ assert Bytes.getInt64(0, bytes) == 1L
1090
+ ```
1091
+
1092
+ ### Bytes.**getUint64**
1093
+
1094
+ <details disabled>
1095
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
1096
+ No other changes yet.
1097
+ </details>
1098
+
1099
+ ```grain
1100
+ getUint64 : (index: Number, bytes: Bytes) => Uint64
1101
+ ```
1102
+
1103
+ Gets an unsigned 64-bit integer starting at the given byte index.
1104
+
1105
+ Parameters:
1106
+
1107
+ |param|type|description|
1108
+ |-----|----|-----------|
1109
+ |`index`|`Number`|The byte index to access|
1110
+ |`bytes`|`Bytes`|The byte sequence to access|
1111
+
1112
+ Returns:
1113
+
1114
+ |type|description|
1115
+ |----|-----------|
1116
+ |`Uint64`|An unsigned 64-bit integer that starts at the given index|
1117
+
1118
+ Throws:
1119
+
1120
+ `IndexOutOfBounds`
1121
+
1122
+ * When `index` is negative
1123
+ * When `index + 8` is greater than the bytes size
1124
+
1125
+ Examples:
1126
+
1127
+ ```grain
1128
+ let bytes = Bytes.make(8)
1129
+ Bytes.setUint64(0, 1uL, bytes)
1130
+ assert Bytes.getUint64(0, bytes) == 1uL
1131
+ ```
1132
+
1133
+ ### Bytes.**setUint64**
1134
+
1135
+ <details disabled>
1136
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
1137
+ No other changes yet.
1138
+ </details>
1139
+
1140
+ ```grain
1141
+ setUint64 : (index: Number, value: Uint64, bytes: Bytes) => Void
1142
+ ```
1143
+
1144
+ Sets an unsigned 64-bit integer starting at the given byte index.
1145
+
1146
+ Parameters:
1147
+
1148
+ |param|type|description|
1149
+ |-----|----|-----------|
1150
+ |`index`|`Number`|The byte index to update|
1151
+ |`value`|`Uint64`|The value to set|
1152
+ |`bytes`|`Bytes`|The byte sequence to mutate|
1153
+
1154
+ Throws:
1155
+
1156
+ `IndexOutOfBounds`
1157
+
1158
+ * When `index` is negative
1159
+ * When `index + 8` is greater than the bytes size
1160
+
1161
+ Examples:
1162
+
1163
+ ```grain
1164
+ let bytes = Bytes.make(8)
1165
+ Bytes.setUint64(0, 1uL, bytes)
1166
+ assert Bytes.getUint64(0, bytes) == 1uL
1167
+ ```
1168
+
697
1169
  ### Bytes.**getFloat64**
698
1170
 
699
1171
  <details disabled>
@@ -702,7 +1174,7 @@ No other changes yet.
702
1174
  </details>
703
1175
 
704
1176
  ```grain
705
- getFloat64 : (Number, Bytes) -> Float64
1177
+ getFloat64 : (index: Number, bytes: Bytes) => Float64
706
1178
  ```
707
1179
 
708
1180
  Gets a 64-bit float starting at the given byte index.
@@ -727,6 +1199,14 @@ Throws:
727
1199
  * When `index` is negative
728
1200
  * When `index + 8` is greater than the bytes size
729
1201
 
1202
+ Examples:
1203
+
1204
+ ```grain
1205
+ let bytes = Bytes.make(8)
1206
+ Bytes.setFloat64(0, 1.0d, bytes)
1207
+ assert Bytes.getFloat64(0, bytes) == 1.0d
1208
+ ```
1209
+
730
1210
  ### Bytes.**setFloat64**
731
1211
 
732
1212
  <details disabled>
@@ -735,7 +1215,7 @@ No other changes yet.
735
1215
  </details>
736
1216
 
737
1217
  ```grain
738
- setFloat64 : (Number, Float64, Bytes) -> Void
1218
+ setFloat64 : (index: Number, value: Float64, bytes: Bytes) => Void
739
1219
  ```
740
1220
 
741
1221
  Sets a 64-bit float starting at the given byte index.
@@ -755,3 +1235,11 @@ Throws:
755
1235
  * When `index` is negative
756
1236
  * When `index + 8` is greater than the bytes size
757
1237
 
1238
+ Examples:
1239
+
1240
+ ```grain
1241
+ let bytes = Bytes.make(8)
1242
+ Bytes.setFloat64(0, 1.0d, bytes)
1243
+ assert Bytes.getFloat64(0, bytes) == 1.0d
1244
+ ```
1245
+