npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

curry-chain

v0.2.0

Published

Chainable function currying

Readme

Chainable Currying

Build status Code coverage Code style License

curry-chain is a library for creating literary, chai-style curried functions.

Usage

curry-chain allows to define curried functions: functions with settable arguments and chainable setters. Curried functions are wrapped around ordinary functions, allowing to set their arguments one by one, set individual properties for object arguments, and much more.

In order to create a curried function, call curry on an existing function:

const curry = require('curry-chain');

function greet (who, how) {
  return how + ', ' + who + '!';
}

var curryGreet = curry.fn(greet).where
  .arg(0).has.setter('who').and
  .arg(1).has.setter('how')
  .done();

This creates a chained function, the 0-th argument of which can be set with a who setter, and the 1-st with a how setter:

var greeting = curryGreet.who('universe').how('Hello').done();
// greeting === 'Hello, universe!'

More details of how the above code works:

  • fn sets the function for currying
  • arg selects the context - the argument index, which further setter and other instructions will describe
  • setter creates a chainable setter with the specified name. The setter will set the current argument. By default, a setter replaces the argument, but other behaviors are also available
  • done signals that the function is complete
  • where, that and and are language chains, they are here just to improve readablility, just like in chai

The created curried function will have the specified chainable setters, and the done function, which will call the original function specified by fn, with the values of arguments set.

Notice that curry looks like a curried function: it is chainable and has the done terminator. This is not a coincidence; curry actually is a curried wrapper around a low-level curry creator function (see the source code for more details).

Argument assignment

Several setters

You can specify several setters for the same argument:

var curryGreet = curry.fn(greet).where
  .arg(0).has.setter('who')
  .arg(1).has.setter('how').and.setter('with')
  .done();
  
curryGreet.with('G\'day').who('world').done();
curryGreet.how('Hello').who('world').done();

Language

You can specify language chains to improve readablility by using the language chain:

var curryAdd = curry.fn((x, y) => x + y).where
  .arg(0).has.setter('x').and
  .arg(1).has.setter('y').and
  .language('with', 'and')
  .done();
  
curryAdd.with.x(10).and.y(5);

The names of language chains may coincide with names of setters.

Setters for properties

It is possible to specify setters for separate properties of an argument using the option and options chains:

function drawFigure(shape, pos, options) {
  // uses pos.x, pos.y, options.color and options.size
}

var curriedDraw = curry.fn(drawFigure).where
  .arg(0).has.setter('shape')
  .arg(1).has.setter('pos').and.option('x').and.option('y')
  .arg(2).has.options('color', 'size')
  .language('with', 'and')
  .done();
  
curriedDraw.shape('circle')
  .with.x(10).and.y(25)
  .color('blue').and.size(10).done();

Option sinks

The sink chain specifies a setter that can assign several properties of an argument using Object.assign:

var curriedDraw = // ...
  .arg(2).has.sink('with').done();

// 'with' may work simultaneously as a language chain and a sink
var shape = curriedDraw.shape('circle').with.x(10).and.color('blue');
// Leaves { color: 'blue' } option intact
shape.with({ size: 10 }).done();

Defaults

You can specify default argument values by using the defaultsTo chain:

var curriedDraw = // ...
  .arg(1).defaultsTo({ x: 0, y: 0 })
  .done();

Partial assignment

As it can be expected from currying, curried functions may have only some arguments assigned.

var curryAdd = // ...
[1, 2, 3].map(curryAdd.with.x(10).done); // returns [11, 12, 13]

Immutability

All generated curry chains are immutable, so you can safely pass them around.

var curriedDraw = // ...
var circle = curriedDraw.type('circle');
var setSize = (shape, sz) => shape.size(sz);

// will draw red circle with size 10
var sizedCircle = setSize(circle.color('red'), 10);
// draws a blue circle with size 25
setSize(circle.color('blue'), 25).done();
// still draws a red circle with size 10
sizedCircle.x(5).y(10).done();

Functional interface

curry is implemented using objects. There is also a purely functional implementation, available via require('chain-curry/fn'). Unlike the default implementation, the functional one does not require the done terminator (although it still works):

var curry = require('chain-curry/fn');

var curryAdd = curry.fn((x, y) => x + y).where
  .arg(0).has.setter('x').and
  .arg(1).has.setter('y').and
  .language('with', 'and')();
  
[1, 2, 3].map(curryAdd.with.x(10)); // returns [11, 12, 13]

Unfortunately, the functional implementation is ~2 times slower than the object one. This is because the object implementation can use prototypes in order to reuse setters during chaining; the functional one needs to create new functions for setters during each chained call.

License

curry-chain is available under the terms of the Apache 2.0 license.