I'm having trouble reasoning about this code, can you show me how it's used?
The last function called in turn creates a function using the Function constructor, which, since it takes a string argument as the function body, allows the expansion of the values dict into variables and thus the population of the template string:
applyTemplate("aaa ${v}")({"v":"yo"}) --> "aaa yo"
tpl = applyTemplate("Hello ${a}");
tpl({"a": "you"}); // --> Hello you
tpl({"a": "dude"}); // --> Hello dude