Skip to content

Hey! This is Partial Application

Daisho Komiyama edited this page Mar 6, 2020 · 1 revision

This is what we call Partial Application pattern?

const multiply = (a, b) => a * b;

function prefill = (fn, prefilledValue) {
    const inner = liveInput => {
        const output = fn(liveInput, prefilledValue);
        return output;
    };
    return inner;
}

const multiplyBy2 = prefill(multiply, 2);

const result = multiplyBy2(5); //10
Clone this wiki locally