Add overArgs
This commit is contained in:
20
snippets/overArgs.md
Normal file
20
snippets/overArgs.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
### overArgs
|
||||||
|
|
||||||
|
Creates a function that invokes the provided function with its arguments transformed.
|
||||||
|
|
||||||
|
Use `Array.map()` to apply `transforms` to `args` in combination with the spread operator (`...`) to pass the transformed arguments to `fn`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const overArgs = (fn, transforms) => (...args) =>
|
||||||
|
fn(...args.map((val, i) => transforms[i](val)));
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
var func = overArgs(
|
||||||
|
function(x, y) {
|
||||||
|
return [x, y];
|
||||||
|
},
|
||||||
|
[square, doubled]
|
||||||
|
);
|
||||||
|
func(9, 3); // [81, 6]
|
||||||
|
```
|
||||||
@ -162,6 +162,7 @@ once:function
|
|||||||
onUserInputChange:browser,event,advanced
|
onUserInputChange:browser,event,advanced
|
||||||
orderBy:object,array
|
orderBy:object,array
|
||||||
over:adapter,function
|
over:adapter,function
|
||||||
|
overArgs:adapter,function
|
||||||
palindrome:string
|
palindrome:string
|
||||||
parseCookie:utility,string
|
parseCookie:utility,string
|
||||||
partial:function
|
partial:function
|
||||||
|
|||||||
Reference in New Issue
Block a user