Files
30-seconds-of-code/node_modules/graphql-compose/lib/utils/compose.js
2019-08-20 15:52:05 +02:00

32 lines
898 B
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
/* eslint-disable */
/**
* 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 composeImpl(...funcs) {
if (funcs.length === 0) {
return arg => arg;
}
const last = funcs[funcs.length - 1];
const rest = funcs.slice(0, -1);
return (...args) => rest.reduceRight((composed, f) => f(composed), last(...args));
}
const compose = composeImpl;
var _default = compose;
exports.default = _default;