babel-plugin-transform-function-partial-application

1.0.0 • Public • Published

babel-plugin-transform-function-partial-application

Travis build status NPM version Canonical Code Style

Uses function-bind syntax to transpile bind expressions to partially applied call expressions. The first parameter of the function is set to the bind context.

Input:

apple
  ::foo('a')
  ::bar('b');

Output:

bar(foo(apple, 'a'), 'b');

BIG WARNING: This is a proof-of-concept. See Motivation.

Examples

Using existing functional programming utilities

import {
  assocPath
} from 'ramda';

({
  name: 'babel-plugin-transform-function-partial-application'
})
  ::assocPath(['repository', 'type'], 'git')
  ::assocPath(['repository', 'url'], 'https://github.com/gajus/babel-plugin-transform-function-partial-application');

// {
//   name: 'babel-plugin-transform-function-partial-application',
//   repository: {
//     type: 'git',
//     url: 'https://github.com/gajus/babel-plugin-transform-function-partial-application'
//   }
// }

Using utility functions to construct Promises

const map = (promise, callback) => {
  return promise
    .then((values) => {
      const mappedValues = [];

      for (const key in values) {
        if (values.hasOwnProperty(key)) {
          mappedValues.push(callback(values[key], key, values));
        }
      }

      return mappedValues;
    });
};

Promise
  .resolve([
    'foo',
    'bar',
    'baz'
  ])
  ::map((currentValue, index) => {
    return index + ':' + currentValue;
  })
  .then((values) => {
    values;

    // [
    //   '0:foo',
    //   '1:bar',
    //   '2:baz'
    // ]
  });

Motivation

Enable use of the existing functional programming libraries in a way thats easy to debug and performant.

Readme

Keywords

Package Sidebar

Install

npm i babel-plugin-transform-function-partial-application

Weekly Downloads

1

Version

1.0.0

License

BSD-3-Clause

Last publish

Collaborators

  • gajus