The description of anonymous lambda functions shows the format: func() : () = { ⦠}
applyNTimes<Text>(10, "Hello!", func(x) = { Debug.print(x) } );
However this results in a syntax error, like this example below:
import Debug "mo:base/Debug";
import Nat "mo:base/Nat";
func foo(n:Nat, callback: Nat -> Nat):Nat {
callback(n+1);
};
func bar() {
let a:Nat = foo(3, func(n):Nat = {n});
Debug.print(Nat.toText(a));
};
But if I take away the equals sign in the lambda function, it compiles:
import Debug "mo:base/Debug";
import Nat "mo:base/Nat";
func foo(n:Nat, callback: Nat -> Nat):Nat {
callback(n+1);
};
func bar() {
let a:Nat = foo(3, func(n):Nat {n});
Debug.print(Nat.toText(a));
};
Is there something Iām missing?