While I love currying in many languages, I have some reservations
about it being generally useful enough in JS to be worth adding syntax
for.

1. Currying isn't friendly with variadic functions (that is, optional
arguments) - you can't tell when the function has consumed "enough"
arguments to finally resolve itself unless you predefine the arity.
2. Currying isn't friendly with JS's style of named arguments (passing
an option bag) - no clue how to solve this even with workarounds?

Partial application, whether via a dedicated syntax or as part of the
smart-mix pipeline syntax, gives you *most* of the benefits of
currying while solving these issues: 1, the partially-evaluated
function will fully evaluate as soon as you call it, with whatever
arguments you've given it (unless you explicitly partially-evaluate
again); 2, with object-rest, you can spread a later options object
into your partially-filled in options object, and then pass that to
the underlying function.

```
// variadic example with pipeline function
const threeOrMore = +> Math.max(3, ...);
// and you can partially-eval again to fill in more options without "finishing":
const moreLimitations = +> threeOrMore(newLimit, ...);`

// option-bag example with arrow function
const someOptions = (arg, moreOpts) => optUsingFunction(arg, 1, 2,
{foo: bar, ...moreOpts});
// or with pipeline function:
const someOptions = +> optUsingFunction(#, 1, 2, {foo:bar, ...##});
```

~TJ
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to