I just finished refactoring a large function to Array.tabulate to try to save some cycles and heap(see New Vector data structure in Motoko - #5 by skilesare) and received a rude awakening when I realized I had to call a type function to create a timer.
Generally, it seems we need a way to do <system>
in iterable functions like tabulate, map, fold, etc.
Would it be insecure to have dynamic functions inherit the type of their context function? I added system to the function that calls tabulate but it doesn’t flow through:
public func myfunc<system>(caller: Principal, items : [Items]) : async* [?result]{
//doesn't work
let results = Array.tabulate(items.size(), func<system>(i : Nat): ?Items {
//doesn't exist and calls into Prim so I can't shim my own
let results = Array.tabulateSys<system>(items.size(), func<system>(i : Nat): ?Items {
//preferred - just flows through to dynamic functions because containing function has the `system` type.
let results = Array.tabulate(items.size(), func(i : Nat): ?Items {
Pingning @claudio @luc-blaeser @ggreif @rvanasa @dfx-json