It creates a function returning a function, where the argument to the first (which is a template) is used as a closure in the second (which takes a dict of values).
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"