Closed cmdcolin closed 3 years ago
Hi Colin!
At the end of the day it all boils down to personal preference, as there's no functional advantage to one over the other. The readme suggests transforms for two main reasons:
function(arg)
syntax employed by C-like languages, then the subject-verb left-to-right flow of price|roundUp
can feel more natural than roundUp(price)
. I pulled that syntax from the family of popular template languages based on Django's (Twig, Nunjucks, etc) where those expressions were also optimized for folks who aren't traditionally programmers.So there you have it! If the function syntax makes more sense to you and anyone you have that might be writing these expressions, by all means you should use that :). If the above reasons could be impactful for you, though, transforms still have a nice place within the language definition.
Enjoy!
gotcha thanks so much :)
You're welcome! :)
Great work on this library. I was wondering about your perspective on functions vs transforms
The readme suggests: "While Transforms are the preferred way to change one value into another value, Jexl also allows top-level expression functions to be defined"
And I see that functions are actually a recent addition, so this is pretty cool, but do you have any reasons why transforms would be preferred?