1.0.0 • Published 8 years ago
babel-plugin-transform-function-partial-application v1.0.0
babel-plugin-transform-function-partial-application
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.
1.0.0
8 years ago