1
0
Fork 0
my_spells/node_modules/redux/lib/compose.js
Joe Wroten 00a0e57784 WIP
2016-07-10 02:17:53 -05:00

40 lines
No EOL
1.1 KiB
JavaScript

"use strict";
exports.__esModule = true;
exports["default"] = compose;
/**
* Composes single-argument functions from right to left. The rightmost
* function can take multiple arguments as it provides the signature for
* the resulting composite function.
*
* @param {...Function} funcs The functions to compose.
* @returns {Function} A function obtained by composing the argument functions
* from right to left. For example, compose(f, g, h) is identical to doing
* (...args) => f(g(h(...args))).
*/
function compose() {
for (var _len = arguments.length, funcs = Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
}
if (funcs.length === 0) {
return function (arg) {
return arg;
};
} else {
var _ret = function () {
var last = funcs[funcs.length - 1];
var rest = funcs.slice(0, -1);
return {
v: function v() {
return rest.reduceRight(function (composed, f) {
return f(composed);
}, last.apply(undefined, arguments));
}
};
}();
if (typeof _ret === "object") return _ret.v;
}
}