babel-plugin-curried-functions

1.0.3 • Public • Published

babel-plugin-curried-functions

Note: This is an experimental plugin made as part of my master thesis with the intent of getting to know the Babel-compiler and its extensibility.

This plugin adds the reserved keyword curry which can prefix a function definition in order to make it curried. For the sake of simplicity currying arrow-functions is not supported.

Syntax

In

curry function f(a, b, c) {
    ...
}

Out

function curry(fn) {
  const numParamsRequired = fn.length;

  function curryFactory(params) {
    return function (...args) {
      const newParams = params.concat(args);

      if (newParams.length >= numParamsRequired) {
        return fn(...newParams);
      }

      return curryFactory(newParams);
    }
  }

  return curryFactory([]);
}

const a = curry(function f(a, b, c) {
    ...
});

/babel-plugin-curried-functions/

    Package Sidebar

    Install

    npm i babel-plugin-curried-functions

    Weekly Downloads

    4

    Version

    1.0.3

    License

    ISC

    Unpacked Size

    3.84 kB

    Total Files

    8

    Last publish

    Collaborators

    • pettersmoen