Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

curry-d

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

curry-d

An optimized version of curry. UMD compatible for widespread use

  • 0.2.1
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

curry-d

An efficient implementation of curry. Using a dispatcher, gets a little more than 20% speed increase over traditional approach while still adding lots of sugar.1

Usage

This module exports three functions: curry, curryRight, and uncurry.

curry

curry fills a functions signature from left to right until all args are defined:

var add = function (a, b) {
    return a + b;
};

// add.length === 2, so it must be given two args.
var curried = curry(add)(40); // a function
curried(2); // 42

In case you need to curry a varargs function you can specify the number of arguments desired at curry time:

var add = function () {
    return require('lodash').reduce(arguments, function (total, n) {return total + n;});
};

var curried = curry(add)(40); // undefined
var curried = curry(add, 2)(40); // a function
curried(2); // 42

You can optionally add multiple arguments in each call:

curry(add, 2)(40, 2); // 42

Unless you want to force a single argument per call (handy w/ e.g., _.forEach):

curry(add, 2, true)(40, 99)(2); // 42

However, you cannot overflow your arguments:

curry(add, 2)(40, 2, 99); // 42

Unless you really want to:

curry(add, null, null, false)(40, 2, 99); // 141

curryRight

curryRight works just like curry, but in the opposite direction:

var divide = function (a, b) {
    return a / b;
};

curry(divide)(1, 2); // .5

curryRight(divide)(1, 2); // 2

uncurry

uncurry takes a curried function and returns the original. Handy if you've curried something but need the original too. Or if you're unsure if something is curried, uncurry is a noop if the function is not curried:

uncurry(curry(divide)(1)) === divide; // true

More to come.

Keywords

FAQs

Package last updated on 13 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc