Exposing functions with Passthrough Utility Classes

How close are we to being able to do something like below? Maybe we can do it now and I just can’t figure out the signature? Seems pretty important to creating a library of composable utiltities.

Utility.mo

module{
    public class Utility(){
       var nonce = 0;
       
       //cant do shared here because "a shared function is only allowed as a public field of an actor (This is a limitation of the current version.)"
       public func getNonce() : async Nat{nonce};
    };
}

myActor.mo

import Utility "Utility";
actor class myActor() = this {
     var __utility = Utility.Utility();

     public shared func getNonce() : () -> async Nonce = __utility.getNonce;
};

It would also be great to be able to do this for query functions.

2 Likes