const minMax = over(Math.min, Math.max); minMax(1, 2, 3, 4, 5); // [1,5]
Creates a function that invokes the provided function with its arguments transformed.
Use Array.map() to apply transforms to args in combination with the spread operator (...) to pass the transformed arguments to fn.
const overArgs = (fn, transforms) => (...args) => fn(...args.map((val, i) => transforms[i](val))); -
var func = overArgs( - function(x, y) { - return [x, y]; - }, - [square, doubled] -); -func(9, 3); // [81, 6] +
const square = n => n * n; +const double = n => n * 2; +const fn = overArgs((x, y) => [x, y], [square, double]); +fn(9, 3); // [81, 6]
Performs left-to-right function composition for asynchronous functions.
Use Array.reduce() with the spread operator (...) to perform left-to-right function composition using Promise.then(). The functions can return a combination of: simple values, Promise's, or they can be defined as async ones returning through await. All functions must be unary.
const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Promise.resolve(arg));
const sum = pipeAsyncFunctions( x => x + 1,