ic-mops 0.8.5 → 0.8.7

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 (99) hide show
  1. package/package.json +3 -1
  2. package/.mops/base@0.7.4/LICENSE +0 -208
  3. package/.mops/base@0.7.4/README.md +0 -64
  4. package/.mops/base@0.7.4/mops.toml +0 -5
  5. package/.mops/base@0.7.4/src/Array.mo +0 -686
  6. package/.mops/base@0.7.4/src/AssocList.mo +0 -203
  7. package/.mops/base@0.7.4/src/Blob.mo +0 -55
  8. package/.mops/base@0.7.4/src/Bool.mo +0 -44
  9. package/.mops/base@0.7.4/src/Buffer.mo +0 -1937
  10. package/.mops/base@0.7.4/src/CertifiedData.mo +0 -29
  11. package/.mops/base@0.7.4/src/Char.mo +0 -67
  12. package/.mops/base@0.7.4/src/Debug.mo +0 -15
  13. package/.mops/base@0.7.4/src/Deque.mo +0 -75
  14. package/.mops/base@0.7.4/src/Error.mo +0 -41
  15. package/.mops/base@0.7.4/src/ExperimentalCycles.mo +0 -51
  16. package/.mops/base@0.7.4/src/ExperimentalInternetComputer.mo +0 -36
  17. package/.mops/base@0.7.4/src/ExperimentalStableMemory.mo +0 -121
  18. package/.mops/base@0.7.4/src/Float.mo +0 -150
  19. package/.mops/base@0.7.4/src/Func.mo +0 -38
  20. package/.mops/base@0.7.4/src/Hash.mo +0 -83
  21. package/.mops/base@0.7.4/src/HashMap.mo +0 -229
  22. package/.mops/base@0.7.4/src/Heap.mo +0 -113
  23. package/.mops/base@0.7.4/src/Int.mo +0 -150
  24. package/.mops/base@0.7.4/src/Int16.mo +0 -159
  25. package/.mops/base@0.7.4/src/Int32.mo +0 -160
  26. package/.mops/base@0.7.4/src/Int64.mo +0 -161
  27. package/.mops/base@0.7.4/src/Int8.mo +0 -160
  28. package/.mops/base@0.7.4/src/Iter.mo +0 -220
  29. package/.mops/base@0.7.4/src/IterType.mo +0 -7
  30. package/.mops/base@0.7.4/src/List.mo +0 -433
  31. package/.mops/base@0.7.4/src/Nat.mo +0 -75
  32. package/.mops/base@0.7.4/src/Nat16.mo +0 -146
  33. package/.mops/base@0.7.4/src/Nat32.mo +0 -146
  34. package/.mops/base@0.7.4/src/Nat64.mo +0 -146
  35. package/.mops/base@0.7.4/src/Nat8.mo +0 -146
  36. package/.mops/base@0.7.4/src/None.mo +0 -19
  37. package/.mops/base@0.7.4/src/Option.mo +0 -160
  38. package/.mops/base@0.7.4/src/Order.mo +0 -46
  39. package/.mops/base@0.7.4/src/Prelude.mo +0 -33
  40. package/.mops/base@0.7.4/src/Principal.mo +0 -58
  41. package/.mops/base@0.7.4/src/RBTree.mo +0 -218
  42. package/.mops/base@0.7.4/src/Random.mo +0 -188
  43. package/.mops/base@0.7.4/src/Result.mo +0 -210
  44. package/.mops/base@0.7.4/src/Stack.mo +0 -40
  45. package/.mops/base@0.7.4/src/Text.mo +0 -615
  46. package/.mops/base@0.7.4/src/Time.mo +0 -37
  47. package/.mops/base@0.7.4/src/Trie.mo +0 -1200
  48. package/.mops/base@0.7.4/src/TrieMap.mo +0 -180
  49. package/.mops/base@0.7.4/src/TrieSet.mo +0 -97
  50. package/.mops/base@0.8.3/LICENSE +0 -208
  51. package/.mops/base@0.8.3/README.md +0 -64
  52. package/.mops/base@0.8.3/mops.toml +0 -6
  53. package/.mops/base@0.8.3/src/Array.mo +0 -717
  54. package/.mops/base@0.8.3/src/AssocList.mo +0 -404
  55. package/.mops/base@0.8.3/src/Blob.mo +0 -212
  56. package/.mops/base@0.8.3/src/Bool.mo +0 -44
  57. package/.mops/base@0.8.3/src/Buffer.mo +0 -2660
  58. package/.mops/base@0.8.3/src/CertifiedData.mo +0 -53
  59. package/.mops/base@0.8.3/src/Char.mo +0 -65
  60. package/.mops/base@0.8.3/src/Debug.mo +0 -56
  61. package/.mops/base@0.8.3/src/Deque.mo +0 -243
  62. package/.mops/base@0.8.3/src/Error.mo +0 -68
  63. package/.mops/base@0.8.3/src/ExperimentalCycles.mo +0 -151
  64. package/.mops/base@0.8.3/src/ExperimentalInternetComputer.mo +0 -60
  65. package/.mops/base@0.8.3/src/ExperimentalStableMemory.mo +0 -348
  66. package/.mops/base@0.8.3/src/Float.mo +0 -843
  67. package/.mops/base@0.8.3/src/Func.mo +0 -46
  68. package/.mops/base@0.8.3/src/Hash.mo +0 -82
  69. package/.mops/base@0.8.3/src/HashMap.mo +0 -457
  70. package/.mops/base@0.8.3/src/Heap.mo +0 -233
  71. package/.mops/base@0.8.3/src/Int.mo +0 -365
  72. package/.mops/base@0.8.3/src/Int16.mo +0 -521
  73. package/.mops/base@0.8.3/src/Int32.mo +0 -522
  74. package/.mops/base@0.8.3/src/Int64.mo +0 -522
  75. package/.mops/base@0.8.3/src/Int8.mo +0 -522
  76. package/.mops/base@0.8.3/src/Iter.mo +0 -227
  77. package/.mops/base@0.8.3/src/IterType.mo +0 -7
  78. package/.mops/base@0.8.3/src/List.mo +0 -930
  79. package/.mops/base@0.8.3/src/Nat.mo +0 -305
  80. package/.mops/base@0.8.3/src/Nat16.mo +0 -144
  81. package/.mops/base@0.8.3/src/Nat32.mo +0 -144
  82. package/.mops/base@0.8.3/src/Nat64.mo +0 -144
  83. package/.mops/base@0.8.3/src/Nat8.mo +0 -144
  84. package/.mops/base@0.8.3/src/None.mo +0 -19
  85. package/.mops/base@0.8.3/src/Option.mo +0 -154
  86. package/.mops/base@0.8.3/src/Order.mo +0 -46
  87. package/.mops/base@0.8.3/src/Prelude.mo +0 -33
  88. package/.mops/base@0.8.3/src/Principal.mo +0 -249
  89. package/.mops/base@0.8.3/src/RBTree.mo +0 -681
  90. package/.mops/base@0.8.3/src/Random.mo +0 -270
  91. package/.mops/base@0.8.3/src/Result.mo +0 -209
  92. package/.mops/base@0.8.3/src/Stack.mo +0 -93
  93. package/.mops/base@0.8.3/src/Text.mo +0 -761
  94. package/.mops/base@0.8.3/src/Time.mo +0 -36
  95. package/.mops/base@0.8.3/src/Timer.mo +0 -62
  96. package/.mops/base@0.8.3/src/Trie.mo +0 -1603
  97. package/.mops/base@0.8.3/src/TrieMap.mo +0 -392
  98. package/.mops/base@0.8.3/src/TrieSet.mo +0 -148
  99. package/network.txt +0 -1
@@ -1,144 +0,0 @@
1
- /// 64-bit unsigned integers with checked arithmetic
2
- ///
3
- /// Most operations are available as built-in operators (e.g. `1 + 1`).
4
- import Nat "Nat";
5
- import Prim "mo:⛔";
6
-
7
- module {
8
-
9
- /// 64-bit natural numbers.
10
- public type Nat64 = Prim.Types.Nat64;
11
-
12
- /// Conversion.
13
- public let toNat : Nat64 -> Nat = Prim.nat64ToNat;
14
-
15
- /// Conversion. Traps on overflow/underflow.
16
- public let fromNat : Nat -> Nat64 = Prim.natToNat64;
17
-
18
- /// Conversion. Wraps on overflow/underflow.
19
- public let fromIntWrap : Int -> Nat64 = Prim.intToNat64Wrap;
20
-
21
- /// Returns the Text representation of `x`.
22
- public func toText(x : Nat64) : Text {
23
- Nat.toText(toNat(x))
24
- };
25
-
26
- /// Returns the minimum of `x` and `y`.
27
- public func min(x : Nat64, y : Nat64) : Nat64 {
28
- if (x < y) { x } else { y }
29
- };
30
-
31
- /// Returns the maximum of `x` and `y`.
32
- public func max(x : Nat64, y : Nat64) : Nat64 {
33
- if (x < y) { y } else { x }
34
- };
35
-
36
- /// Returns `x == y`.
37
- public func equal(x : Nat64, y : Nat64) : Bool { x == y };
38
-
39
- /// Returns `x != y`.
40
- public func notEqual(x : Nat64, y : Nat64) : Bool { x != y };
41
-
42
- /// Returns `x < y`.
43
- public func less(x : Nat64, y : Nat64) : Bool { x < y };
44
-
45
- /// Returns `x <= y`.
46
- public func lessOrEqual(x : Nat64, y : Nat64) : Bool { x <= y };
47
-
48
- /// Returns `x > y`.
49
- public func greater(x : Nat64, y : Nat64) : Bool { x > y };
50
-
51
- /// Returns `x >= y`.
52
- public func greaterOrEqual(x : Nat64, y : Nat64) : Bool { x >= y };
53
-
54
- /// Returns the order of `x` and `y`.
55
- public func compare(x : Nat64, y : Nat64) : { #less; #equal; #greater } {
56
- if (x < y) { #less } else if (x == y) { #equal } else { #greater }
57
- };
58
-
59
- /// Returns the sum of `x` and `y`, `x + y`. Traps on overflow.
60
- public func add(x : Nat64, y : Nat64) : Nat64 { x + y };
61
-
62
- /// Returns the difference of `x` and `y`, `x - y`. Traps on underflow.
63
- public func sub(x : Nat64, y : Nat64) : Nat64 { x - y };
64
-
65
- /// Returns the product of `x` and `y`, `x * y`. Traps on overflow.
66
- public func mul(x : Nat64, y : Nat64) : Nat64 { x * y };
67
-
68
- /// Returns the division of `x by y`, `x / y`.
69
- /// Traps when `y` is zero.
70
- public func div(x : Nat64, y : Nat64) : Nat64 { x / y };
71
-
72
- /// Returns the remainder of `x` divided by `y`, `x % y`.
73
- /// Traps when `y` is zero.
74
- public func rem(x : Nat64, y : Nat64) : Nat64 { x % y };
75
-
76
- /// Returns `x` to the power of `y`, `x ** y`. Traps on overflow.
77
- public func pow(x : Nat64, y : Nat64) : Nat64 { x ** y };
78
-
79
- /// Returns the bitwise negation of `x`, `^x`.
80
- public func bitnot(x : Nat64) : Nat64 { ^x };
81
-
82
- /// Returns the bitwise and of `x` and `y`, `x & y`.
83
- public func bitand(x : Nat64, y : Nat64) : Nat64 { x & y };
84
-
85
- /// Returns the bitwise or of `x` and `y`, `x \| y`.
86
- public func bitor(x : Nat64, y : Nat64) : Nat64 { x | y };
87
-
88
- /// Returns the bitwise exclusive or of `x` and `y`, `x ^ y`.
89
- public func bitxor(x : Nat64, y : Nat64) : Nat64 { x ^ y };
90
-
91
- /// Returns the bitwise shift left of `x` by `y`, `x << y`.
92
- public func bitshiftLeft(x : Nat64, y : Nat64) : Nat64 { x << y };
93
-
94
- /// Returns the bitwise shift right of `x` by `y`, `x >> y`.
95
- public func bitshiftRight(x : Nat64, y : Nat64) : Nat64 { x >> y };
96
-
97
- /// Returns the bitwise rotate left of `x` by `y`, `x <<> y`.
98
- public func bitrotLeft(x : Nat64, y : Nat64) : Nat64 { x <<> y };
99
-
100
- /// Returns the bitwise rotate right of `x` by `y`, `x <>> y`.
101
- public func bitrotRight(x : Nat64, y : Nat64) : Nat64 { x <>> y };
102
-
103
- /// Returns the value of bit `p mod 64` in `x`, `(x & 2^(p mod 64)) == 2^(p mod 64)`.
104
- public func bittest(x : Nat64, p : Nat) : Bool {
105
- Prim.btstNat64(x, Prim.natToNat64(p))
106
- };
107
-
108
- /// Returns the value of setting bit `p mod 64` in `x` to `1`.
109
- public func bitset(x : Nat64, p : Nat) : Nat64 {
110
- x | (1 << Prim.natToNat64(p))
111
- };
112
-
113
- /// Returns the value of clearing bit `p mod 64` in `x` to `0`.
114
- public func bitclear(x : Nat64, p : Nat) : Nat64 {
115
- x & ^(1 << Prim.natToNat64(p))
116
- };
117
-
118
- /// Returns the value of flipping bit `p mod 64` in `x`.
119
- public func bitflip(x : Nat64, p : Nat) : Nat64 {
120
- x ^ (1 << Prim.natToNat64(p))
121
- };
122
-
123
- /// Returns the count of non-zero bits in `x`.
124
- public let bitcountNonZero : (x : Nat64) -> Nat64 = Prim.popcntNat64;
125
-
126
- /// Returns the count of leading zero bits in `x`.
127
- public let bitcountLeadingZero : (x : Nat64) -> Nat64 = Prim.clzNat64;
128
-
129
- /// Returns the count of trailing zero bits in `x`.
130
- public let bitcountTrailingZero : (x : Nat64) -> Nat64 = Prim.ctzNat64;
131
-
132
- /// Returns the sum of `x` and `y`, `x +% y`. Wraps on overflow.
133
- public func addWrap(x : Nat64, y : Nat64) : Nat64 { x +% y };
134
-
135
- /// Returns the difference of `x` and `y`, `x -% y`. Wraps on underflow.
136
- public func subWrap(x : Nat64, y : Nat64) : Nat64 { x -% y };
137
-
138
- /// Returns the product of `x` and `y`, `x *% y`. Wraps on overflow.
139
- public func mulWrap(x : Nat64, y : Nat64) : Nat64 { x *% y };
140
-
141
- /// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow.
142
- public func powWrap(x : Nat64, y : Nat64) : Nat64 { x **% y };
143
-
144
- }
@@ -1,144 +0,0 @@
1
- /// 8-bit unsigned integers with checked arithmetic
2
- ///
3
- /// Most operations are available as built-in operators (e.g. `1 + 1`).
4
- import Nat "Nat";
5
- import Prim "mo:⛔";
6
-
7
- module {
8
-
9
- /// 8-bit natural numbers.
10
- public type Nat8 = Prim.Types.Nat8;
11
-
12
- /// Conversion.
13
- public let toNat : Nat8 -> Nat = Prim.nat8ToNat;
14
-
15
- /// Conversion. Traps on overflow/underflow.
16
- public let fromNat : Nat -> Nat8 = Prim.natToNat8;
17
-
18
- /// Conversion. Wraps on overflow/underflow.
19
- public let fromIntWrap : Int -> Nat8 = Prim.intToNat8Wrap;
20
-
21
- /// Returns the Text representation of `x`.
22
- public func toText(x : Nat8) : Text {
23
- Nat.toText(toNat(x))
24
- };
25
-
26
- /// Returns the minimum of `x` and `y`.
27
- public func min(x : Nat8, y : Nat8) : Nat8 {
28
- if (x < y) { x } else { y }
29
- };
30
-
31
- /// Returns the maximum of `x` and `y`.
32
- public func max(x : Nat8, y : Nat8) : Nat8 {
33
- if (x < y) { y } else { x }
34
- };
35
-
36
- /// Returns `x == y`.
37
- public func equal(x : Nat8, y : Nat8) : Bool { x == y };
38
-
39
- /// Returns `x != y`.
40
- public func notEqual(x : Nat8, y : Nat8) : Bool { x != y };
41
-
42
- /// Returns `x < y`.
43
- public func less(x : Nat8, y : Nat8) : Bool { x < y };
44
-
45
- /// Returns `x <= y`.
46
- public func lessOrEqual(x : Nat8, y : Nat8) : Bool { x <= y };
47
-
48
- /// Returns `x > y`.
49
- public func greater(x : Nat8, y : Nat8) : Bool { x > y };
50
-
51
- /// Returns `x >= y`.
52
- public func greaterOrEqual(x : Nat8, y : Nat8) : Bool { x >= y };
53
-
54
- /// Returns the order of `x` and `y`.
55
- public func compare(x : Nat8, y : Nat8) : { #less; #equal; #greater } {
56
- if (x < y) { #less } else if (x == y) { #equal } else { #greater }
57
- };
58
-
59
- /// Returns the sum of `x` and `y`, `x + y`. Traps on overflow.
60
- public func add(x : Nat8, y : Nat8) : Nat8 { x + y };
61
-
62
- /// Returns the difference of `x` and `y`, `x - y`. Traps on underflow.
63
- public func sub(x : Nat8, y : Nat8) : Nat8 { x - y };
64
-
65
- /// Returns the product of `x` and `y`, `x * y`. Traps on overflow.
66
- public func mul(x : Nat8, y : Nat8) : Nat8 { x * y };
67
-
68
- /// Returns the division of `x by y`, `x / y`.
69
- /// Traps when `y` is zero.
70
- public func div(x : Nat8, y : Nat8) : Nat8 { x / y };
71
-
72
- /// Returns the remainder of `x` divided by `y`, `x % y`.
73
- /// Traps when `y` is zero.
74
- public func rem(x : Nat8, y : Nat8) : Nat8 { x % y };
75
-
76
- /// Returns `x` to the power of `y`, `x ** y`. Traps on overflow.
77
- public func pow(x : Nat8, y : Nat8) : Nat8 { x ** y };
78
-
79
- /// Returns the bitwise negation of `x`, `^x`.
80
- public func bitnot(x : Nat8) : Nat8 { ^x };
81
-
82
- /// Returns the bitwise and of `x` and `y`, `x & y`.
83
- public func bitand(x : Nat8, y : Nat8) : Nat8 { x & y };
84
-
85
- /// Returns the bitwise or of `x` and `y`, `x \| y`.
86
- public func bitor(x : Nat8, y : Nat8) : Nat8 { x | y };
87
-
88
- /// Returns the bitwise exclusive or of `x` and `y`, `x ^ y`.
89
- public func bitxor(x : Nat8, y : Nat8) : Nat8 { x ^ y };
90
-
91
- /// Returns the bitwise shift left of `x` by `y`, `x << y`.
92
- public func bitshiftLeft(x : Nat8, y : Nat8) : Nat8 { x << y };
93
-
94
- /// Returns the bitwise shift right of `x` by `y`, `x >> y`.
95
- public func bitshiftRight(x : Nat8, y : Nat8) : Nat8 { x >> y };
96
-
97
- /// Returns the bitwise rotate left of `x` by `y`, `x <<> y`.
98
- public func bitrotLeft(x : Nat8, y : Nat8) : Nat8 { x <<> y };
99
-
100
- /// Returns the bitwise rotate right of `x` by `y`, `x <>> y`.
101
- public func bitrotRight(x : Nat8, y : Nat8) : Nat8 { x <>> y };
102
-
103
- /// Returns the value of bit `p mod 8` in `x`, `(x & 2^(p mod 8)) == 2^(p mod 8)`.
104
- public func bittest(x : Nat8, p : Nat) : Bool {
105
- Prim.btstNat8(x, Prim.natToNat8(p))
106
- };
107
-
108
- /// Returns the value of setting bit `p mod 8` in `x` to `1`.
109
- public func bitset(x : Nat8, p : Nat) : Nat8 {
110
- x | (1 << Prim.natToNat8(p))
111
- };
112
-
113
- /// Returns the value of clearing bit `p mod 8` in `x` to `0`.
114
- public func bitclear(x : Nat8, p : Nat) : Nat8 {
115
- x & ^(1 << Prim.natToNat8(p))
116
- };
117
-
118
- /// Returns the value of flipping bit `p mod 8` in `x`.
119
- public func bitflip(x : Nat8, p : Nat) : Nat8 {
120
- x ^ (1 << Prim.natToNat8(p))
121
- };
122
-
123
- /// Returns the count of non-zero bits in `x`.
124
- public let bitcountNonZero : (x : Nat8) -> Nat8 = Prim.popcntNat8;
125
-
126
- /// Returns the count of leading zero bits in `x`.
127
- public let bitcountLeadingZero : (x : Nat8) -> Nat8 = Prim.clzNat8;
128
-
129
- /// Returns the count of trailing zero bits in `x`.
130
- public let bitcountTrailingZero : (x : Nat8) -> Nat8 = Prim.ctzNat8;
131
-
132
- /// Returns the sum of `x` and `y`, `x +% y`. Wraps on overflow.
133
- public func addWrap(x : Nat8, y : Nat8) : Nat8 { x +% y };
134
-
135
- /// Returns the difference of `x` and `y`, `x -% y`. Wraps on underflow.
136
- public func subWrap(x : Nat8, y : Nat8) : Nat8 { x -% y };
137
-
138
- /// Returns the product of `x` and `y`, `x *% y`. Wraps on overflow.
139
- public func mulWrap(x : Nat8, y : Nat8) : Nat8 { x *% y };
140
-
141
- /// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow.
142
- public func powWrap(x : Nat8, y : Nat8) : Nat8 { x **% y };
143
-
144
- }
@@ -1,19 +0,0 @@
1
- /// The absent value
2
- ///
3
- /// The `None` type represents a type with _no_ value.
4
- ///
5
- /// It is often used to type code that fails to return control (e.g. an infinite loop)
6
- /// or to designate impossible values (e.g. the type `?None` only contains `null`).
7
-
8
- import Prim "mo:⛔";
9
-
10
- module {
11
-
12
- /// The empty type. A subtype of all types.
13
- public type None = Prim.Types.None;
14
-
15
- /// Turns an absurd value into an arbitrary type.
16
- public let impossible : <A> None -> A = func<A>(x : None) : A {
17
- switch (x) {}
18
- }
19
- }
@@ -1,154 +0,0 @@
1
- /// Typesafe nulls
2
- ///
3
- /// Optional values can be seen as a typesafe `null`. A value of type `?Int` can
4
- /// be constructed with either `null` or `?42`. The simplest way to get at the
5
- /// contents of an optional is to use pattern matching:
6
- ///
7
- /// ```motoko
8
- /// let optionalInt1 : ?Int = ?42;
9
- /// let optionalInt2 : ?Int = null;
10
- ///
11
- /// let int1orZero : Int = switch optionalInt1 {
12
- /// case null 0;
13
- /// case (?int) int;
14
- /// };
15
- /// assert int1orZero == 42;
16
- ///
17
- /// let int2orZero : Int = switch optionalInt2 {
18
- /// case null 0;
19
- /// case (?int) int;
20
- /// };
21
- /// assert int2orZero == 0;
22
- /// ```
23
- ///
24
- /// The functions in this module capture some common operations when working
25
- /// with optionals that can be more succinct than using pattern matching.
26
-
27
- import P "Prelude";
28
-
29
- module {
30
-
31
- /// Unwraps an optional value, with a default value, i.e. `get(?x, d) = x` and
32
- /// `get(null, d) = d`.
33
- public func get<T>(x : ?T, default : T) : T = switch x {
34
- case null { default };
35
- case (?x_) { x_ }
36
- };
37
-
38
- /// Unwraps an optional value using a function, or returns the default, i.e.
39
- /// `option(?x, f, d) = f x` and `option(null, f, d) = d`.
40
- public func getMapped<A, B>(x : ?A, f : A -> B, default : B) : B = switch x {
41
- case null { default };
42
- case (?x_) { f(x_) }
43
- };
44
-
45
- /// Applies a function to the wrapped value. `null`'s are left untouched.
46
- /// ```motoko
47
- /// import Option "mo:base/Option";
48
- /// assert Option.map<Nat, Nat>(?42, func x = x + 1) == ?43;
49
- /// assert Option.map<Nat, Nat>(null, func x = x + 1) == null;
50
- /// ```
51
- public func map<A, B>(x : ?A, f : A -> B) : ?B = switch x {
52
- case null { null };
53
- case (?x_) { ?f(x_) }
54
- };
55
-
56
- /// Applies a function to the wrapped value, but discards the result. Use
57
- /// `iterate` if you're only interested in the side effect `f` produces.
58
- ///
59
- /// ```motoko
60
- /// import Option "mo:base/Option";
61
- /// var counter : Nat = 0;
62
- /// Option.iterate(?5, func (x : Nat) { counter += x });
63
- /// assert counter == 5;
64
- /// Option.iterate(null, func (x : Nat) { counter += x });
65
- /// assert counter == 5;
66
- /// ```
67
- public func iterate<A>(x : ?A, f : A -> ()) = switch x {
68
- case null {};
69
- case (?x_) { f(x_) }
70
- };
71
-
72
- /// Applies an optional function to an optional value. Returns `null` if at
73
- /// least one of the arguments is `null`.
74
- public func apply<A, B>(x : ?A, f : ?(A -> B)) : ?B {
75
- switch (f, x) {
76
- case (?f_, ?x_) {
77
- ?f_(x_)
78
- };
79
- case (_, _) {
80
- null
81
- }
82
- }
83
- };
84
-
85
- /// Applies a function to an optional value. Returns `null` if the argument is
86
- /// `null`, or the function returns `null`.
87
- public func chain<A, B>(x : ?A, f : A -> ?B) : ?B {
88
- switch (x) {
89
- case (?x_) {
90
- f(x_)
91
- };
92
- case (null) {
93
- null
94
- }
95
- }
96
- };
97
-
98
- /// Given an optional optional value, removes one layer of optionality.
99
- /// ```motoko
100
- /// import Option "mo:base/Option";
101
- /// assert Option.flatten(?(?(42))) == ?42;
102
- /// assert Option.flatten(?(null)) == null;
103
- /// assert Option.flatten(null) == null;
104
- /// ```
105
- public func flatten<A>(x : ??A) : ?A {
106
- chain<?A, A>(
107
- x,
108
- func(x_ : ?A) : ?A {
109
- x_
110
- }
111
- )
112
- };
113
-
114
- /// Creates an optional value from a definite value.
115
- /// ```motoko
116
- /// import Option "mo:base/Option";
117
- /// assert Option.make(42) == ?42;
118
- /// ```
119
- public func make<A>(x : A) : ?A = ?x;
120
-
121
- /// Returns true if the argument is not `null`, otherwise returns false.
122
- public func isSome(x : ?Any) : Bool = switch x {
123
- case null { false };
124
- case _ { true }
125
- };
126
-
127
- /// Returns true if the argument is `null`, otherwise returns false.
128
- public func isNull(x : ?Any) : Bool = switch x {
129
- case null { true };
130
- case _ { false }
131
- };
132
-
133
- /// Asserts that the value is not `null`; fails otherwise.
134
- /// @deprecated Option.assertSome will be removed soon; use an assert expression instead
135
- public func assertSome(x : ?Any) = switch x {
136
- case null { P.unreachable() };
137
- case _ {}
138
- };
139
-
140
- /// Asserts that the value _is_ `null`; fails otherwise.
141
- /// @deprecated Option.assertNull will be removed soon; use an assert expression instead
142
- public func assertNull(x : ?Any) = switch x {
143
- case null {};
144
- case _ { P.unreachable() }
145
- };
146
-
147
- /// Unwraps an optional value, i.e. `unwrap(?x) = x`.
148
- ///
149
- /// @deprecated Option.unwrap is unsafe and fails if the argument is null; it will be removed soon; use a `switch` or `do?` expression instead
150
- public func unwrap<T>(x : ?T) : T = switch x {
151
- case null { P.unreachable() };
152
- case (?x_) { x_ }
153
- }
154
- }
@@ -1,46 +0,0 @@
1
- /// Order
2
-
3
- module {
4
-
5
- /// A type to represent an order.
6
- public type Order = {
7
- #less;
8
- #equal;
9
- #greater
10
- };
11
-
12
- /// Check if an order is #less.
13
- public func isLess(order : Order) : Bool {
14
- switch order {
15
- case (#less) { true };
16
- case _ { false }
17
- }
18
- };
19
-
20
- /// Check if an order is #equal.
21
- public func isEqual(order : Order) : Bool {
22
- switch order {
23
- case (#equal) { true };
24
- case _ { false }
25
- }
26
- };
27
-
28
- /// Check if an order is #greater.
29
- public func isGreater(order : Order) : Bool {
30
- switch order {
31
- case (#greater) { true };
32
- case _ { false }
33
- }
34
- };
35
-
36
- /// Returns true if only if `o1` and `o2` are the same ordering.
37
- public func equal(o1 : Order, o2 : Order) : Bool {
38
- switch (o1, o2) {
39
- case (#less, #less) { true };
40
- case (#equal, #equal) { true };
41
- case (#greater, #greater) { true };
42
- case _ { false }
43
- }
44
- };
45
-
46
- }
@@ -1,33 +0,0 @@
1
- /// General utilities
2
- ///
3
- /// This prelude file proposes standard library features that _may_
4
- /// belong in the _language_ (compiler-internal) prelude sometime, after
5
- /// some further experience and discussion. Until then, they live here.
6
-
7
- import Debug "Debug";
8
-
9
- module {
10
-
11
- /// Not yet implemented
12
- ///
13
- /// Mark incomplete code with the `nyi` and `xxx` functions.
14
- ///
15
- /// Each have calls are well-typed in all typing contexts, which
16
- /// trap in all execution contexts.
17
- public func nyi() : None {
18
- Debug.trap("Prelude.nyi()")
19
- };
20
-
21
- public func xxx() : None {
22
- Debug.trap("Prelude.xxx()")
23
- };
24
-
25
- /// Mark unreachable code with the `unreachable` function.
26
- ///
27
- /// Calls are well-typed in all typing contexts, and they
28
- /// trap in all execution contexts.
29
- public func unreachable() : None {
30
- Debug.trap("Prelude.unreachable()")
31
- };
32
-
33
- }