0.1.0 • Published 9 years ago
saffron v0.1.0
saffron
An implementation of function currying in JavaScript.
Why
This was written mainly as a learning exercise.
Usage
'use strict';
var saffron = require('saffron');
var fn = function(x) {
return function(y, z) {
return x + y + z;
};
};
console.log(saffron(fn)(1, 2, 3)); //=> 6
console.log(saffron(fn)(1, 2)(3)); //=> 6
console.log(saffron(fn)(1)(2, 3)); //=> 6
console.log(saffron(fn)(1)(2)(3)); //=> 6
fn
can return a function, which in turn returns a function, which in turn returns another function, and so on…- There aren’t any restrictions on how the curried function receives its arguments. As above, arguments could be supplied all at a time, some at a time, or even one at a time.
API
var saffron = require('saffron');
saffron(fn , context)
Returns a curried version of fn
.
fn
— Throws if not a function.context
— The context (ie.this
) forfn
. The context is propagated to all functions possibly “nested” infn
.
Installation
Install via npm:
$ npm i --save saffron
Changelog
- 0.1.0
- Initial release
License
0.1.0
9 years ago