Prepend function arguments

JavaScript, Function · Sep 15, 2020

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);
const greet = (greeting, name) => greeting + ' ' + name + '!';
const greetHello = partial(greet, 'Hello');
greetHello('John'); // 'Hello John!'

More like this

  • Append function arguments

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

    JavaScript, Function · Sep 15, 2020

  • Bind function context

    Creates a function that invokes fn with a given context, optionally prepending any additional supplied parameters to the arguments.

    JavaScript, Function · Oct 18, 2020

  • Invoke functions on arguments

    Creates a function that invokes each provided function with the arguments it receives and returns the results.

    JavaScript, Function · Oct 21, 2020