froebel
Version:
TypeScript utility library
38 lines (34 loc) • 941 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
/**
* Given a function and its nth..last arguments, return a function accepting
* arguments 0..n-1.
*
* @example
* ```
* const divide = (dividend: number, divisor: number) => dividend / divisor
*
* // (dividend: number) => number
* const divideBy2 = forward(divide, 2)
*
* // prints: 0.5
* console.log(divideBy2(1))
* ```
*
* @example
* ```
* const fetchUrl = async (protocol: string, domain: string, path: string) =>
* await fetch(`${protocol}://${domain}/${path}`)
*
* const fetchRepo = forward(fetchUrl, 'github.com', 'MathisBullinger/froebel')
*
* const viaHTTPS = await fetchRepo('https')
* ```
*/
const forward = (fun, ...argsRight) => (...argsLeft) => fun(...argsLeft, ...argsRight);
var _default = forward;
exports.default = _default;
module.exports = Object.assign(exports.default || {}, exports);