0.0.1 • Published 9 years ago
ocurry v0.0.1
ocurry.js
Curry named-argument functions
Usage
// Function that takes an object of argument-properties
var request = function(args) {
return args.protocol + ' ' +
args.method + ' ' +
args.host +
args.path;
};
var http = ocurry(
// Function to curry
request,
// Named arguments to curry
{ protocol: 'HTTP' },
// (Optional) required named arguments
[ 'protocol', 'method', 'host', 'path' ]
);
http({ path: '/some/resource' });
// -> throws an error
var fromLocalhost = ocurry(http, { host: 'localhost' });
fromLocalhost({ path: '/some/resource' });
// -> throws an error
fromLocalhost.curried
// -> { protocol: 'HTTP', host: 'localhost' }
fromLocalhost.required
// -> [ 'method', 'path' ]
var getFromLocalhost = ocurry(fromLocalhost, { method: 'GET' });
getFromLocalhost.curried
// -> { protocol: 'HTTP', host: 'localhost', method: 'GET' }
getFromLocalhost.required;
// -> [ 'path' ]
getFromLocalhost();
// -> throws an error
getFromLocalhost({ path: '/some/resource' });
// -> returns 'HTTP GET localhost/some/resource'
Documentation
Comments to the source are Docco-compatible. To generate an annotated source listing for browsing:
npm --global install docco
docco --output docs ocurry.js
License
See LICENSE.md.
0.0.1
9 years ago