0.1.0 • Published 9 years ago

saffron v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

saffron npm Version Build Status Coverage Status

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 arent 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) for fn. The context is propagated to all functions possibly nested in fn.

Installation

Install via npm:

$ npm i --save saffron

Changelog

  • 0.1.0
    • Initial release

License

MIT