Partial Application
Fix some arguments and reuse functions.
What Is Partial Application?
Partial application means taking a function that needs several arguments and fixing some of them ahead of time, producing a new function that needs only the rest.
It lets you build specialized functions from general ones. A generic multiply(a, b) can become a specialized double(b) by fixing a = 2.
A Function With Many Arguments
Start with a general-purpose function. Here add takes three numbers. Often you call it again and again with the same first argument.
function add(a, b, c) {
return a + b + c;
}
console.log(add(1, 2, 3));
console.log(add(1, 10, 100));All lessons in this course
- Partial Application
- Currying Functions
- Function Composition
- Building pipe and compose