Socket
Socket
Sign inDemoInstall

arity-n

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    arity-n

Wraps a function with a function of a sertain arity.


Version published
Weekly downloads
1.2M
decreased by-19.41%
Maintainers
1
Install size
7.17 kB
Created
Weekly downloads
 

Package description

What is arity-n?

The arity-n package is designed to help with function arity, specifically allowing you to create functions of any arity based on a single function. This can be particularly useful for currying and partial application patterns, where the number of arguments a function takes is important for its execution.

What are arity-n's main functionalities?

Creating fixed arity functions

This feature allows you to create a new function with a fixed number of arguments (arity) from an existing function. In the example, `arityN` is used to ensure the `sum` function strictly accepts two arguments.

const { arityN } = require('arity-n');
const sum = (a, b) => a + b;
const sumFixed = arityN(2, sum);
console.log(sumFixed(1, 2)); // Outputs: 3

Currying functions with specific arity

This demonstrates how to curry a function to a specific arity using `curryN`. The `add` function is transformed into a curried version that requires exactly three arguments, provided one at a time.

const { curryN } = require('arity-n');
const add = (a, b, c) => a + b + c;
const curriedAdd = curryN(3, add);
console.log(curriedAdd(1)(2)(3)); // Outputs: 6

Other packages similar to arity-n

Readme

Source

arity-n

Build Status npm version

Wraps a function with a function of a sertain arity.

Installation

npm install arity-n

Usage

function fn(a, b, c, d) {
}

var arityN = require('arity-n');
var newFn = arityN(fn, 3);

newFn.length; // => 3

var arity4 = require('arity-n/4');
var newFn = arity4(fn);

newFn.length; // => 4

// Max arity is 5.
var newFn = arityN(fn, 7);

newFn.length; // => 4

Keywords

FAQs

Last updated on 07 Apr 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