ocurry

0.0.1 • Public • Published

ocurry.js

npm version Bower version build status

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.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.1
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.1
    1

Package Sidebar

Install

npm i ocurry

Weekly Downloads

1

Version

0.0.1

License

Apache-2.0

Last publish

Collaborators

  • kemitchell