auto-curry
Supercharge your functions by giving them the ability to auto-curry
Last updated 9 years ago by zeusdeux .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install auto-curry 
SYNC missed versions from official npm registry.

auto-curry

Supercharge your functions by giving them the ability to auto-curry.

Note: This library actually uses partial application internally and not currying. So, yes, the name is a misnomer. It is the result of my incorrect understanding of the concepts when I wrote the library. It is still perfectly usable and is used in production.

Installation

npm install auto-curry --save

Usage

In node, you can just require('auto-curry').

In the browser, you can use build/auto-curry.min.js

  • with require.js, browserify etc
  • directly by using window.autoCurry

Node

var cu = require('auto-curry');
var add = cu(function (a, b) {
    return a + b;
});
var messWithThis = cu(function(v){
  this.a.push(v);
  return ++v;
});
var map = cu(function map(fn, list) {
  var self = arguments[2] ? arguments[2] : this;
  try {
    return list.map(fn, self);
  }
  catch (e) {
    return [].map.call(list, fn, self);
  }
});
var x = {a: []};

console.log(map(add(1), [1, 2, 3])); //[2, 3, 4]
console.log(map(messWithThis, [1,2,3], x)); //[2, 3, 4]
console.log(x.a); //[1, 2, 3]

Browser

var cu = window.autoCurry; //using it off the global
var add = cu(function (a, b) {
    return a + b;
});
var messWithThis = cu(function(v){
  this.a.push(v);
  return ++v;
});
var map = cu(function map(fn, list) {
  console.log(arguments[2]);
  var self = arguments[2] ? arguments[2] : this;
  try {
    return list.map(fn, self);
  }
  catch (e) {
    return [].map.call(list, fn, self);
  }
});
var x = {a: []};

console.log(map(add(1), [1, 2, 3])); //[2, 3, 4]
console.log(map(messWithThis, [1,2,3], x)); //[2, 3, 4]
console.log(x.a); //[1, 2, 3]

License

MIT

Changelog

0.2.1

  • Now, if the function passed to auto-curry has an arity of one, the function itself is returned. Earlier this was only for zero arity functions.

Current Tags

  • 0.2.1                                ...           latest (9 years ago)

4 Versions

  • 0.2.1                                ...           9 years ago
  • 0.2.0                                ...           12 years ago
  • 0.1.1                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (4)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |