Ramda.js R.unary() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

A wrapper that lets only the first argument through. R.unary(fn) returns a new function that calls fn with its first argument and ignores the rest — the classic fix for callbacks that receive extra values, like parseInt inside .map.

Status: stable since Ramda v0.2.0 — not deprecated, experimental, or non-standard.

Syntax

Call R.unary. Start with this line.

Ramda
R.unary(fn)
CallWhat it does
R.unary(fn)Primary signature.
R.unary(...)Call the function helper.

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

Library declarations
Ramda
R.unary(fn)

Parameters

ParameterDescription
fnRequired. Any function

Return Value

Return ValueDescription
*A function of length 1 that calls fn(firstArg)

Ramda Examples

Example 1 — Official: takesTwoArgs

The wrapper has length 1, so the second argument never arrives.

Ramda
function takesTwoArgs(a, b) {
  return [a, b];
}
const takesOneArg = R.unary(takesTwoArgs);

console.log(takesTwoArgs.length);   // → 2
console.log(takesTwoArgs(1, 2));    // → [1, 2]
console.log(takesOneArg.length);    // → 1
console.log(takesOneArg(1, 2));     // → [1, undefined]
Try It Yourself

How It Works

  1. Original. takesTwoArgs declares two parameters, so its length is 2.
  2. Wrap. R.unary returns a function with length 1.
  3. Call. takesOneArg(1, 2) forwards only 1.
  4. Result. b is missing, so it is undefined.

Example 2 — Fix map(parseInt)

The index from .map becomes parseInt’s radix. Unary blocks it.

Ramda
const nums = ["10", "10", "10"];

console.log(nums.map(parseInt));
// → [10, NaN, 2]

console.log(nums.map(R.unary(parseInt)));
// → [10, 10, 10]
Try It Yourself

How It Works

  1. Extra args. .map calls the callback with (value, index, array).
  2. Radix leak. parseInt reads the index as its radix: 0, 1, 2.
  3. Bad results. Radix 1 is invalid (NaN); radix 2 reads "10" as binary (2).
  4. Fix. R.unary(parseInt) forwards only the value, so every string becomes 10.

Example 3 — Protect a Default Parameter

An optional second parameter gets overwritten by the index — unless you wrap it.

Ramda
const greet = (name, greeting = "Hello") => greeting + ", " + name;
const names = ["Ada", "Bob"];

console.log(names.map(greet));
// → ["0, Ada", "1, Bob"]

console.log(names.map(R.unary(greet)));
// → ["Hello, Ada", "Hello, Bob"]
Try It Yourself

How It Works

  1. Default. greeting uses "Hello" only when it is undefined (a default parameter).
  2. Leak. .map passes the index 0, 1 as greeting.
  3. Fix. With R.unary, greeting stays undefined, so the default kicks in.

Example 4 — unary vs binary vs nAry

Same function, three limits: one, two, or n arguments.

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

console.log(R.unary(three)(1, 2, 3));    // → [1, undefined, undefined]
console.log(R.binary(three)(1, 2, 3));   // → [1, 2, undefined]
console.log(R.nAry(3, three)(1, 2, 3));  // → [1, 2, 3]
Try It Yourself

How It Works

  1. unary. Only 1 gets through; b and c are undefined.
  2. binary. R.binary lets two through: 1, 2.
  3. nAry. R.nAry(3, …) lets all three through.
  4. Rule. R.unary(fn) is just R.nAry(1, fn).

Example 5 — R.map vs R.addIndex(R.map)

R.map is already safe. Its indexed version is not — that’s where unary helps in Ramda code.

Ramda
const nums = ["10", "10", "10"];
const mapIndexed = R.addIndex(R.map);

console.log(R.map(parseInt, nums));               // → [10, 10, 10]
console.log(mapIndexed(parseInt, nums));          // → [10, NaN, 2]
console.log(mapIndexed(R.unary(parseInt), nums)); // → [10, 10, 10]
Try It Yourself

How It Works

  1. R.map. R.map calls parseInt(value) only, so it works.
  2. addIndex. R.addIndex(R.map) also passes the index — the radix bug returns.
  3. Fix. R.unary(parseInt) drops the index again.

Browser & Runtime Support

R.unary has been in Ramda since v0.2.0. Ramda’s browser build is plain ES5, so it runs in any modern browser and in Node.js / Bun / Deno with npm install ramda.

✓ Stable · Ramda 0.2.0+

R.unary()

A plain function wrapper, so no special browser API is needed. The examples use ES2015 arrow functions and default parameters, supported by every evergreen browser.

100% With Ramda 0.2.0+
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.unary Ramda 0.2.0+

Bottom line: Safe for production with any modern Ramda version. The labs on this page use [email protected].

Frequently Asked Questions

R.unary(fn) returns a new function that passes only its first argument to fn and ignores the rest. The wrapper has length 1. Docs sample: R.unary(takesTwoArgs)(1, 2) //=> [1, undefined].
Array map calls the callback with (value, index, array). parseInt reads the index as its radix, so you get parseInt('10', 0), parseInt('10', 1) and parseInt('10', 2). Wrapping it as R.unary(parseInt) keeps only the value and gives [10, 10, 10].
No. R.map already calls the function with just one argument, so R.map(parseInt) works. You need unary with native .map, .forEach, or R.addIndex(R.map), which pass extra arguments.
R.unary(fn) keeps 1 argument, R.binary(fn) keeps 2, and R.nAry(n, fn) keeps n (0 to 10). R.unary(fn) is the same as R.nAry(1, fn).
No. Extra arguments are thrown away, not saved for a later call. R.unary(fn)(1, 2) runs fn(1) immediately.
No. R.unary has been a stable Ramda function helper since v0.2.0 — not deprecated, experimental, or non-standard.

Next: R.uncurryN()

Learn how to turn a curried function back into one that takes all its arguments at once.

R.uncurryN() 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.

6 people found this page helpful