Files
30-seconds-of-code/snippets/partial.md
2018-01-24 14:40:16 +02:00

447 B

partial

Creates a function that invokes fn with partials prepended to the arguments it receives.

Use the spread operator (...) to prepend partials to the list of arguments of fn.

const partial = (fn, ...partials) => (...args) => fn(...partials, ...args);
function greet(greeting, name) {
  return greeting + ' ' + name + '!';
}
const greetHello = partial(greet, 'Hello');
greetHello('John'); // 'Hello John!'