For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/function/ary.md.

ary es-toolkit

Creates a new function that limits the number of arguments a function can accept.

const limitedFunc = ary(func, n);

Usage

ary(func, n)

Use ary when you want to limit the number of arguments a function can accept. Additional arguments passed are ignored. This is especially useful in functional programming to prevent callback functions from receiving unexpected arguments.

import { ary } from 'es-toolkit/function';

function fn(a: number, b: number, c: number) {
  return Array.from(arguments);
}

// Limit to accept no arguments
ary(fn, 0)(1, 2, 3);
// Returns: []

// Limit to accept only 1 argument
ary(fn, 1)(1, 2, 3);
// Returns: [1]

// Limit to accept only 2 arguments
ary(fn, 2)(1, 2, 3);
// Returns: [1, 2]

This is especially useful when used with array methods like map.

// parseInt accepts two arguments, but map passes three
['1', '2', '3'].map(parseInt);
// Returns: [1, NaN, NaN]
// Because parseInt('2', 1), parseInt('3', 2) are executed.

// Use ary to limit to only the first argument
['1', '2', '3'].map(ary(parseInt, 1));
// Result: [1, 2, 3] ✅

Parameters

funcFrequired

The function to limit the number of arguments.

nnumberrequired

The maximum number of arguments to accept.

Returns

A new function that accepts at most n arguments.

(...args: any[]) => ReturnType<F>
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.