How to write a function that returns a type Trie.Trie<Nat, Text> in Motoko

Can someone give an example of the correct syntax for writing a function that returns a data type of Trie.Trie<Nat,Text>

1 Like

Hi Jesse.

I had I problem returning Trie but solve it with the help of:

My example:

public shared(msg) func readOwnedFT () : async Result.Result<[FT], Error> {

        let callerId = msg.caller;
        if(Principal.toText(callerId) == "2vxsx-fae") {
            return #err(#NotAuthorized);

        let ownedForms : Trie.Trie<Nat, FT> = Trie.filter<Nat, FT>(formTemplates, func (k, v) {
          Principal.equal(v.principal, callerId) 
        let result : [FT] = Trie.toArray<Nat, FT, FT>(ownedForms, func (k, v) { v });

        if(Nat.notEqual(result.size(), 0)) {
        } else {

My error: I was using return Result.fromOption(result, )