Hint
Partial application = pre-fill some args, return function waiting for the rest; currying = always one arg at a time
Both techniques create specialized functions from general ones β but differ in how arguments are collected.
// Partial Application β pre-fill SOME args
function partial(fn, ...presetArgs) {
return function(...laterArgs) {
return fn(...presetArgs, ...laterArgs);
};
}
const add = (a, b, c) => a + b + c;
const add10 = partial(add, 10); // pre-fill first arg
const add10and20 = partial(add, 10, 20); // pre-fill two args
add10(5, 3); // 18 β takes remaining 2 args AT ONCE
add10and20(7); // 37 β takes remaining 1 arg
// Currying β always ONE arg at a time
const curriedAdd = a => b => c => a + b + c;
curriedAdd(1)(2)(3); // 6 β strictly one at a time
// Practical partial application with bind()
function greet(greeting, punct, name) {
return `${greeting}, ${name}${punct}`;
}
const hello = greet.bind(null, 'Hello', '!'); // partial via bind
hello('Alice'); // 'Hello, Alice!'
hello('Bob'); // 'Hello, Bob!'
Summary: