Why Transform?
Last updated
Last updated
You might be wondering:
"When would I use function transformations in the real world?"
"Isn't it simpler to just define functions at the top level of the code, and call them as needed?"
Good questions. To be clear, we don't just transform functions at for the fun of it! We only use advanced techniques like function transformations when they make our code simpler than it would otherwise be.
Creating variations of the same function dynamically can make it a lot easier to share common functionality. Take a look at this formatter
function. It accepts a "pattern" and returns a new function that formats text according to that pattern:
Now we can create new formatters easily:
And use them like this: