Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
better-curry
Advanced tools
Forget Function.bind and func.apply(context, arguments), performance matters! For a better curry!
=================
Because return function(){ return fn.apply(context, Array.prototype.slice.call(arguments)); }
isn't good enough, that's why better curry.
Forget Function.bind
and func.apply(context, arguments)
, performance matters! For a better curry!
You won't find any other curry module that can achieve those benchmarks.
~ npm install better-curry
or
~ bower install better-curry
Works on the browser or on node.js (super duper performance on the latter)
BetterCurry.wrap(fn, [context], [len])
When the function have all arguments defined.
You can bind the new resulting function to a new context (change the this
inside the function).
function base(argument1, argument2){
return this.data + ' ' + argument1 + argument2;
}
var based = BetterCurry.wrap(base, {data: 'hurry'});
based('up','!'); // 'hurry up!'
If the function doesn't have defined parameters, you can still coerce the function to adopt a length
function base(){
return Array.prototype.slice.call(arguments).join(' + ');
}
var based = BetterCurry.wrap(base, null, 3);
based('one', 'two', 'three', 'will be ignored'); // 'one + two + three'
Passing a len
of -1
will make sure it behaves like variadic (that is, uses fn.apply(context, Array.prototype.slice.call(arguments));
function base(){
return Array.prototype.slice.call(arguments).join(' + ');
}
var based = BetterCurry.wrap(base, null, -1);
based('one', 'two', 'three', 'wont be ignored','its','free for all'); // 'one + two + three + wont be ignored + its + free for all'
BetterCurry.predefine(fn, args, [context], [len])
Predefine creates a function that, when executed, will have the predefined arguments plus any arguments that you pass:
function base(argument){
return argument;
}
var based = BetterCurry.predefine(base, ['argument','will be ignored']);
based('this will be ignored as well'); // 'argument'
Variadic work as well, just remember to pass the len -1
(or 8
if you think it will be that big...)
function base(){
return Array.prototype.slice.call(arguments).join(' + ');
}
var curried = BetterCurry.predefine(base, ['1','2','3','4'], null, -1);
curried('5'); // '1 + 2 + 3 + 4 + 5'
curried = BetterCurry.predefine(base, ['1','2','3','4'], null, 5);
curried('5','6'); // '1 + 2 + 3 + 4 + 5'
All -1
len are slower since it uses Function.apply
(many times slower than Function.call
and Array.prototype.slice
+ concat
)
BetterCurry.delegate(proto, target)
A minor rewrite of visionmedia's delegates but around 13% faster
var obj = {
request: {
_value: 1,
function1: function(){},
get value(){
return this._value;
},
set value(val){
this._value = val;
},
}
};
var delegated = BetterCurry.delegate(obj, 'request'); //all mirror functions from obj will reflect to obj.request with the same context
delegated
.method('function1')
.access('value')
.access({name: 'value', as: 'value2'})
.method({name: 'function1', as: 'function2', args:['arg1']});
//obj is now:
obj = {
function1: function1(){/*...*/},
function2: function1(arg1){/*...*/},
value: /*..value..*/
value2: /*..value..*/
request: {/*...*/}
};
Just regular stuff (100% coverage by the way)
npm run test
npm run coverage
=============================== Coverage summary ===============================
Statements : 100% ( 90/90 ), 3 ignored
Branches : 100% ( 223/223 ), 5 ignored
Functions : 100% ( 26/26 )
Lines : 100% ( 90/90 )
================================================================================
Curious about performance? Get flabbergasted.
npm run benchmark
The MIT License (MIT)
Copyright (c) 2014 Paulo Cesar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
FAQs
Forget Function.bind and func.apply(context, arguments), performance matters! For a better curry!
The npm package better-curry receives a total of 469 weekly downloads. As such, better-curry popularity was classified as not popular.
We found that better-curry demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.