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

arity-n

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

arity-n

Wraps a function with a function of a sertain arity.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

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

Keywords

FAQs

Package last updated on 20 Jan 2015

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