Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
A hybrid curry, and partial function.
Curry, or partially apply a function.
var curry = require('cast-curry');
function func(a, b, c){
return a + b + c;
}
var f = curry(func, 'x');
//print xyz
console.log(f('y', 'z'));
If some parameters positioned more to the left aren't known yet then you can use a placeholder.
var curry = require('cast-curry'),
_ = require('cast-curry/__');
function func2(a, b, c, d){
return a + b + c + d;
}
var part = curry(func2, _, 'x', _, 'z');
//print wxyz
console.log('part '+part('w', 'y'));
If the function you want to curry is variadic you can add a placeholder to the right if you know how many arguments you will need.
var curry = require('cast-curry'),
_ = require('cast-curry/__');
function greet(){
var str = '';
for(var i=0; i<arguments.length; i++){
str += arguments[i];
}
return str;
}
var getGreeting = curry(greet, 'Hello ', _, _, _, _);
//print Hello how are you?
console.log(getGreeting('how ', 'are ')('you')('?'));
Variadic functions won't work correctly if you don't add a placeholder to the right.
var getGreeting = curry(greet, 'Hello');
//This is an error.
console.log(getGreeting('how ', 'are ')('you')('?'));
You can pass a this
context as the first argument to set the function's context.
If you do then set the function to curry to the second argument.
Here push
is native. Like many native functions push
doesn't have a Function.length
property so you need to set a placeholder as the first push
parameter.
var array = [];
var push = curry(array, [].push, _);
//print 1
console.log(push('5'));
//print [ '5' ]
console.log(array);
//print 2
console.log(push('10'));
//print [ '5', '10' ]
console.log(array);
Objects, and arrays still have references to their data even when passed to a function.
So if you curry a function with a default parameter of array, or object later they can be altered. This means sometimes you might find you're data has changed unexpectedly.
This is ok if that's what you want, and you think you can keep track of that.
In many situations you probably don't want partial parameters to change.
For partial parameters use a deep clone
function, or a library like Immutable.js to order to make your objects, or list types not changeable if you want to limit side effects.
Curry functions, and make partials out of functions.
The placeholder parameter concept is taken from the really cool library Rambda.
FAQs
Curry, and partially apply funcitons
The npm package cast-curry receives a total of 4 weekly downloads. As such, cast-curry popularity was classified as not popular.
We found that cast-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.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.