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 greet = (greeting, name) => greeting + ' ' + name + '!'; const greetHello = partial(greet, 'Hello'); greetHello('John'); // 'Hello John!'
Creates a function that invokes fn with partials appended to the arguments it receives.
Use the spread operator (...) to append partials to the list of arguments of fn.
const partialRight = (fn, ...partials) => (...args) => fn(...args, ...partials); -
function greet(greeting, name) { - return greeting + ' ' + name + '!'; -} +
const greet = (greeting, name) => greeting + ' ' + name + '!'; const greetJohn = partialRight(greet, 'John'); greetJohn('Hello'); // 'Hello John!'
Runs an array of promises in series.
Use Array.reduce() to create a promise chain, where each promise returns the next promise when resolved.
const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve());