Skip to content
curry named-argument functions
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.editorconfig
.gitattributes
.gitignore
.istanbul.yml
.jshintignore
.jshintrc
.npmignore
.travis.yml
LICENSE.md
README.md
bower.json
ocurry.js
package.json

README.md

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.

Something went wrong with that request. Please try again.