@teleology/fp
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -8,13 +8,13 @@ "use strict"; | ||
const curry = fn => (...args) => fn.bind(null, ...args); // export const curry = (arity = 0, fn) => (...args) => { | ||
// // we have surpassed the expected arity, so invoke the final function | ||
// if (arity <= args.length) { | ||
// return fn(...args); | ||
// } | ||
// // we still have args we can bind, recurse | ||
// const bound = fn.bind(fn, ...args); | ||
// return curry(arity - args.length, bound); | ||
// }; | ||
const curry = (arity = 0, fn) => (...args) => { | ||
// we have surpassed the expected arity, so invoke the final function | ||
if (arity <= args.length) { | ||
return fn(...args); | ||
} // we still have args we can bind, recurse | ||
const bound = fn.bind(fn, ...args); | ||
return curry(arity - args.length, bound); | ||
}; | ||
exports.curry = curry; |
{ | ||
"name": "@teleology/fp", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "A small collection of functional programming utils", | ||
@@ -5,0 +5,0 @@ "author": "Chris Sullivan <chrissullivan.dev@gmail.com>", |
@@ -147,3 +147,21 @@ # @teleology/fp | ||
## curry | ||
Curry a specific function with a known [arity](https://en.wikipedia.org/wiki/Arity). Please note, optional arguments are not considered during invocation unless they are explicity set. | ||
Example: | ||
```javascript | ||
const { curry } = require('@teleology/fp'); | ||
const test = (a, b, c) => console.log([a, b, c]); | ||
const curried = curry(3, test); | ||
// allows for flexibility | ||
curried(1, 2, 3); // [1, 2, 3] | ||
curried(1)(2)(3); // [1, 2, 3] | ||
curried(1)(2, 3); // [1, 2, 3] | ||
curried(1, 2)(3); // [1, 2, 3] | ||
``` | ||
## filter | ||
@@ -313,2 +331,5 @@ | ||
**2.0.2** | ||
- Added `curry` function | ||
**2.0.0** | ||
@@ -315,0 +336,0 @@ - Changed how `pick` operates, to migrate use `get` which is now exposed |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21115
358
412