33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
(function (global, factory) {
|
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
(global = global || self, factory(global.cumpa = {}));
|
|
}(this, function (exports) { 'use strict';
|
|
|
|
/**
|
|
* Similar to compose but performs from left-to-right function composition.<br/>
|
|
* {@link https://30secondsofcode.org/function#composeright see also}
|
|
* @param {...[function]} fns) - list of unary function
|
|
* @returns {*} result of the computation
|
|
*/
|
|
const composeRight = (...fns) => compose(...fns.reverse());
|
|
|
|
/**
|
|
* Performs right-to-left function composition.<br/>
|
|
* Use Array.prototype.reduce() to perform right-to-left function composition.<br/>
|
|
* The last (rightmost) function can accept one or more arguments; the remaining functions must be unary.<br/>
|
|
* {@link https://30secondsofcode.org/function#compose original source code}
|
|
* @param {...[function]} fns) - list of unary function
|
|
* @returns {*} result of the computation
|
|
*/
|
|
function compose(...fns) {
|
|
return fns.reduce((f, g) => (...args) => f(g(...args)))
|
|
}
|
|
|
|
exports.composeRight = composeRight;
|
|
exports.default = compose;
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
}));
|