Add partial, partialRight
This commit is contained in:
17
snippets/partial.md
Normal file
17
snippets/partial.md
Normal file
@ -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!'
|
||||||
|
```
|
||||||
17
snippets/partialRight.md
Normal file
17
snippets/partialRight.md
Normal file
@ -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!'
|
||||||
|
```
|
||||||
@ -160,6 +160,8 @@ orderBy:object,array
|
|||||||
over:adapter,function
|
over:adapter,function
|
||||||
palindrome:string
|
palindrome:string
|
||||||
parseCookie:utility,string
|
parseCookie:utility,string
|
||||||
|
partial:function
|
||||||
|
partialRight:function
|
||||||
partition:array,object,function
|
partition:array,object,function
|
||||||
percentile:math
|
percentile:math
|
||||||
pick:object,array
|
pick:object,array
|
||||||
|
|||||||
Reference in New Issue
Block a user