sanctuary-js / sanctuary-def

Run-time type system for JavaScript
MIT License
294 stars 23 forks source link

abandon Ramda-style currying in favour of simple currying #179

Closed davidchambers closed 6 years ago

davidchambers commented 6 years ago

Commit message:

def has served two roles:

  • currying an uncurried implementation function; and
  • performing type checking at run time.

At the time of this project's inception in 2015 it seemed unreasonable to require users to provide curried implementation functions. Defining curried functions manually was onerous prior to ES6:

function(x) {
  return function(y) {
    return function(z) {
      return ...;
    };
  };
}

With ES6, defining curried functions is trivial:

x => y => z => ...

The landscape has changed since 2015, and it's now reasonable to assume that users are targeting ES6. Furthermore, the advantages of Ramda-style currying over simple currying do not justify the additional complexity. There's no compelling reason for def to continue to serve two roles.

User-facing changes:

  • $ functions must now be applied to arguments one at a time;
  • def now requires a curried implementation function;
  • def no longer imposes an arbitrary arity limit;
  • def functions must now be applied to arguments one at a time; and
  • __ has been removed (simple currying precludes placeholders).

Internal changes:

  • the checkTypes option is now checked in just one place; and
  • def is now essentially a no-op if type checking is disabled.

This pull request embraces the f (x) (y) style proposed in sanctuary-js/sanctuary#438.

The changes to the test suite will be easier to review once #178 has been merged.

davidchambers commented 6 years ago

I've rebased this pull request now that #184 has been merged. Please review scripts/lint and .eslint-es6.js.