Ramda.js R.pair() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

A tiny list function that puts two values into a new array. R.pair(first, second) returns [first, second]. It does the same job as writing [a, b], but because it is a curried function, you can pass it to R.map, R.converge, and other helpers.

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

Syntax

Call R.pair. Start with this line.

Ramda
R.pair(first, second)
CallWhat it does
R.pair(first, second)Primary signature.
R.pair(...)Call the list helper.

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

Library declarations
Ramda
R.pair(first, second)

Parameters

ParameterDescription
firstRequired. Any value; goes to index 0
secondRequired. Any value; goes to index 1

Return Value

Return ValueDescription
*A new array [first, second]

Ramda Examples

Example 1 — Official: "foo" and "bar"

The docs sample, written normally and curried.

Ramda
console.log(R.pair("foo", "bar"));   // → ["foo", "bar"]
console.log(R.pair("foo")("bar"));   // → ["foo", "bar"]
Try It Yourself

How It Works

  1. Both values. R.pair("foo", "bar") builds the array right away.
  2. One at a time. R.pair("foo") returns a function; calling it with "bar" finishes the job.
  3. Same result. Both styles give ["foo", "bar"].

Example 2 — Build an Object From Pairs

Each pair is one [key, value] row for R.fromPairs.

Ramda
const rows = [R.pair("a", 1), R.pair("b", 2)];

console.log(R.fromPairs(rows));
// → { a: 1, b: 2 }
Try It Yourself

How It Works

  1. Pairs. rows is [["a", 1], ["b", 2]].
  2. Convert. R.fromPairs reads index 0 as the key and index 1 as the value.
  3. Result. You get the object { a: 1, b: 2 }. R.toPairs does the reverse.

Example 3 — Pair Each Word With Its Length

Use R.pair inside R.map to build one row per item.

Ramda
const names = ["Ada", "Grace"];
const rows = R.map(name => R.pair(name, name.length), names);

console.log(rows);
// → [["Ada", 3], ["Grace", 5]]
Try It Yourself

How It Works

  1. Map. R.map runs the arrow function for each name.
  2. Pair. R.pair(name, name.length) turns "Ada" into ["Ada", 3].
  3. Result. A list of pairs, ready for R.fromPairs if you want { Ada: 3, Grace: 5 }.

Example 4 — Return Two Results From a Function

Send back the smallest and largest number together, then destructure them.

Ramda
const minMax = xs => R.pair(Math.min(...xs), Math.max(...xs));

const [low, high] = minMax([4, 9, 1]);
console.log(low);    // → 1
console.log(high);   // → 9
Try It Yourself

How It Works

  1. Compute. Math.min gives 1 and Math.max gives 9.
  2. Pair. R.pair(1, 9) returns [1, 9].
  3. Unpack. const [low, high] takes index 0 and index 1 into two variables.

Example 5 — First and Last Item With R.converge

Run two functions on the same list and pair their answers.

Ramda
const ends = R.converge(R.pair, [R.head, R.last]);

console.log(ends([3, 5, 8]));
// → [3, 8]
Try It Yourself

How It Works

  1. Branch. R.converge gives [3, 5, 8] to both R.head and R.last.
  2. Results. They return 3 and 8.
  3. Join. Those two answers become the arguments of R.pair → [3, 8].

Browser & Runtime Support

R.pair was added in Ramda v0.18.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.18.0+

R.pair()

It only creates a two-item array, so no special browser API is needed. The function has not changed since it was added.

100% With Ramda 0.18.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.pair Ramda 0.18.0+

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

Frequently Asked Questions

R.pair(first, second) returns a new two-item array [first, second]. Docs sample: R.pair('foo', 'bar') //=> ['foo', 'bar'].
For a one-off value, [a, b] is fine. R.pair is a curried function, so you can pass it to R.map, R.converge, or R.zipWith, or partially apply it: R.pair('id') waits for the second value.
You get a function back, not [x, undefined]. R.pair('foo') is a function waiting for the second value, so R.pair('foo')('bar') is ['foo', 'bar'].
R.pair builds a two-item array. R.of(Array, x) wraps one value as [x]. R.objOf(key, value) builds a one-key object such as {a: 1}.
No. The array is new, but objects inside it are the same objects you passed in. Changing one changes the original too.
No. R.pair has been a stable Ramda list function since v0.18.0 — not deprecated, experimental, or non-standard.

Next: R.partition()

Learn how to split one list into two groups with a single test.

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