Currying is a functional-programming technique that transforms a function with N parameters into a series of functions that each take one or more of those parameters.
In everyday JavaScript development, currying enables elegant composition patterns and partial application.
Your task is to write a generic curry
helper.
function curry<F extends (...args: any[]) => any>(fn: F): Curried<F>;
Curried<F>
must satisfy these rules at runtime:
fn
.fn
and return its result.const join = (a: string | number, b: string | number, c: string | number) => `${a}_${b}_${c}`;
const curriedJoin = curry(join);
curriedJoin(1, 2, 3); // '1_2_3'
curriedJoin(1)(2, 3); // '1_2_3'
curriedJoin(1, 2)(3); // '1_2_3'
Further reading: