@grain/stdlib 0.6.5 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.6](https://github.com/grain-lang/grain/compare/stdlib-v0.6.5...stdlib-v0.6.6) (2024-08-12)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **stdlib:** Synchronize Grain versions
9
+
3
10
  ## [0.6.5](https://github.com/grain-lang/grain/compare/stdlib-v0.6.4...stdlib-v0.6.5) (2024-07-31)
4
11
 
5
12
 
package/list.gr CHANGED
@@ -9,6 +9,10 @@
9
9
  */
10
10
  module List
11
11
 
12
+ from "runtime/unsafe/memory" include Memory
13
+ from "runtime/unsafe/wasmi32" include WasmI32
14
+ from "runtime/dataStructures" include DataStructures
15
+
12
16
  /**
13
17
  * Creates a new list of the specified length where each element is
14
18
  * initialized with the result of an initializer function. The initializer
@@ -842,6 +846,51 @@ provide let sub = (start, length, list) => {
842
846
  take(length, drop(start, list))
843
847
  }
844
848
 
849
+ // List.join helpers
850
+ @unsafe
851
+ let rec computeJoinSize = (sepSize: WasmI32, size: WasmI32, lst: List<String>) => {
852
+ use WasmI32.{ (+) }
853
+ use DataStructures.{ stringSize }
854
+ match (lst) {
855
+ [] => size,
856
+ [hd] => size + stringSize(WasmI32.fromGrain(hd)),
857
+ [hd, ...tl] => {
858
+ let size = size + stringSize(WasmI32.fromGrain(hd)) + sepSize
859
+ ignore(hd)
860
+ computeJoinSize(sepSize, size, tl)
861
+ },
862
+ }
863
+ }
864
+ @unsafe
865
+ let rec buildJoinedString = (
866
+ strPtr: WasmI32,
867
+ sepPtr: WasmI32,
868
+ sepSize: WasmI32,
869
+ offset: WasmI32,
870
+ lst: List<String>,
871
+ ) => {
872
+ use WasmI32.{ (+) }
873
+ use DataStructures.{ stringSize }
874
+ match (lst) {
875
+ [] => void,
876
+ // Last element
877
+ [hd] => {
878
+ let ptr = WasmI32.fromGrain(hd)
879
+ let size = stringSize(ptr)
880
+ Memory.copy(offset, ptr + 8n, size)
881
+ ignore(hd)
882
+ },
883
+ [hd, ...tl] => {
884
+ let ptr = WasmI32.fromGrain(hd)
885
+ let size = stringSize(ptr)
886
+ Memory.copy(offset, ptr + 8n, size)
887
+ ignore(hd)
888
+ let offset = offset + size
889
+ Memory.copy(offset, sepPtr, sepSize)
890
+ buildJoinedString(strPtr, sepPtr, sepSize, offset + sepSize, tl)
891
+ },
892
+ }
893
+ }
845
894
  /**
846
895
  * Combine the given list of strings into one string with the specified
847
896
  * separator inserted between each item.
@@ -852,25 +901,17 @@ provide let sub = (start, length, list) => {
852
901
  *
853
902
  * @since v0.4.0
854
903
  */
904
+ @unsafe
855
905
  provide let join = (separator: String, list: List<String>) => {
856
- let rec iter = (sep, acc, rem) => {
857
- match (rem) {
858
- [] => acc,
859
- [hd, ...tl] => {
860
- let newAcc = match (acc) {
861
- None => Some(hd),
862
- Some(s) => Some(hd ++ sep ++ s),
863
- }
864
- iter(sep, newAcc, tl)
865
- },
866
- }
867
- }
868
-
869
- // Reverse and reduce to take advantage of TCE
870
- match (iter(separator, None, reverse(list))) {
871
- None => "",
872
- Some(s) => s,
873
- }
906
+ use WasmI32.{ (+), (-), (<=) }
907
+ use DataStructures.{ allocateString, stringSize }
908
+ let sepPtr = WasmI32.fromGrain(separator)
909
+ let sepSize = stringSize(sepPtr)
910
+ let strSize = computeJoinSize(sepSize, 0n, list)
911
+ let newString = allocateString(strSize)
912
+ buildJoinedString(newString, sepPtr + 8n, sepSize, newString + 8n, list)
913
+ ignore(sepPtr)
914
+ return WasmI32.toGrain(newString): String
874
915
  }
875
916
 
876
917
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grain/stdlib",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "description": "The standard library for the Grain language.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://grain-lang.org",
package/uint16.gr CHANGED
@@ -2,6 +2,9 @@
2
2
  * Utilities for working with the Uint16 type.
3
3
  * @example from "uint16" include Uint16
4
4
  *
5
+ * @example 1uS
6
+ * @example 10uS
7
+ *
5
8
  * @since v0.6.0
6
9
  */
7
10
  module Uint16
@@ -33,6 +36,9 @@ provide { fromNumber, toNumber }
33
36
  * @param number: The value to convert
34
37
  * @returns The Int16 represented as a Uint16
35
38
  *
39
+ * @example Uint16.fromInt16(1uS) == 1uS
40
+ * @example Uint16.fromInt16(-1uS) == 65535uS
41
+ *
36
42
  * @since v0.6.0
37
43
  */
38
44
  @unsafe
@@ -49,6 +55,8 @@ provide let fromInt16 = (number: Int16) => {
49
55
  * @param value: The value to increment
50
56
  * @returns The incremented value
51
57
  *
58
+ * @example Uint16.incr(1uS) == 2uS
59
+ *
52
60
  * @since v0.6.0
53
61
  */
54
62
  @unsafe
@@ -65,6 +73,9 @@ provide let incr = (value: Uint16) => {
65
73
  * @param value: The value to decrement
66
74
  * @returns The decremented value
67
75
  *
76
+ * @example Uint16.decr(1uS) == 0uS
77
+ * @example Uint16.decr(0uS) == 65535uS
78
+ *
68
79
  * @since v0.6.0
69
80
  */
70
81
  @unsafe
@@ -82,6 +93,10 @@ provide let decr = (value: Uint16) => {
82
93
  * @param y: The second operand
83
94
  * @returns The sum of the two operands
84
95
  *
96
+ * @example
97
+ * use Uint16.{ (+) }
98
+ * assert 1uS + 1uS == 2uS
99
+ *
85
100
  * @since v0.6.0
86
101
  */
87
102
  @unsafe
@@ -103,6 +118,10 @@ provide let (+) = (x: Uint16, y: Uint16) => {
103
118
  * @param y: The second operand
104
119
  * @returns The difference of the two operands
105
120
  *
121
+ * @example
122
+ * use Uint16.{ (-) }
123
+ * assert 2uS - 1uS == 1uS
124
+ *
106
125
  * @since v0.6.0
107
126
  */
108
127
  @unsafe
@@ -121,6 +140,10 @@ provide let (-) = (x: Uint16, y: Uint16) => {
121
140
  * @param y: The second operand
122
141
  * @returns The product of the two operands
123
142
  *
143
+ * @example
144
+ * use Uint16.{ (*) }
145
+ * assert 2uS * 2uS == 4uS
146
+ *
124
147
  * @since v0.6.0
125
148
  */
126
149
  @unsafe
@@ -138,6 +161,10 @@ provide let (*) = (x: Uint16, y: Uint16) => {
138
161
  * @param y: The second operand
139
162
  * @returns The quotient of its operands
140
163
  *
164
+ * @example
165
+ * use Uint16.{ (/) }
166
+ * assert 5uS / 2uS == 2uS
167
+ *
141
168
  * @since v0.6.0
142
169
  */
143
170
  @unsafe
@@ -155,6 +182,8 @@ provide let (/) = (x: Uint16, y: Uint16) => {
155
182
  * @param y: The second operand
156
183
  * @returns The remainder of its operands
157
184
  *
185
+ * @example Uint16.rem(5uS, 2uS) == 1uS
186
+ *
158
187
  * @since v0.6.0
159
188
  */
160
189
  @unsafe
@@ -172,6 +201,10 @@ provide let rem = (x: Uint16, y: Uint16) => {
172
201
  * @param amount: The number of bits to shift by
173
202
  * @returns The shifted value
174
203
  *
204
+ * @example
205
+ * use Uint16.{ (<<) }
206
+ * assert (5uS << 1uS) == 10uS
207
+ *
175
208
  * @since v0.6.0
176
209
  */
177
210
  @unsafe
@@ -191,6 +224,10 @@ provide let (<<) = (value: Uint16, amount: Uint16) => {
191
224
  * @param amount: The amount to shift by
192
225
  * @returns The shifted value
193
226
  *
227
+ * @example
228
+ * use Uint16.{ (>>>) }
229
+ * assert (5uS >>> 1uS) == 2uS
230
+ *
194
231
  * @since v0.6.0
195
232
  */
196
233
  @unsafe
@@ -210,6 +247,10 @@ provide let (>>>) = (value: Uint16, amount: Uint16) => {
210
247
  * @param y: The second value
211
248
  * @returns `true` if the first value is equal to the second value or `false` otherwise
212
249
  *
250
+ * @example
251
+ * use Uint16.{ (==) }
252
+ * assert 1uS == 1uS
253
+ *
213
254
  * @since v0.6.0
214
255
  */
215
256
  @unsafe
@@ -226,6 +267,10 @@ provide let (==) = (x: Uint16, y: Uint16) => {
226
267
  * @param y: The second value
227
268
  * @returns `true` if the first value is not equal to the second value or `false` otherwise
228
269
  *
270
+ * @example
271
+ * use Uint16.{ (!=) }
272
+ * assert 1uS != 3uS
273
+ *
229
274
  * @since v0.6.0
230
275
  */
231
276
  @unsafe
@@ -242,6 +287,10 @@ provide let (!=) = (x: Uint16, y: Uint16) => {
242
287
  * @param y: The second value
243
288
  * @returns `true` if the first value is less than the second value or `false` otherwise
244
289
  *
290
+ * @example
291
+ * use Uint16.{ (<) }
292
+ * assert 1uS < 5uS
293
+ *
245
294
  * @since v0.6.0
246
295
  */
247
296
  @unsafe
@@ -258,6 +307,10 @@ provide let (<) = (x: Uint16, y: Uint16) => {
258
307
  * @param y: The second value
259
308
  * @returns `true` if the first value is greater than the second value or `false` otherwise
260
309
  *
310
+ * @example
311
+ * use Uint16.{ (>) }
312
+ * assert 4uS > 2uS
313
+ *
261
314
  * @since v0.6.0
262
315
  */
263
316
  @unsafe
@@ -274,6 +327,13 @@ provide let (>) = (x: Uint16, y: Uint16) => {
274
327
  * @param y: The second value
275
328
  * @returns `true` if the first value is less than or equal to the second value or `false` otherwise
276
329
  *
330
+ * @example
331
+ * use Uint16.{ (<=) }
332
+ * assert 1uS <= 2uS
333
+ * @example
334
+ * use Uint16.{ (<=) }
335
+ * assert 1uS <= 1uS
336
+ *
277
337
  * @since v0.6.0
278
338
  */
279
339
  @unsafe
@@ -290,6 +350,13 @@ provide let (<=) = (x: Uint16, y: Uint16) => {
290
350
  * @param y: The second value
291
351
  * @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
292
352
  *
353
+ * @example
354
+ * use Uint16.{ (>=) }
355
+ * assert 3uS >= 2uS
356
+ * @example
357
+ * use Uint16.{ (>=) }
358
+ * assert 1uS >= 1uS
359
+ *
293
360
  * @since v0.6.0
294
361
  */
295
362
  @unsafe
@@ -305,6 +372,8 @@ provide let (>=) = (x: Uint16, y: Uint16) => {
305
372
  * @param value: The given value
306
373
  * @returns Containing the inverted bits of the given value
307
374
  *
375
+ * @example Uint16.lnot(5uS) == 65530uS
376
+ *
308
377
  * @since v0.6.0
309
378
  */
310
379
  @unsafe
@@ -320,6 +389,10 @@ provide let lnot = (value: Uint16) => {
320
389
  * @param y: The second operand
321
390
  * @returns Containing a `1` in each bit position for which the corresponding bits of both operands are `1`
322
391
  *
392
+ * @example
393
+ * use Uint16.{ (&) }
394
+ * assert (3uS & 4uS) == 0uS
395
+ *
323
396
  * @since v0.6.0
324
397
  */
325
398
  @unsafe
@@ -338,6 +411,10 @@ provide let (&) = (x: Uint16, y: Uint16) => {
338
411
  * @param y: The second operand
339
412
  * @returns Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1`
340
413
  *
414
+ * @example
415
+ * use Uint16.{ (|) }
416
+ * assert (3uS | 4uS) == 7uS
417
+ *
341
418
  * @since v0.6.0
342
419
  */
343
420
  @unsafe
@@ -356,6 +433,10 @@ provide let (|) = (x: Uint16, y: Uint16) => {
356
433
  * @param y: The second operand
357
434
  * @returns Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1`
358
435
  *
436
+ * @example
437
+ * use Uint16.{ (^) }
438
+ * assert (3uS ^ 5uS) == 6uS
439
+ *
359
440
  * @since v0.6.0
360
441
  */
361
442
  @unsafe
package/uint16.md CHANGED
@@ -13,6 +13,14 @@ No other changes yet.
13
13
  from "uint16" include Uint16
14
14
  ```
15
15
 
16
+ ```grain
17
+ 1uS
18
+ ```
19
+
20
+ ```grain
21
+ 10uS
22
+ ```
23
+
16
24
  ## Values
17
25
 
18
26
  Functions and constants included in the Uint16 module.
@@ -92,6 +100,16 @@ Returns:
92
100
  |----|-----------|
93
101
  |`Uint16`|The Int16 represented as a Uint16|
94
102
 
103
+ Examples:
104
+
105
+ ```grain
106
+ Uint16.fromInt16(1uS) == 1uS
107
+ ```
108
+
109
+ ```grain
110
+ Uint16.fromInt16(-1uS) == 65535uS
111
+ ```
112
+
95
113
  ### Uint16.**incr**
96
114
 
97
115
  <details disabled>
@@ -117,6 +135,12 @@ Returns:
117
135
  |----|-----------|
118
136
  |`Uint16`|The incremented value|
119
137
 
138
+ Examples:
139
+
140
+ ```grain
141
+ Uint16.incr(1uS) == 2uS
142
+ ```
143
+
120
144
  ### Uint16.**decr**
121
145
 
122
146
  <details disabled>
@@ -142,6 +166,16 @@ Returns:
142
166
  |----|-----------|
143
167
  |`Uint16`|The decremented value|
144
168
 
169
+ Examples:
170
+
171
+ ```grain
172
+ Uint16.decr(1uS) == 0uS
173
+ ```
174
+
175
+ ```grain
176
+ Uint16.decr(0uS) == 65535uS
177
+ ```
178
+
145
179
  ### Uint16.**(+)**
146
180
 
147
181
  <details disabled>
@@ -168,6 +202,13 @@ Returns:
168
202
  |----|-----------|
169
203
  |`Uint16`|The sum of the two operands|
170
204
 
205
+ Examples:
206
+
207
+ ```grain
208
+ use Uint16.{ (+) }
209
+ assert 1uS + 1uS == 2uS
210
+ ```
211
+
171
212
  ### Uint16.**(-)**
172
213
 
173
214
  <details disabled>
@@ -194,6 +235,13 @@ Returns:
194
235
  |----|-----------|
195
236
  |`Uint16`|The difference of the two operands|
196
237
 
238
+ Examples:
239
+
240
+ ```grain
241
+ use Uint16.{ (-) }
242
+ assert 2uS - 1uS == 1uS
243
+ ```
244
+
197
245
  ### Uint16.**(*)**
198
246
 
199
247
  <details disabled>
@@ -220,6 +268,13 @@ Returns:
220
268
  |----|-----------|
221
269
  |`Uint16`|The product of the two operands|
222
270
 
271
+ Examples:
272
+
273
+ ```grain
274
+ use Uint16.{ (*) }
275
+ assert 2uS * 2uS == 4uS
276
+ ```
277
+
223
278
  ### Uint16.**(/)**
224
279
 
225
280
  <details disabled>
@@ -246,6 +301,13 @@ Returns:
246
301
  |----|-----------|
247
302
  |`Uint16`|The quotient of its operands|
248
303
 
304
+ Examples:
305
+
306
+ ```grain
307
+ use Uint16.{ (/) }
308
+ assert 5uS / 2uS == 2uS
309
+ ```
310
+
249
311
  ### Uint16.**rem**
250
312
 
251
313
  <details disabled>
@@ -272,6 +334,12 @@ Returns:
272
334
  |----|-----------|
273
335
  |`Uint16`|The remainder of its operands|
274
336
 
337
+ Examples:
338
+
339
+ ```grain
340
+ Uint16.rem(5uS, 2uS) == 1uS
341
+ ```
342
+
275
343
  ### Uint16.**(<<)**
276
344
 
277
345
  <details disabled>
@@ -298,6 +366,13 @@ Returns:
298
366
  |----|-----------|
299
367
  |`Uint16`|The shifted value|
300
368
 
369
+ Examples:
370
+
371
+ ```grain
372
+ use Uint16.{ (<<) }
373
+ assert (5uS << 1uS) == 10uS
374
+ ```
375
+
301
376
  ### Uint16.**(>>>)**
302
377
 
303
378
  <details disabled>
@@ -324,6 +399,13 @@ Returns:
324
399
  |----|-----------|
325
400
  |`Uint16`|The shifted value|
326
401
 
402
+ Examples:
403
+
404
+ ```grain
405
+ use Uint16.{ (>>>) }
406
+ assert (5uS >>> 1uS) == 2uS
407
+ ```
408
+
327
409
  ### Uint16.**(==)**
328
410
 
329
411
  <details disabled>
@@ -350,6 +432,13 @@ Returns:
350
432
  |----|-----------|
351
433
  |`Bool`|`true` if the first value is equal to the second value or `false` otherwise|
352
434
 
435
+ Examples:
436
+
437
+ ```grain
438
+ use Uint16.{ (==) }
439
+ assert 1uS == 1uS
440
+ ```
441
+
353
442
  ### Uint16.**(!=)**
354
443
 
355
444
  <details disabled>
@@ -376,6 +465,13 @@ Returns:
376
465
  |----|-----------|
377
466
  |`Bool`|`true` if the first value is not equal to the second value or `false` otherwise|
378
467
 
468
+ Examples:
469
+
470
+ ```grain
471
+ use Uint16.{ (!=) }
472
+ assert 1uS != 3uS
473
+ ```
474
+
379
475
  ### Uint16.**(<)**
380
476
 
381
477
  <details disabled>
@@ -402,6 +498,13 @@ Returns:
402
498
  |----|-----------|
403
499
  |`Bool`|`true` if the first value is less than the second value or `false` otherwise|
404
500
 
501
+ Examples:
502
+
503
+ ```grain
504
+ use Uint16.{ (<) }
505
+ assert 1uS < 5uS
506
+ ```
507
+
405
508
  ### Uint16.**(>)**
406
509
 
407
510
  <details disabled>
@@ -428,6 +531,13 @@ Returns:
428
531
  |----|-----------|
429
532
  |`Bool`|`true` if the first value is greater than the second value or `false` otherwise|
430
533
 
534
+ Examples:
535
+
536
+ ```grain
537
+ use Uint16.{ (>) }
538
+ assert 4uS > 2uS
539
+ ```
540
+
431
541
  ### Uint16.**(<=)**
432
542
 
433
543
  <details disabled>
@@ -454,6 +564,18 @@ Returns:
454
564
  |----|-----------|
455
565
  |`Bool`|`true` if the first value is less than or equal to the second value or `false` otherwise|
456
566
 
567
+ Examples:
568
+
569
+ ```grain
570
+ use Uint16.{ (<=) }
571
+ assert 1uS <= 2uS
572
+ ```
573
+
574
+ ```grain
575
+ use Uint16.{ (<=) }
576
+ assert 1uS <= 1uS
577
+ ```
578
+
457
579
  ### Uint16.**(>=)**
458
580
 
459
581
  <details disabled>
@@ -480,6 +602,18 @@ Returns:
480
602
  |----|-----------|
481
603
  |`Bool`|`true` if the first value is greater than or equal to the second value or `false` otherwise|
482
604
 
605
+ Examples:
606
+
607
+ ```grain
608
+ use Uint16.{ (>=) }
609
+ assert 3uS >= 2uS
610
+ ```
611
+
612
+ ```grain
613
+ use Uint16.{ (>=) }
614
+ assert 1uS >= 1uS
615
+ ```
616
+
483
617
  ### Uint16.**lnot**
484
618
 
485
619
  <details disabled>
@@ -505,6 +639,12 @@ Returns:
505
639
  |----|-----------|
506
640
  |`Uint16`|Containing the inverted bits of the given value|
507
641
 
642
+ Examples:
643
+
644
+ ```grain
645
+ Uint16.lnot(5uS) == 65530uS
646
+ ```
647
+
508
648
  ### Uint16.**(&)**
509
649
 
510
650
  <details disabled>
@@ -531,6 +671,13 @@ Returns:
531
671
  |----|-----------|
532
672
  |`Uint16`|Containing a `1` in each bit position for which the corresponding bits of both operands are `1`|
533
673
 
674
+ Examples:
675
+
676
+ ```grain
677
+ use Uint16.{ (&) }
678
+ assert (3uS & 4uS) == 0uS
679
+ ```
680
+
534
681
  ### Uint16.**(|)**
535
682
 
536
683
  <details disabled>
@@ -557,6 +704,13 @@ Returns:
557
704
  |----|-----------|
558
705
  |`Uint16`|Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1`|
559
706
 
707
+ Examples:
708
+
709
+ ```grain
710
+ use Uint16.{ (|) }
711
+ assert (3uS | 4uS) == 7uS
712
+ ```
713
+
560
714
  ### Uint16.**(^)**
561
715
 
562
716
  <details disabled>
@@ -583,3 +737,10 @@ Returns:
583
737
  |----|-----------|
584
738
  |`Uint16`|Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1`|
585
739
 
740
+ Examples:
741
+
742
+ ```grain
743
+ use Uint16.{ (^) }
744
+ assert (3uS ^ 5uS) == 6uS
745
+ ```
746
+
package/uint8.gr CHANGED
@@ -2,6 +2,9 @@
2
2
  * Utilities for working with the Uint8 type.
3
3
  * @example from "uint8" include Uint8
4
4
  *
5
+ * @example 1us
6
+ * @example 10us
7
+ *
5
8
  * @since v0.6.0
6
9
  */
7
10
  module Uint8
@@ -33,6 +36,9 @@ provide { fromNumber, toNumber }
33
36
  * @param number: The value to convert
34
37
  * @returns The Int8 represented as a Uint8
35
38
  *
39
+ * @example Uint8.fromInt8(1s) == 1us
40
+ * @example Uint8.fromInt8(-1s) == 255us
41
+ *
36
42
  * @since v0.6.0
37
43
  */
38
44
  @unsafe
@@ -49,6 +55,8 @@ provide let fromInt8 = (number: Int8) => {
49
55
  * @param value: The value to increment
50
56
  * @returns The incremented value
51
57
  *
58
+ * @example Uint8.incr(1us) == 2us
59
+ *
52
60
  * @since v0.6.0
53
61
  */
54
62
  @unsafe
@@ -65,6 +73,9 @@ provide let incr = (value: Uint8) => {
65
73
  * @param value: The value to decrement
66
74
  * @returns The decremented value
67
75
  *
76
+ * @example Uint8.decr(1us) == 0us
77
+ * @example Uint8.decr(0us) == 255us
78
+ *
68
79
  * @since v0.6.0
69
80
  */
70
81
  @unsafe
@@ -82,6 +93,10 @@ provide let decr = (value: Uint8) => {
82
93
  * @param y: The second operand
83
94
  * @returns The sum of the two operands
84
95
  *
96
+ * @example
97
+ * use Uint8.{ (+) }
98
+ * assert 1us + 1us == 2us
99
+ *
85
100
  * @since v0.6.0
86
101
  */
87
102
  @unsafe
@@ -103,6 +118,10 @@ provide let (+) = (x: Uint8, y: Uint8) => {
103
118
  * @param y: The second operand
104
119
  * @returns The difference of the two operands
105
120
  *
121
+ * @example
122
+ * use Uint8.{ (-) }
123
+ * assert 2us - 1us == 1us
124
+ *
106
125
  * @since v0.6.0
107
126
  */
108
127
  @unsafe
@@ -121,6 +140,10 @@ provide let (-) = (x: Uint8, y: Uint8) => {
121
140
  * @param y: The second operand
122
141
  * @returns The product of the two operands
123
142
  *
143
+ * @example
144
+ * use Uint8.{ (*) }
145
+ * assert 2us * 2us == 4us
146
+ *
124
147
  * @since v0.6.0
125
148
  */
126
149
  @unsafe
@@ -138,6 +161,10 @@ provide let (*) = (x: Uint8, y: Uint8) => {
138
161
  * @param y: The second operand
139
162
  * @returns The quotient of its operands
140
163
  *
164
+ * @example
165
+ * use Uint8.{ (/) }
166
+ * assert 5us / 2us == 2us
167
+ *
141
168
  * @since v0.6.0
142
169
  */
143
170
  @unsafe
@@ -155,6 +182,8 @@ provide let (/) = (x: Uint8, y: Uint8) => {
155
182
  * @param y: The second operand
156
183
  * @returns The remainder of its operands
157
184
  *
185
+ * @example Uint8.rem(5us, 2us) == 1us
186
+ *
158
187
  * @since v0.6.0
159
188
  */
160
189
  @unsafe
@@ -172,6 +201,10 @@ provide let rem = (x: Uint8, y: Uint8) => {
172
201
  * @param amount: The number of bits to shift by
173
202
  * @returns The shifted value
174
203
  *
204
+ * @example
205
+ * use Uint8.{ (<<) }
206
+ * assert (5us << 1us) == 10us
207
+ *
175
208
  * @since v0.6.0
176
209
  */
177
210
  @unsafe
@@ -191,6 +224,10 @@ provide let (<<) = (value: Uint8, amount: Uint8) => {
191
224
  * @param amount: The amount to shift by
192
225
  * @returns The shifted value
193
226
  *
227
+ * @example
228
+ * use Uint8.{ (>>>) }
229
+ * assert (5us >>> 1us) == 2us
230
+ *
194
231
  * @since v0.6.0
195
232
  */
196
233
  @unsafe
@@ -210,6 +247,10 @@ provide let (>>>) = (value: Uint8, amount: Uint8) => {
210
247
  * @param y: The second value
211
248
  * @returns `true` if the first value is equal to the second value or `false` otherwise
212
249
  *
250
+ * @example
251
+ * use Uint8.{ (==) }
252
+ * assert 1us == 1us
253
+ *
213
254
  * @since v0.6.0
214
255
  */
215
256
  @unsafe
@@ -226,6 +267,10 @@ provide let (==) = (x: Uint8, y: Uint8) => {
226
267
  * @param y: The second value
227
268
  * @returns `true` if the first value is not equal to the second value or `false` otherwise
228
269
  *
270
+ * @example
271
+ * use Uint8.{ (!=) }
272
+ * assert 1us != 3us
273
+ *
229
274
  * @since v0.6.0
230
275
  */
231
276
  @unsafe
@@ -242,6 +287,10 @@ provide let (!=) = (x: Uint8, y: Uint8) => {
242
287
  * @param y: The second value
243
288
  * @returns `true` if the first value is less than the second value or `false` otherwise
244
289
  *
290
+ * @example
291
+ * use Uint8.{ (<) }
292
+ * assert 1us < 5us
293
+ *
245
294
  * @since v0.6.0
246
295
  */
247
296
  @unsafe
@@ -258,6 +307,10 @@ provide let (<) = (x: Uint8, y: Uint8) => {
258
307
  * @param y: The second value
259
308
  * @returns `true` if the first value is greater than the second value or `false` otherwise
260
309
  *
310
+ * @example
311
+ * use Uint8.{ (>) }
312
+ * assert 4us > 2us
313
+ *
261
314
  * @since v0.6.0
262
315
  */
263
316
  @unsafe
@@ -274,6 +327,13 @@ provide let (>) = (x: Uint8, y: Uint8) => {
274
327
  * @param y: The second value
275
328
  * @returns `true` if the first value is less than or equal to the second value or `false` otherwise
276
329
  *
330
+ * @example
331
+ * use Uint8.{ (<=) }
332
+ * assert 1us <= 2us
333
+ * @example
334
+ * use Uint8.{ (<=) }
335
+ * assert 1us <= 1us
336
+ *
277
337
  * @since v0.6.0
278
338
  */
279
339
  @unsafe
@@ -290,6 +350,13 @@ provide let (<=) = (x: Uint8, y: Uint8) => {
290
350
  * @param y: The second value
291
351
  * @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
292
352
  *
353
+ * @example
354
+ * use Uint8.{ (>=) }
355
+ * assert 3us >= 2us
356
+ * @example
357
+ * use Uint8.{ (>=) }
358
+ * assert 1us >= 1us
359
+ *
293
360
  * @since v0.6.0
294
361
  */
295
362
  @unsafe
@@ -305,6 +372,8 @@ provide let (>=) = (x: Uint8, y: Uint8) => {
305
372
  * @param value: The given value
306
373
  * @returns Containing the inverted bits of the given value
307
374
  *
375
+ * @example Uint8.lnot(5us) == 250us
376
+ *
308
377
  * @since v0.6.0
309
378
  */
310
379
  @unsafe
@@ -320,6 +389,10 @@ provide let lnot = (value: Uint8) => {
320
389
  * @param y: The second operand
321
390
  * @returns Containing a `1` in each bit position for which the corresponding bits of both operands are `1`
322
391
  *
392
+ * @example
393
+ * use Uint8.{ (&) }
394
+ * assert (3us & 4us) == 0us
395
+ *
323
396
  * @since v0.6.0
324
397
  */
325
398
  @unsafe
@@ -338,6 +411,10 @@ provide let (&) = (x: Uint8, y: Uint8) => {
338
411
  * @param y: The second operand
339
412
  * @returns Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1`
340
413
  *
414
+ * @example
415
+ * use Uint8.{ (|) }
416
+ * assert (3us | 4us) == 7us
417
+ *
341
418
  * @since v0.6.0
342
419
  */
343
420
  @unsafe
@@ -356,6 +433,10 @@ provide let (|) = (x: Uint8, y: Uint8) => {
356
433
  * @param y: The second operand
357
434
  * @returns Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1`
358
435
  *
436
+ * @example
437
+ * use Uint8.{ (^) }
438
+ * assert (3us ^ 5us) == 6us
439
+ *
359
440
  * @since v0.6.0
360
441
  */
361
442
  @unsafe
package/uint8.md CHANGED
@@ -13,6 +13,14 @@ No other changes yet.
13
13
  from "uint8" include Uint8
14
14
  ```
15
15
 
16
+ ```grain
17
+ 1us
18
+ ```
19
+
20
+ ```grain
21
+ 10us
22
+ ```
23
+
16
24
  ## Values
17
25
 
18
26
  Functions and constants included in the Uint8 module.
@@ -92,6 +100,16 @@ Returns:
92
100
  |----|-----------|
93
101
  |`Uint8`|The Int8 represented as a Uint8|
94
102
 
103
+ Examples:
104
+
105
+ ```grain
106
+ Uint8.fromInt8(1s) == 1us
107
+ ```
108
+
109
+ ```grain
110
+ Uint8.fromInt8(-1s) == 255us
111
+ ```
112
+
95
113
  ### Uint8.**incr**
96
114
 
97
115
  <details disabled>
@@ -117,6 +135,12 @@ Returns:
117
135
  |----|-----------|
118
136
  |`Uint8`|The incremented value|
119
137
 
138
+ Examples:
139
+
140
+ ```grain
141
+ Uint8.incr(1us) == 2us
142
+ ```
143
+
120
144
  ### Uint8.**decr**
121
145
 
122
146
  <details disabled>
@@ -142,6 +166,16 @@ Returns:
142
166
  |----|-----------|
143
167
  |`Uint8`|The decremented value|
144
168
 
169
+ Examples:
170
+
171
+ ```grain
172
+ Uint8.decr(1us) == 0us
173
+ ```
174
+
175
+ ```grain
176
+ Uint8.decr(0us) == 255us
177
+ ```
178
+
145
179
  ### Uint8.**(+)**
146
180
 
147
181
  <details disabled>
@@ -168,6 +202,13 @@ Returns:
168
202
  |----|-----------|
169
203
  |`Uint8`|The sum of the two operands|
170
204
 
205
+ Examples:
206
+
207
+ ```grain
208
+ use Uint8.{ (+) }
209
+ assert 1us + 1us == 2us
210
+ ```
211
+
171
212
  ### Uint8.**(-)**
172
213
 
173
214
  <details disabled>
@@ -194,6 +235,13 @@ Returns:
194
235
  |----|-----------|
195
236
  |`Uint8`|The difference of the two operands|
196
237
 
238
+ Examples:
239
+
240
+ ```grain
241
+ use Uint8.{ (-) }
242
+ assert 2us - 1us == 1us
243
+ ```
244
+
197
245
  ### Uint8.**(*)**
198
246
 
199
247
  <details disabled>
@@ -220,6 +268,13 @@ Returns:
220
268
  |----|-----------|
221
269
  |`Uint8`|The product of the two operands|
222
270
 
271
+ Examples:
272
+
273
+ ```grain
274
+ use Uint8.{ (*) }
275
+ assert 2us * 2us == 4us
276
+ ```
277
+
223
278
  ### Uint8.**(/)**
224
279
 
225
280
  <details disabled>
@@ -246,6 +301,13 @@ Returns:
246
301
  |----|-----------|
247
302
  |`Uint8`|The quotient of its operands|
248
303
 
304
+ Examples:
305
+
306
+ ```grain
307
+ use Uint8.{ (/) }
308
+ assert 5us / 2us == 2us
309
+ ```
310
+
249
311
  ### Uint8.**rem**
250
312
 
251
313
  <details disabled>
@@ -272,6 +334,12 @@ Returns:
272
334
  |----|-----------|
273
335
  |`Uint8`|The remainder of its operands|
274
336
 
337
+ Examples:
338
+
339
+ ```grain
340
+ Uint8.rem(5us, 2us) == 1us
341
+ ```
342
+
275
343
  ### Uint8.**(<<)**
276
344
 
277
345
  <details disabled>
@@ -298,6 +366,13 @@ Returns:
298
366
  |----|-----------|
299
367
  |`Uint8`|The shifted value|
300
368
 
369
+ Examples:
370
+
371
+ ```grain
372
+ use Uint8.{ (<<) }
373
+ assert (5us << 1us) == 10us
374
+ ```
375
+
301
376
  ### Uint8.**(>>>)**
302
377
 
303
378
  <details disabled>
@@ -324,6 +399,13 @@ Returns:
324
399
  |----|-----------|
325
400
  |`Uint8`|The shifted value|
326
401
 
402
+ Examples:
403
+
404
+ ```grain
405
+ use Uint8.{ (>>>) }
406
+ assert (5us >>> 1us) == 2us
407
+ ```
408
+
327
409
  ### Uint8.**(==)**
328
410
 
329
411
  <details disabled>
@@ -350,6 +432,13 @@ Returns:
350
432
  |----|-----------|
351
433
  |`Bool`|`true` if the first value is equal to the second value or `false` otherwise|
352
434
 
435
+ Examples:
436
+
437
+ ```grain
438
+ use Uint8.{ (==) }
439
+ assert 1us == 1us
440
+ ```
441
+
353
442
  ### Uint8.**(!=)**
354
443
 
355
444
  <details disabled>
@@ -376,6 +465,13 @@ Returns:
376
465
  |----|-----------|
377
466
  |`Bool`|`true` if the first value is not equal to the second value or `false` otherwise|
378
467
 
468
+ Examples:
469
+
470
+ ```grain
471
+ use Uint8.{ (!=) }
472
+ assert 1us != 3us
473
+ ```
474
+
379
475
  ### Uint8.**(<)**
380
476
 
381
477
  <details disabled>
@@ -402,6 +498,13 @@ Returns:
402
498
  |----|-----------|
403
499
  |`Bool`|`true` if the first value is less than the second value or `false` otherwise|
404
500
 
501
+ Examples:
502
+
503
+ ```grain
504
+ use Uint8.{ (<) }
505
+ assert 1us < 5us
506
+ ```
507
+
405
508
  ### Uint8.**(>)**
406
509
 
407
510
  <details disabled>
@@ -428,6 +531,13 @@ Returns:
428
531
  |----|-----------|
429
532
  |`Bool`|`true` if the first value is greater than the second value or `false` otherwise|
430
533
 
534
+ Examples:
535
+
536
+ ```grain
537
+ use Uint8.{ (>) }
538
+ assert 4us > 2us
539
+ ```
540
+
431
541
  ### Uint8.**(<=)**
432
542
 
433
543
  <details disabled>
@@ -454,6 +564,18 @@ Returns:
454
564
  |----|-----------|
455
565
  |`Bool`|`true` if the first value is less than or equal to the second value or `false` otherwise|
456
566
 
567
+ Examples:
568
+
569
+ ```grain
570
+ use Uint8.{ (<=) }
571
+ assert 1us <= 2us
572
+ ```
573
+
574
+ ```grain
575
+ use Uint8.{ (<=) }
576
+ assert 1us <= 1us
577
+ ```
578
+
457
579
  ### Uint8.**(>=)**
458
580
 
459
581
  <details disabled>
@@ -480,6 +602,18 @@ Returns:
480
602
  |----|-----------|
481
603
  |`Bool`|`true` if the first value is greater than or equal to the second value or `false` otherwise|
482
604
 
605
+ Examples:
606
+
607
+ ```grain
608
+ use Uint8.{ (>=) }
609
+ assert 3us >= 2us
610
+ ```
611
+
612
+ ```grain
613
+ use Uint8.{ (>=) }
614
+ assert 1us >= 1us
615
+ ```
616
+
483
617
  ### Uint8.**lnot**
484
618
 
485
619
  <details disabled>
@@ -505,6 +639,12 @@ Returns:
505
639
  |----|-----------|
506
640
  |`Uint8`|Containing the inverted bits of the given value|
507
641
 
642
+ Examples:
643
+
644
+ ```grain
645
+ Uint8.lnot(5us) == 250us
646
+ ```
647
+
508
648
  ### Uint8.**(&)**
509
649
 
510
650
  <details disabled>
@@ -531,6 +671,13 @@ Returns:
531
671
  |----|-----------|
532
672
  |`Uint8`|Containing a `1` in each bit position for which the corresponding bits of both operands are `1`|
533
673
 
674
+ Examples:
675
+
676
+ ```grain
677
+ use Uint8.{ (&) }
678
+ assert (3us & 4us) == 0us
679
+ ```
680
+
534
681
  ### Uint8.**(|)**
535
682
 
536
683
  <details disabled>
@@ -557,6 +704,13 @@ Returns:
557
704
  |----|-----------|
558
705
  |`Uint8`|Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1`|
559
706
 
707
+ Examples:
708
+
709
+ ```grain
710
+ use Uint8.{ (|) }
711
+ assert (3us | 4us) == 7us
712
+ ```
713
+
560
714
  ### Uint8.**(^)**
561
715
 
562
716
  <details disabled>
@@ -583,3 +737,10 @@ Returns:
583
737
  |----|-----------|
584
738
  |`Uint8`|Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1`|
585
739
 
740
+ Examples:
741
+
742
+ ```grain
743
+ use Uint8.{ (^) }
744
+ assert (3us ^ 5us) == 6us
745
+ ```
746
+