UNPKG

moltres-utils

Version:
69 lines (55 loc) 1.89 kB
"use strict"; require("core-js/modules/es6.object.define-property"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _arrayFlatten = _interopRequireDefault(require("../lang/arrayFlatten")); var _arrayLikeReduce = _interopRequireDefault(require("../lang/arrayLikeReduce")); var _arrayLikeSlice = _interopRequireDefault(require("../lang/arrayLikeSlice")); var _identity = _interopRequireDefault(require("./identity")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // TODO BRN: This method is important at a fundamental level. Need to rewrite this to not depend upon data methods. /** * Performs left-to-right function composition. The leftmost function may have * any arity; the remaining functions must be unary. * * In some libraries this function is named `sequence`. * * **Note:** The result of pipe is not automatically curried. * * @function * @since v0.0.11 * @category common * @param {...Function} functions * @returns {Function} * @example * * const f = pipe(Math.pow, negate, inc) * * f(3, 4) // -(3^4) + 1 */ var pipe = function pipe() { for (var _len = arguments.length, functions = new Array(_len), _key = 0; _key < _len; _key++) { functions[_key] = arguments[_key]; } functions = (0, _arrayFlatten.default)(functions); var _functions = functions, length = _functions.length; if (length === 0) { return _identity.default; } if (length === 1) { return functions[0]; } var firstFunc = functions[0]; var rest = (0, _arrayLikeSlice.default)(functions, 1); return function () { return (0, _arrayLikeReduce.default)(rest, firstFunc.apply(void 0, arguments), function (piped, func) { return func(piped); }); }; }; var _default = pipe; exports.default = _default; //# sourceMappingURL=pipe.js.map