Ramda.js R.nAry() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Wraps a function so it accepts exactly n parameters (official Ramda docs). Extra arguments never reach the inner function. Missing ones arrive as undefined. The wrapper’s .length is n.

Stable since v0.1.0: R.nAry is a core Ramda helper — not deprecated, experimental, or non-standard. n must be an integer from 0 through 10.

Syntax

Call R.nAry. Start with this line.

Ramda
R.nAry(n, fn)
CallWhat it does
R.nAry(n, fn)Primary signature.
R.nAry(...)Call the function helper.

Prefer import { nAry } from "ramda" when you want a named import.

Library declarations
Ramda
R.nAry(n, fn)

Parameters

ParameterDescription
nRequired. Arity of the wrapper (0–10)
fnRequired. Function to wrap

Return Value

Return ValueDescription
*New function with .length === n

Ramda Examples

Example 1 — Official takesOneArg

Wrap a two-argument function so only one argument is forwarded.

Ramda
const takesTwoArgs = (a, b) => [a, b];
const takesOneArg = R.nAry(1, takesTwoArgs);

console.log(takesTwoArgs.length);
console.log(JSON.stringify(takesTwoArgs(1, 2)));
console.log(takesOneArg.length);
console.log(takesOneArg(1, 2));
Try It Yourself

How It Works

  1. Original. takesTwoArgs has length 2 and returns both values.
  2. Clamp. nAry(1, …) builds a wrapper with length 1.
  3. Drop extra. The call (1, 2) forwards only 1.
  4. Missing slot. Inside fn, b is undefined → [1, undefined].

Example 2 — Nullary nAry(0)

Forward zero arguments — every caller argument is ignored.

Ramda
const takesThreeArgs = (a, b, c) => [a, b, c];
const takesNone = R.nAry(0, takesThreeArgs);

console.log(takesNone.length);
console.log(takesNone());
console.log(takesNone(1, 2, 3));
Try It Yourself

How It Works

  1. n = 0. The wrapper has no parameters (.length is 0).
  2. Empty call. fn runs with an empty argument list → three undefineds.
  3. Args ignored. (1, 2, 3) still forwards nothing — same result.
  4. Use case. Handy when a callback must not see event objects or leftover args.

Example 3 — nAry(1) vs nAry(2) vs nAry(3)

The same three-argument function, clamped three different ways.

Ramda
const takesThreeArgs = (a, b, c) => [a, b, c];

console.log(R.nAry(1, takesThreeArgs)(1, 2, 3));
console.log(R.nAry(2, takesThreeArgs)(1, 2, 3));
console.log(R.nAry(3, takesThreeArgs)(1, 2, 3));
Try It Yourself

How It Works

  1. n = 1. Only 1 is kept → [1, undefined, undefined].
  2. n = 2. Keeps 1 and 2 → third slot empty.
  3. n = 3. All three arrive → full list.
  4. Aliases. R.unary ≡ nAry(1); R.binary ≡ nAry(2).

Example 4 — Fix parseInt with nAry(1)

map passes (value, index). That index becomes a broken radix unless you clamp.

Ramda
const values = ['10', '11', '12'];

console.log(values.map(parseInt));
console.log(values.map(R.nAry(1, parseInt)));
Try It Yourself

How It Works

  1. Leak. Bare map(parseInt) passes index as radix → NaN / wrong base.
  2. Clamp to 1. nAry(1, parseInt) forwards only the string.
  3. Base 10. Every item parses correctly → [10, 11, 12].
  4. Why not 2? nAry(2, parseInt) still leaks the index as radix — use 1 (or R.unary).

Example 5 — nAry Does Not Wait Like curryN

Missing args become undefined immediately — they do not create a waiting function.

Ramda
const sum = (a, b) => a + b;
const clamped = R.nAry(2, sum);
const curried = R.curryN(2, sum);

console.log(clamped(1, 2));
console.log(clamped(1));
console.log(typeof curried(1));
console.log(curried(1)(2));
Try It Yourself

How It Works

  1. Full clamp. clamped(1, 2) → 3.
  2. Partial clamp. clamped(1) calls sum(1, undefined) → NaN.
  3. Curry waits. curryN(2, sum)(1) returns a function.
  4. Then finish. That function with 2 yields 3. Clamp with nAry; wait with curryN.

Browser & Runtime Support

R.nAry() is ordinary JavaScript once Ramda is loaded. It needs no special browser API — only a JS runtime that can run Ramda v0.1.0+.

✓ Ramda 0.1.0+ · Any JS runtime

Ramda.js R.nAry()

Works in every modern browser and runtime where you can load Ramda 0.1.0 or later (CDN or npm). Older Ramda builds before 0.1.0 do not include nAry.

100% With Ramda 0.1+
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
R.nAry() Universal

Bottom line: Safe in any project that includes Ramda 0.1.0 or later. Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Bun, and Deno.

Frequently Asked Questions

R.nAry(n, fn) wraps fn in a new function that accepts exactly n parameters. Extra arguments are not passed through. Missing arguments arrive as undefined. The wrapper's .length is n. Added in v0.1.0.

Next: R.nthArg()

Return a function that picks the nth argument from a wider call.

R.nthArg() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful