diff --git a/snippets/partial.md b/snippets/partial.md new file mode 100644 index 000000000..17a53b49e --- /dev/null +++ b/snippets/partial.md @@ -0,0 +1,17 @@ +### 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`. + +```js +const partial = (fn, ...partials) => (...args) => fn(...partials, ...args); +``` + +```js +function greet(greeting, name) { + return greeting + ' ' + name + '!'; +} +const greetHello = partial(greet, 'Hello'); +greetHello('John'); // 'Hello John!' +``` diff --git a/snippets/partialRight.md b/snippets/partialRight.md new file mode 100644 index 000000000..6b6aa1131 --- /dev/null +++ b/snippets/partialRight.md @@ -0,0 +1,17 @@ +### partialRight + +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`. + +```js +const partialRight = (fn, ...partials) => (...args) => fn( ...args, ...partials); +``` + +```js +function greet(greeting, name) { + return greeting + ' ' + name + '!'; +} +const greetJohn = partialRight(greet, 'John'); +greetJohn('Hello'); // 'Hello John!' +``` diff --git a/tag_database b/tag_database index fa638b65f..c34856405 100644 --- a/tag_database +++ b/tag_database @@ -160,6 +160,8 @@ orderBy:object,array over:adapter,function palindrome:string parseCookie:utility,string +partial:function +partialRight:function partition:array,object,function percentile:math pick:object,array