Comparing version
# curriable CHANGELOG | ||
## 1.2.4 | ||
- Refactor under the hood to make performance more consistent across browsers | ||
## 1.2.3 | ||
- Improve `rollup` build (have distinct UMD, CommonJS, and ESM builds) | ||
## 1.2.2 | ||
@@ -4,0 +12,0 @@ |
@@ -5,48 +5,50 @@ 'use strict'; | ||
var __ = typeof Symbol === 'function' ? Symbol('curriable placeholder') : 0xedd1; | ||
/** | ||
* @function getArgs | ||
* | ||
* @description | ||
* get the complete args with previous placeholders being filled in | ||
* | ||
* @param originalArgs the arguments from the previous run | ||
* @param nextArgs the arguments from the next run | ||
* @returns the complete list of args | ||
* @constant __ placeholder used when parameters are skipped | ||
*/ | ||
var getArgs = function (originalArgs, nextArgs) { | ||
var length = originalArgs.length; | ||
var nextLength = nextArgs.length; | ||
var args = new Array(length); | ||
var nextArgsIndex = 0; | ||
for (var index = 0; index < length; index++) { | ||
args[index] = | ||
originalArgs[index] === __ && nextArgsIndex < nextLength | ||
? nextArgs[nextArgsIndex++] | ||
: originalArgs[index]; | ||
} | ||
if (nextArgsIndex < nextLength) { | ||
for (; nextArgsIndex < nextLength; nextArgsIndex++) { | ||
args.push(nextArgs[nextArgsIndex]); | ||
} | ||
} | ||
return args; | ||
}; | ||
var __ = typeof Symbol === 'function' ? Symbol('curriable placeholder') : 0xedd1; | ||
/** | ||
* @function hasPlaceholder | ||
* @function recursiveCurry | ||
* | ||
* @description | ||
* determine if any of the arguments are placeholders | ||
* recursively curry over the arguments until all have been resolved | ||
* | ||
* @param args the args passed to the function | ||
* @param arity the arity of the function | ||
* @returns are any of the args placeholders | ||
* @param fn the function to curry | ||
* @param arity the length of the function to curry until | ||
* @param args the existing arguments | ||
* @returns the result of the function call | ||
*/ | ||
var hasPlaceholder = function (args, arity) { | ||
for (var index = 0; index < arity; index++) { | ||
if (args[index] === __) { | ||
return true; | ||
var recursiveCurry = function (fn, arity, args) { | ||
return function () { | ||
var length = args.length; | ||
var newArgs = arguments; | ||
var newArgsLength = newArgs.length; | ||
var combined = []; | ||
var newArgsIndex = 0; | ||
var remaining = arity; | ||
var value; | ||
if (length) { | ||
for (var index = 0; index < length; index++) { | ||
value = combined[index] = | ||
args[index] === __ && newArgsIndex < newArgsLength | ||
? newArgs[newArgsIndex++] | ||
: args[index]; | ||
if (value !== __) { | ||
--remaining; | ||
} | ||
} | ||
} | ||
} | ||
return false; | ||
if (newArgsIndex < newArgsLength) { | ||
for (; newArgsIndex < newArgsLength; newArgsIndex++) { | ||
value = newArgs[newArgsIndex]; | ||
combined.push(value); | ||
if (value !== __ && newArgsIndex < arity) { | ||
--remaining; | ||
} | ||
} | ||
} | ||
return remaining > 0 | ||
? recursiveCurry(fn, arity, combined) | ||
: fn.apply(this, combined); | ||
}; | ||
}; | ||
@@ -67,10 +69,3 @@ | ||
if (arity === void 0) { arity = fn.length; } | ||
function curried() { | ||
var args = arguments; | ||
return args.length >= arity && !hasPlaceholder(args, arity) | ||
? fn.apply(this, args) | ||
: function () { | ||
return curried.apply(this, getArgs(args, arguments)); | ||
}; | ||
} | ||
var curried = recursiveCurry(fn, arity, []); | ||
curried.arity = arity; | ||
@@ -77,0 +72,0 @@ curried.fn = fn; |
@@ -1,47 +0,49 @@ | ||
var __ = typeof Symbol === 'function' ? Symbol('curriable placeholder') : 0xedd1; | ||
/** | ||
* @function getArgs | ||
* | ||
* @description | ||
* get the complete args with previous placeholders being filled in | ||
* | ||
* @param originalArgs the arguments from the previous run | ||
* @param nextArgs the arguments from the next run | ||
* @returns the complete list of args | ||
* @constant __ placeholder used when parameters are skipped | ||
*/ | ||
var getArgs = function (originalArgs, nextArgs) { | ||
var length = originalArgs.length; | ||
var nextLength = nextArgs.length; | ||
var args = new Array(length); | ||
var nextArgsIndex = 0; | ||
for (var index = 0; index < length; index++) { | ||
args[index] = | ||
originalArgs[index] === __ && nextArgsIndex < nextLength | ||
? nextArgs[nextArgsIndex++] | ||
: originalArgs[index]; | ||
} | ||
if (nextArgsIndex < nextLength) { | ||
for (; nextArgsIndex < nextLength; nextArgsIndex++) { | ||
args.push(nextArgs[nextArgsIndex]); | ||
} | ||
} | ||
return args; | ||
}; | ||
var __ = typeof Symbol === 'function' ? Symbol('curriable placeholder') : 0xedd1; | ||
/** | ||
* @function hasPlaceholder | ||
* @function recursiveCurry | ||
* | ||
* @description | ||
* determine if any of the arguments are placeholders | ||
* recursively curry over the arguments until all have been resolved | ||
* | ||
* @param args the args passed to the function | ||
* @param arity the arity of the function | ||
* @returns are any of the args placeholders | ||
* @param fn the function to curry | ||
* @param arity the length of the function to curry until | ||
* @param args the existing arguments | ||
* @returns the result of the function call | ||
*/ | ||
var hasPlaceholder = function (args, arity) { | ||
for (var index = 0; index < arity; index++) { | ||
if (args[index] === __) { | ||
return true; | ||
var recursiveCurry = function (fn, arity, args) { | ||
return function () { | ||
var length = args.length; | ||
var newArgs = arguments; | ||
var newArgsLength = newArgs.length; | ||
var combined = []; | ||
var newArgsIndex = 0; | ||
var remaining = arity; | ||
var value; | ||
if (length) { | ||
for (var index = 0; index < length; index++) { | ||
value = combined[index] = | ||
args[index] === __ && newArgsIndex < newArgsLength | ||
? newArgs[newArgsIndex++] | ||
: args[index]; | ||
if (value !== __) { | ||
--remaining; | ||
} | ||
} | ||
} | ||
} | ||
return false; | ||
if (newArgsIndex < newArgsLength) { | ||
for (; newArgsIndex < newArgsLength; newArgsIndex++) { | ||
value = newArgs[newArgsIndex]; | ||
combined.push(value); | ||
if (value !== __ && newArgsIndex < arity) { | ||
--remaining; | ||
} | ||
} | ||
} | ||
return remaining > 0 | ||
? recursiveCurry(fn, arity, combined) | ||
: fn.apply(this, combined); | ||
}; | ||
}; | ||
@@ -62,10 +64,3 @@ | ||
if (arity === void 0) { arity = fn.length; } | ||
function curried() { | ||
var args = arguments; | ||
return args.length >= arity && !hasPlaceholder(args, arity) | ||
? fn.apply(this, args) | ||
: function () { | ||
return curried.apply(this, getArgs(args, arguments)); | ||
}; | ||
} | ||
var curried = recursiveCurry(fn, arity, []); | ||
curried.arity = arity; | ||
@@ -72,0 +67,0 @@ curried.fn = fn; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.curriable = {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
(global = global || self, factory(global.curriable = {})); | ||
}(this, function (exports) { 'use strict'; | ||
var __ = typeof Symbol === 'function' ? Symbol('curriable placeholder') : 0xedd1; | ||
/** | ||
* @function getArgs | ||
* | ||
* @description | ||
* get the complete args with previous placeholders being filled in | ||
* | ||
* @param originalArgs the arguments from the previous run | ||
* @param nextArgs the arguments from the next run | ||
* @returns the complete list of args | ||
* @constant __ placeholder used when parameters are skipped | ||
*/ | ||
var getArgs = function (originalArgs, nextArgs) { | ||
var length = originalArgs.length; | ||
var nextLength = nextArgs.length; | ||
var args = new Array(length); | ||
var nextArgsIndex = 0; | ||
for (var index = 0; index < length; index++) { | ||
args[index] = | ||
originalArgs[index] === __ && nextArgsIndex < nextLength | ||
? nextArgs[nextArgsIndex++] | ||
: originalArgs[index]; | ||
} | ||
if (nextArgsIndex < nextLength) { | ||
for (; nextArgsIndex < nextLength; nextArgsIndex++) { | ||
args.push(nextArgs[nextArgsIndex]); | ||
} | ||
} | ||
return args; | ||
}; | ||
var __ = typeof Symbol === 'function' ? Symbol('curriable placeholder') : 0xedd1; | ||
/** | ||
* @function hasPlaceholder | ||
* @function recursiveCurry | ||
* | ||
* @description | ||
* determine if any of the arguments are placeholders | ||
* recursively curry over the arguments until all have been resolved | ||
* | ||
* @param args the args passed to the function | ||
* @param arity the arity of the function | ||
* @returns are any of the args placeholders | ||
* @param fn the function to curry | ||
* @param arity the length of the function to curry until | ||
* @param args the existing arguments | ||
* @returns the result of the function call | ||
*/ | ||
var hasPlaceholder = function (args, arity) { | ||
for (var index = 0; index < arity; index++) { | ||
if (args[index] === __) { | ||
return true; | ||
var recursiveCurry = function (fn, arity, args) { | ||
return function () { | ||
var length = args.length; | ||
var newArgs = arguments; | ||
var newArgsLength = newArgs.length; | ||
var combined = []; | ||
var newArgsIndex = 0; | ||
var remaining = arity; | ||
var value; | ||
if (length) { | ||
for (var index = 0; index < length; index++) { | ||
value = combined[index] = | ||
args[index] === __ && newArgsIndex < newArgsLength | ||
? newArgs[newArgsIndex++] | ||
: args[index]; | ||
if (value !== __) { | ||
--remaining; | ||
} | ||
} | ||
} | ||
} | ||
return false; | ||
if (newArgsIndex < newArgsLength) { | ||
for (; newArgsIndex < newArgsLength; newArgsIndex++) { | ||
value = newArgs[newArgsIndex]; | ||
combined.push(value); | ||
if (value !== __ && newArgsIndex < arity) { | ||
--remaining; | ||
} | ||
} | ||
} | ||
return remaining > 0 | ||
? recursiveCurry(fn, arity, combined) | ||
: fn.apply(this, combined); | ||
}; | ||
}; | ||
@@ -68,10 +70,3 @@ | ||
if (arity === void 0) { arity = fn.length; } | ||
function curried() { | ||
var args = arguments; | ||
return args.length >= arity && !hasPlaceholder(args, arity) | ||
? fn.apply(this, args) | ||
: function () { | ||
return curried.apply(this, getArgs(args, arguments)); | ||
}; | ||
} | ||
var curried = recursiveCurry(fn, arity, []); | ||
curried.arity = arity; | ||
@@ -101,3 +96,3 @@ curried.fn = fn; | ||
}))); | ||
})); | ||
//# sourceMappingURL=curriable.js.map |
@@ -1,1 +0,1 @@ | ||
(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):b(a.curriable={})})(this,function(a){"use strict";var b="function"==typeof Symbol?Symbol("curriable placeholder"):60881,c=function(a,c){for(var d=a.length,e=c.length,f=Array(d),g=0,h=0;h<d;h++)f[h]=a[h]===b&&g<e?c[g++]:a[h];if(g<e)for(;g<e;g++)f.push(c[g]);return f},d=function(a,c){for(var d=0;d<c;d++)if(a[d]===b)return!0;return!1},e=function(a,b){function e(){var f=arguments;return f.length>=b&&!d(f,b)?a.apply(this,f):function(){return e.apply(this,c(f,arguments))}}return void 0===b&&(b=a.length),e.arity=b,e.fn=a,e};e.__=b;var f=function(a){return a.fn};e.uncurry=f,a.__=b,a.curry=e,a.uncurry=f,a.default=e,Object.defineProperty(a,"__esModule",{value:!0})}); | ||
(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):(a=a||self,b(a.curriable={}))})(this,function(a){"use strict";var b="function"==typeof Symbol?Symbol("curriable placeholder"):60881,c=function(a,d,e){return function(){var f,g=e.length,h=arguments,i=h.length,j=[],k=0,l=d;if(g)for(var m=0;m<g;m++)f=j[m]=e[m]===b&&k<i?h[k++]:e[m],f!==b&&--l;if(k<i)for(;k<i;k++)f=h[k],j.push(f),f!==b&&k<d&&--l;return 0<l?c(a,d,j):a.apply(this,j)}},d=function(a,b){void 0===b&&(b=a.length);var d=c(a,b,[]);return d.arity=b,d.fn=a,d};d.__=b;var e=function(a){return a.fn};d.uncurry=e,a.__=b,a.curry=d,a.uncurry=e,a.default=d,Object.defineProperty(a,"__esModule",{value:!0})}); |
@@ -17,3 +17,3 @@ { | ||
"devDependencies": { | ||
"@types/jest": "^23.3.8", | ||
"@types/jest": "^23.3.11", | ||
"benchmark": "^2.1.4", | ||
@@ -28,4 +28,4 @@ "cli-table": "^0.3.1", | ||
"performance-now": "^2.1.0", | ||
"ramda": "^0.25.0", | ||
"rollup": "^0.66.6", | ||
"ramda": "^0.26.1", | ||
"rollup": "^0.68.2", | ||
"rollup-plugin-babel-minify": "^6.2.0", | ||
@@ -73,3 +73,3 @@ "rollup-plugin-typescript2": "^0.18.1", | ||
"types": "index.d.ts", | ||
"version": "1.2.3" | ||
"version": "1.2.4" | ||
} |
@@ -21,3 +21,3 @@ # curriable | ||
`curriable` provides a `curry` method that is [highly performant](#benchmarks) with a small footprint (_473 bytes minified+gzipped_). You can call the method with any combination of parameters (one at a time, all at once, or any number in between), and placeholders are supported. | ||
`curriable` provides a `curry` method that is [highly performant](#benchmarks) with a small footprint (_573 bytes minified+gzipped_). You can call the method with any combination of parameters (one at a time, all at once, or any number in between), and placeholders are supported. | ||
@@ -127,3 +127,3 @@ If `fn` is the curried function and `_` is the placeholder value, the following are all equivalent: | ||
Benchmarks were performed on an i7 8-core Arch Linux laptop with 16GB of memory using NodeJS version `8.9.4`. | ||
Benchmarks were performed on an i7 8-core Arch Linux laptop with 16GB of memory using NodeJS version `10.15.0`. | ||
@@ -134,5 +134,5 @@ #### Passing each parameter in curried calls | ||
| ------------- | ------------------- | ------------------------ | | ||
| **curriable** | **1,632,076** | **1.43%** | | ||
| ramda | 1,041,570 | 1.15% | | ||
| lodash | 138,685 | 0.88% | | ||
| **curriable** | **3,577,400** | **1.22%** | | ||
| ramda | 2,327,403 | 1.00% | | ||
| lodash | 211,666 | 0.62% | | ||
@@ -143,5 +143,5 @@ #### Passing all parameters in one call | ||
| ------------- | ------------------- | ------------------------ | | ||
| **curriable** | **21,517,188** | **1.36%** | | ||
| ramda | 10,064,677 | 0.97% | | ||
| lodash | 8,031,747 | 1.18% | | ||
| **curriable** | **17,081,266** | **0.59%** | | ||
| ramda | 13,347,748 | 0.67% | | ||
| lodash | 9,398,950 | 0.70% | | ||
@@ -152,5 +152,5 @@ #### Using placeholder parameters in curried calls | ||
| ------------- | ------------------- | ------------------------ | | ||
| **curriable** | **2,577,105** | **1.02%** | | ||
| ramda | 1,309,428 | 1.02% | | ||
| lodash | 204,268 | 0.77% | | ||
| **curriable** | **4,341,722** | **0.63%** | | ||
| ramda | 2,902,086 | 0.66% | | ||
| lodash | 280,139 | 0.50% | | ||
@@ -163,11 +163,10 @@ ## Development | ||
- `build` => run `rollup` to build `dist` files | ||
- `build:types` => create the `index.d.ts` types file | ||
- `clean` => run `rimraf` on the `lib` folder | ||
- `clean` => run `rimraf` on the `dist` folder | ||
- `dev` => run webpack dev server to run example app (playground!) | ||
- `lint` => runs `tslint` against all files in the `src` folder | ||
- `lint:fix` => runs `lint``, fixing any errors if possible | ||
- `lint:fix` => runs `lint`, fixing any errors if possible | ||
- `prepublish` => runs `prepublish:compile` | ||
- `prepublish:compile` => run `lint`, `flow`, `test:coverage`, `transpile:lib`, `transpile:es`, and `dist` | ||
- `prepublish:compile` => run `lint`, `flow`, `test:coverage`, `clean`, and `dist` | ||
- `test` => run `jest` test functions | ||
- `test:coverage` => run `test`, but with coverage checker | ||
- `test:watch` => run `test`, but with persistent watcher |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
32807
-6.4%13
-18.75%332
-18.02%167
-0.6%