Socket
Socket
Sign inDemoInstall

chickencurry

Package Overview
Dependencies
0
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    chickencurry

Add some chicken curry to your functions


Version published
Maintainers
1
Created

Readme

Source

Chickencurry

Build Status npm version

Add some chickencurry to your functions

Installation

npm install chickencurry

Usage

Basic usage

var curry = require('chickencurry');

function add(a, b) {
  return a + b;
}
var add1 = curry(add, 1);
var add12 = curry(add, 1, 2);

add1(3); // => 4
add12(); // => 3

Recurry

You can curry a function and define the arguments for the curryied functions later.

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

var curryiedAdd = curry(add); // no arguments passed to curry
var add1 = curryiedAdd(1);
var add2 = curryiedAdd(2);

add1(3); // => 4
add2(3); // => 5

function sum3(a, b, c) {
  return a + b + c;
}

curry(sum3)(1, 2)(3) // => 6
curry(sum3)(1)(2)(3) // => 6

function join() {
  return Array.prototype.slice.call(arguments).join();
}

Curry n arguments

var curryN = require('chickencurry/N');

curryN(join, 3)(1, 2)(3) // => '1,2,3'

Placeholder

You can curry a function using placeholders, if you want to set the i.e 3rd argument.

function join(a, b, sep) {
  return a + sep + b;
};

var __ = require('chickencurry/__');

var join_ = curry(join, __, __, '_'); 
// or var join_ = curry(join, undefined, undefined, '_'); 

join_('chicken', 'curry'); // => 'chicken_curry'


var joinCurry = curry(join); 
var joinDash = joinCurry(__, __, '-');

joinDash('chicken', 'curry'); // => 'chicken-curry'

Function scope

If you want to curry a method of an object you have to bind the scope to the function.

var obj = {
  name: 'stoeffel',
  myFunc: function(arg) {
    return arg + this.name;
  }
};

var myFunc = curry(obj.myFunc.bind(obj), 'Hello ');
myFunc(); // => 'Hello stoeffel'

Keywords

FAQs

Last updated on 05 Feb 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc