3 ms·
It can be idiomatic in Javascript if you choose a functional style. I think Javascript has become a kitchen-sink language. It is, as you say, a language that a
by agentultra 9y ago
It can be idiomatic in Javascript if you choose a functional style.
I think Javascript has become a kitchen-sink language. It is, as you say, a language that affords many styles. If you pick a sub-set of the language that is functional you can see that currying is quite idiomatic in that context.
That being said I think library support is a necessity when choosing a more functional approach in Javascript as the "core" experience in JS caters to an imperative, C-derived language (as per many of the examples). If you work with Ramda you can get most of what you need today to make working with currying, and it's compositional capabilities, pleasant.
Consider R.curryN:
const add = R.curryN(2, (a, b) => a + b)
You can now call this:
add(1)(2)
add(1)
add(1, 2)
And you have options in terms of order of parameters:
const sillyAdd2 = add(R.__, 2) // a silly example
sillyAdd2(3) // => 5
And if you want even more flexibility there is Fantasyland[0] and Sanctuary[1] among others.
Javascript is fertile ground, in my experience, for getting developers to experiment with and adopt functional programming paradigms.
[0] https://github.com/fantasyland/fantasy-land https://github.com/fantasyland/fantasy-land
[1] https://github.com/sanctuary-js/sanctuary https://github.com/sanctuary-js/sanctuary