Add partial, partialRight

This commit is contained in:
Angelos Chalaris
2018-01-24 14:40:16 +02:00
parent 6b8d3e5886
commit 7c481f80bf
3 changed files with 36 additions and 0 deletions

17
snippets/partial.md Normal file
View 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
View 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!'
```

View File

@ -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