UNPKG

froebel

Version:
28 lines (27 loc) 741 B
/** * 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); export default forward;