This is a follow-up to the basic currying problem. In addition to regular currying, the new curry
helper must support placeholders that allow arguments to be supplied out of order.
curry.placeholder
symbol (or unique value). Users pass this placeholder in any position to mark an argument as to be provided later.const _: unique symbol; // exported via curry.placeholder
function curry<F extends (...args: any[]) => any>(fn: F): Curried<F>;
const join = (a: any, b: any, c: any) => `${a}_${b}_${c}`;
const curriedJoin = curry(join);
const _ = curry.placeholder;
curriedJoin(1, 2, 3); // '1_2_3'
curriedJoin(_, 2)(1, 3); // '1_2_3'
curriedJoin(_, _, _)(1)(_, 3)(2); // '1_2_3'
Further reading: