📕 subnode [[@ryan/20210607203034 partial_application]]
in 📚 node [[20210607203034-partial_application]]
Partial application is a form of functional applicationwherein the first n
arguments are bound.
This is not to be confused with currying
In JavaScriptin particular, a built-in method on functions called .bind
can accomplish this:
const add = (x, y) => x + y; const add10 = add.bind(null, 10); console.log(add10(20));
30
We could implement a free function as such in TypeScript
type Variadic<R> = (...args: any[]) => R; function partial<T>(fn: Variadic<T>, ...args: any[]): Variadic<T> { return function(...rest: any[]) { return fn(...args, ...rest); } } const add = (x: number, y: number): number => x + y; const add10 = partial(add, 10); console.log(add10(100));
: 110
📖 stoas
- public document at doc.anagora.org/20210607203034-partial_application
- video call at meet.jit.si/20210607203034-partial_application