Skip to content

petter/babel-plugin-curried-functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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) {
    ...
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published