This package has been deprecated

Author message:

Deprecated

saffron

0.1.0 • Public • Published

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 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) 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

Package Sidebar

Install

npm i saffron

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • yuanqing
  • pi0