Generic currying
This commit is contained in:
11
snippets/curry.md
Normal file
11
snippets/curry.md
Normal file
@ -0,0 +1,11 @@
|
||||
### Curry
|
||||
|
||||
Use recursion.
|
||||
If the number of provided arguments (`args`) is sufficient, call the passed function `f`.
|
||||
Otherwise return a curried function `f` that expects the rest of the arguments.
|
||||
|
||||
```js
|
||||
curry = f =>
|
||||
(...args) =>
|
||||
args.length >= f.length ? f(...args) : (...otherArgs) => curry(f)(...args, ...otherArgs)
|
||||
```
|
||||
Reference in New Issue
Block a user