Having curry by default allows you to create very readable code using function composition, which is the primary way of transforming data through multiple steps in FP.
For example of a typical imperative approach to applying functions:
Compared to a haskell-style JS which combines currying and function composition (. combines functions in Haskell):
price :: Product -> (Int)
price p =
p == 'book' && () => 10
p == 'laptop' && () => 20
shipping :: Product -> (Int -> Int)
shipping p =
p == 'book' && (x) => x + 10
p == 'laptop' && (x) => x + 25
tax :: Int -> Int
tax x = x + (x * 0.13)
total :: Product -> Int
total p = tax . shipping(p) . price(p)
Alternatively, you can easily create object specific total functions:
Note how in the FP `total` version the data is not held in temporary variables but passed directly to the next function, which could be a performance gain.
Another benefit is how it's easier to work with curried functions when using map/reduce and list comprehensions - two other fundamental building blocks of FP programs. For example, you can pass a curried `shipping` function directly to map whereas `addShipping` would required an anonymous function (since it has two arguments).
The performance question is largely a question of the implementation and compiler optimizations. But considering we're working in a browser environment the "bottle-neck" is going to be DOM interaction not passing around curried functions everywhere.
Additionally, you are much more like to create functions in FP with single arguments rather than multiple in order for composition to work cleanly.
For example of a typical imperative approach to applying functions:
Compared to a haskell-style JS which combines currying and function composition (. combines functions in Haskell): Alternatively, you can easily create object specific total functions: Note how in the FP `total` version the data is not held in temporary variables but passed directly to the next function, which could be a performance gain.Another benefit is how it's easier to work with curried functions when using map/reduce and list comprehensions - two other fundamental building blocks of FP programs. For example, you can pass a curried `shipping` function directly to map whereas `addShipping` would required an anonymous function (since it has two arguments).
The performance question is largely a question of the implementation and compiler optimizations. But considering we're working in a browser environment the "bottle-neck" is going to be DOM interaction not passing around curried functions everywhere.Additionally, you are much more like to create functions in FP with single arguments rather than multiple in order for composition to work cleanly.