💾partial(f, a, b ...)
function composition
Last updated
Was this helpful?
function composition
Last updated
Was this helpful?
Was this helpful?
JS ⟩ value ⟩ function ⟩ higher-order ⟩ example ⟩ partial(f)
partial application of function
partialLeft(f, a)(x,y) = f(a, x,y)
partialRight(f, a)(x,y) = f(x,y, a)
partial(f, _, a)(x,y) = f(x, a, y) // _ means `undefined`
replit ⟩ partial(f)
// ⭐ partial left
// - partialLeft(f, a,b,c)(x,y) = f(a,b,c, x,y)
// ╰───╯ ╰─L─╯
function partialLeft(f, ...outerArgs) {
return function(...innerArgs) {
let args = [...outerArgs, ...innerArgs];
example
const f = (x,y,z) => x * (y - z); // test function
const _ = undefined;
partialLeft(f, 2)(3,4) // f(2, 3, 4) = 2 * (3-4) = -2
// ^ ^
partialRight(f, 2)(3,4) // f(3, 4, 2) = 3 * (4-2) = 6
// ^ ^
partial(f, _, 2)(3,4) // f(3, 2, 4) = 3 * (2-4) = -6
// ^ ^