Ramda.js R.binary() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Wraps a function of any arity in a function that accepts exactly 2 parameters. Extraneous parameters are not passed to the supplied function (official Ramda docs). The new function’s .length is always 2.

Stable since v0.2.0: R.binary is a core Ramda helper — not deprecated, experimental, or non-standard. Same idea as R.nAry(2, fn).

Syntax

Call R.binary. Start with this line.

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

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

Library declarations
Ramda
R.binary(fn)

Parameters

ParameterDescription
fnRequired. Any function to wrap (any arity, including nullary)

Return Value

Return ValueDescription
*New function guaranteed of arity 2

Ramda Examples

Example 1 — Official takesTwoArgs

Wrap a three-argument function — the sample from the Ramda docs.

Ramda
const takesThreeArgs = function (a, b, c) {
  return [a, b, c];
};

console.log(takesThreeArgs.length);     // 3
console.log(takesThreeArgs(1, 2, 3));   // [1, 2, 3]

const takesTwoArgs = R.binary(takesThreeArgs);
console.log(takesTwoArgs.length);       // 2
console.log(takesTwoArgs(1, 2, 3));     // [1, 2, undefined]
Try It Yourself

How It Works

  1. Original arity. takesThreeArgs.length is 3; all three values arrive.
  2. Wrap. R.binary returns a new function with .length === 2.
  3. Call with three. Only 1 and 2 are forwarded; c stays undefined.
  4. Same return shape. The array still has three slots — the third is empty.

Example 2 — Extra Arguments Always Dropped

A fourth argument still never reaches the wrapped function.

Ramda
const takesThreeArgs = (a, b, c) => [a, b, c];
const takesTwoArgs = R.binary(takesThreeArgs);

console.log(takesTwoArgs(1, 2, 3));    // [1, 2, undefined]
console.log(takesTwoArgs(1, 2, 3, 4)); // [1, 2, undefined]
Try It Yourself

How It Works

  1. Hard cap at two. Everything after the second argument is ignored.
  2. Same result. Passing 3 or 3, 4 does not change what fn sees.
  3. Why it helps. Callbacks from APIs often pass more args than you want.
  4. Predictable. The wrapper’s contract is always “two in.”

Example 3 — unary vs binary vs nAry

Same function, different arity caps.

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

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

How It Works

  1. Unary. Keeps only the first argument.
  2. Binary. Keeps the first two — this page’s helper.
  3. nAry(3). Forwards all three; here it matches the original.
  4. Shortcut. R.binary(fn) means R.nAry(2, fn).

Example 4 — Stop Array.map From Leaking the Array

map calls (value, index, array). Clamp to two if you only want value + index.

Ramda
const tag = (value, index, list) =>
  value + ':' + index + ':' + (list ? list.length : 'no-list');

console.log(['a', 'b'].map(tag));
// ["a:0:2", "b:1:2"]  — array leaked as 3rd arg

console.log(['a', 'b'].map(R.binary(tag)));
// ["a:0:no-list", "b:1:no-list"]
Try It Yourself

How It Works

  1. map’s contract. Every callback gets value, index, and the full array.
  2. Leak. If list is a real parameter, the array length shows up (2).
  3. Clamp. R.binary(tag) drops the third argument → list is undefined.
  4. Value + index only. Useful when a helper’s third param must stay unused.

Example 5 — parseInt Still Needs R.unary

R.binary keeps the index — which parseInt treats as a radix. Use unary instead.

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

console.log(values.map(parseInt));
// [10, NaN, 1]  — index used as radix

console.log(values.map(R.binary(parseInt)));
// [10, NaN, 1]  — still broken (index kept)

console.log(values.map(R.unary(parseInt)));
// [10, 11, 12]  ✓
Try It Yourself

How It Works

  1. The bug. map passes the index; parseInt(str, radix) misreads it.
  2. Binary is not enough. It still forwards the second argument (the index).
  3. Unary fixes it. Only the string reaches parseInt.
  4. Pick the right cap. Drop the index → unary; keep index, drop array → binary.

Browser & Runtime Support

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

✓ Ramda 0.2.0+ · Any JS runtime

Ramda.js R.binary()

Works in every modern browser and runtime where you can load Ramda (CDN or npm). Internet Explorer needs a build that targets that environment; there is no native IE API to polyfill.

100% With Ramda loaded
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.binary() Universal

Bottom line: Safe in any project that includes Ramda 0.2.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.binary(fn) wraps fn in a new function that accepts exactly two arguments. Extra arguments are not passed through. The wrapped function's .length is 2. Missing arguments stay undefined inside fn.

Next: R.bind()

Create a function bound to a given this context.

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