curry :: (a → b → c → ... → d) → a → b → c → ... → d
Returns a curried version of the supplied function.
const add = curry((a, b) => a + b);
const inc = add(1);
inc(2); //=> 3
apply :: (a → b → c → ... → d) → [a, b, c, ...] → d
Returns the application of the supplied list as arguments to the supplied function.
const sum = (a, b) => a + b;
apply(sum, [2, 3]); //=> 5
flip :: (a → b → c) → (b → a → c)
Returns a function with the arguments flipped.
const invertedPower = flip(Math.pow);
invertedPower(2, 3); //=> 9
fix :: (Function → Function) → Function
Fix-point function for anonymous recursion, implemented with the Y combinator.
fix((fib) => (n) => n <= 1
? 1
: fib(n - 1) + fib(n - 2))(9); //=> 55
memoize :: Function → Function
Caches computed results, speeding up later calls with the same arguments.
const memoF = memoize(expensiveFunction);
memoF(2) // slow, but result is then cached
memoF(2) // fast
deny :: Function → Function
Denies the result of a predicate function
const gt2 = (x) => x > 2;
const twoOrLess = deny(gt2);
gt2(2); //=> false
twoOrLess(2); //=> true
compose :: ((y → z), (x → y), …, (o → p), ((a, b, …, n) → o)) → (a → b → … → n → z)
Performs right-to-left function composition. The rightmost function may have any arity; the remaining functions must be unary.
const plus1 = (x) => x + 1;
const negate = (x) => -x;
const complex = compose(plus1, negate, Math.pow);
complex(3, 2) === plus1(negate(Math.pow(3, 2)));