Anonymous function documentation seems wrong

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?

1 Like

If you put an equals sign like func(n):Nat = {n}, then I think you need a name for the function like func foo(n):Nat = {n}. Probably not a lambda in that case then.