@@ -40,7 +40,7 @@ module {
4040
4141 // / Unwraps an optional value using a function, or returns the default, i.e.
4242 // / `option(?x, f, d) = f x` and `option(null, f, d) = d`.
43- public func getMapped< A , B > (x : ?A , f : A -> B , default : B ) : B = switch x {
43+ public func getMapped< T , R > (x : ?T , f : T -> R , default : R ) : R = switch x {
4444 case null { default };
4545 case (?x_) { f(x_) }
4646 };
@@ -51,7 +51,7 @@ module {
5151 // / assert Option.map<Nat, Nat>(?42, func x = x + 1) == ?43;
5252 // / assert Option.map<Nat, Nat>(null, func x = x + 1) == null;
5353 // / ```
54- public func map< A , B > (x : ?A , f : A -> B ) : ?B = switch x {
54+ public func map< T , R > (x : ?T , f : T -> R ) : ?R = switch x {
5555 case null { null };
5656 case (?x_) { ?f(x_) }
5757 };
@@ -67,14 +67,14 @@ module {
6767 // / Option.forEach(null, func (x : Nat) { counter += x });
6868 // / assert counter == 5;
6969 // / ```
70- public func forEach< A > (x : ?A , f : A -> ()) = switch x {
70+ public func forEach< T > (x : ?T , f : T -> ()) = switch x {
7171 case null {};
7272 case (?x_) { f(x_) }
7373 };
7474
7575 // / Applies an optional function to an optional value. Returns `null` if at
7676 // / least one of the arguments is `null`.
77- public func apply< A , B > (x : ?A , f : ?(A -> B )) : ?B {
77+ public func apply< T , R > (x : ?T , f : ?(T -> R )) : ?R {
7878 switch (f, x) {
7979 case (?f_, ?x_) { ?f_(x_) };
8080 case (_, _) { null }
@@ -83,7 +83,7 @@ module {
8383
8484 // / Applies a function to an optional value. Returns `null` if the argument is
8585 // / `null`, or the function returns `null`.
86- public func chain< A , B > (x : ?A , f : A -> ?B ) : ?B {
86+ public func chain< T , R > (x : ?T , f : T -> ?R ) : ?R {
8787 switch (x) {
8888 case (?x_) { f(x_) };
8989 case (null ) { null }
@@ -97,16 +97,16 @@ module {
9797 // / assert Option.flatten(?(null)) == null;
9898 // / assert Option.flatten(null) == null;
9999 // / ```
100- public func flatten< A > (x : ??A ) : ?A {
101- chain< ?A , A > (x, func (x_ : ?A ) : ?A = x_)
100+ public func flatten< T > (x : ??T ) : ?T {
101+ chain< ?T , T > (x, func (x_ : ?T ) : ?T = x_)
102102 };
103103
104104 // / Creates an optional value from a definite value.
105105 // / ```motoko
106106 // / import Option "mo:core/Option";
107107 // / assert Option.some(42) == ?42;
108108 // / ```
109- public func some< A > (x : A ) : ?A = ?x;
109+ public func some< T > (x : T ) : ?T = ?x;
110110
111111 // / Returns true if the argument is not `null`, otherwise returns false.
112112 public func isSome(x : ?Any ) : Bool {
@@ -119,7 +119,7 @@ module {
119119 };
120120
121121 // / Returns true if the optional arguments are equal according to the equality function provided, otherwise returns false.
122- public func equal< A > (x : ?A , y : ?A , eq : (A , A ) -> Bool ) : Bool = switch (x, y) {
122+ public func equal< T > (x : ?T , y : ?T , eq : (implicit : (equal : ( T , T ) -> Bool )) ) : Bool = switch (x, y) {
123123 case (null , null ) { true };
124124 case (?x_, ?y_) { eq(x_, y_) };
125125 case (_, _) { false }
@@ -132,7 +132,7 @@ module {
132132 // / - `#less` if the first value is `null` and the second is not,
133133 // / - `#greater` if the first value is not `null` and the second is,
134134 // / - the result of the comparison function when both values are not `null`.
135- public func compare< A > (x : ?A , y : ?A , cmp : (A , A ) -> Types . Order ) : Types . Order = switch (x, y) {
135+ public func compare< T > (x : ?T , y : ?T , cmp : (implicit : (compare : ( T , T ) -> Types . Order )) ) : Types . Order = switch (x, y) {
136136 case (null , null ) #equal;
137137 case (null , _) #less;
138138 case (_, null ) #greater;
@@ -148,7 +148,7 @@ module {
148148 };
149149
150150 // / Returns the textural representation of an optional value for debugging purposes.
151- public func toText< A > (x : ?A , toText : A -> Text ) : Text = switch x {
151+ public func toText< T > (x : ?T , toText : (implicit : T -> Text ) ) : Text = switch x {
152152 case null { "null" };
153153 case (?x_) { "?" # toText(x_) }
154154 };
0 commit comments