Ramda.js R.zipWith() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.zipWith(fn, list1, list2) walks two lists side by side and calls fn on the items at the same position. The answers form a new list, which stops when the shorter list runs out (official Ramda docs).

Stable since v0.1.0: R.zipWith is not deprecated, experimental, or non-standard. JavaScript arrays have no built-in zipWith, so this helper fills a real gap.

Syntax

Call R.zipWith. Start with this line.

Ramda
R.zipWith(fn, list1, list2) or R.zipWith(fn)(list1)(list2)
CallWhat it does
R.zipWith(fn, list1, list2) or R.zipWith(fn)(list1)(list2)Primary signature.
R.zipWith(...)Call the list helper.

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

Library declarations
Ramda
R.zipWith(fn, list1, list2) or R.zipWith(fn)(list1)(list2)

Parameters

ParameterDescription
fnRequired. Called as fn(list1[i], list2[i]); its return value becomes item i
list1Required. Supplies the first argument of every call
list2Optional. Supplies the second argument; omit it to get a reusable function

Return Value

Return ValueDescription
*A new array of min(list1.length, list2.length) results

Ramda Examples

Example 1 — Official: Combine Items by Position

The Ramda docs use a placeholder f. Here f joins each number with the letter at the same index.

Ramda
const f = (x, y) => x + y;

console.log(R.zipWith(f, [1, 2, 3], ['a', 'b', 'c']));
// ['1a', '2b', '3c']
Try It Yourself

How It Works

  1. Index 0. Ramda calls f(1, 'a'), and 1 + 'a' is '1a'.
  2. Index 1. f(2, 'b') gives '2b'.
  3. Index 2. f(3, 'c') gives '3c'.
  4. Result. One call per position, so 3 results: [f(1, 'a'), f(2, 'b'), f(3, 'c')].

Example 2 — Add Two Lists (the Shorter Wins)

Pass R.add to sum same-position numbers. Uneven lists stop early.

Ramda
console.log(R.zipWith(R.add, [1, 2, 3], [10, 20, 30]));  // [11, 22, 33]
console.log(R.zipWith(R.add, [1, 2, 3], [10, 20]));      // [11, 22]
console.log(R.zipWith(R.add, [], [10, 20]));             // []
Try It Yourself

How It Works

  1. Sum. R.add runs at each index: 1 + 10, 2 + 20, 3 + 30.
  2. Shorter length. In the second call min(3, 2) is 2, so 3 is never added.
  3. Empty. An empty list has length 0, so fn never runs and the result is [].

Example 3 — Argument Order Matters

Items from list1 are always the first argument. Swap the lists and R.subtract flips its answer.

Ramda
const prices = [100, 250, 40];
const discounts = [10, 50, 0];

console.log(R.zipWith(R.subtract, prices, discounts));
// [90, 200, 40]

console.log(R.zipWith(R.subtract, discounts, prices));
// [-90, -200, -40]
Try It Yourself

How It Works

  1. Calls. Ramda calls subtract(prices[i], discounts[i]): 100 - 10, 250 - 50, 40 - 0.
  2. Result. Each price minus its discount gives [90, 200, 40].
  3. Swap. With the lists swapped, the calls become 10 - 100 and so on, so every answer turns negative.
  4. Rule. R.subtract(a, b) means a - b, so put the list you subtract from first.

Example 4 — Build an Object for Each Position

The function can return anything. Here it turns each name and score into a small record.

Ramda
const names = ['Ana', 'Ben', 'Cy'];
const scores = [90, 85, 77];

const toRecord = (name, score) => ({ name, score });

console.log(R.zipWith(toRecord, names, scores));
// [{ name: 'Ana', score: 90 }, { name: 'Ben', score: 85 }, { name: 'Cy', score: 77 }]
Try It Yourself

How It Works

  1. Combiner. toRecord is an arrow function that takes a name and a score.
  2. Object. ({ name, score }) builds { name: name, score: score }; the parentheses tell JavaScript it is an object, not a function body.
  3. Per index. Ramda calls toRecord('Ana', 90), then toRecord('Ben', 85), then toRecord('Cy', 77).
  4. Result. A list of 3 records, made in one pass without building pairs first.

Example 5 — Day-to-Day Changes

Combine a list with its own tail to compare each item with the next one.

Ramda
const temps = [18, 21, 19, 24];

const changes = (list) => R.zipWith(R.subtract, R.tail(list), list);

console.log(R.tail(temps));   // [21, 19, 24]
console.log(changes(temps));  // [3, -2, 5]
Try It Yourself

How It Works

  1. Shift. R.tail(temps) is the same list moved one step left: each slot now holds “tomorrow”.
  2. Subtract. Ramda calls subtract(tomorrow, today): 21 - 18, 19 - 21, 24 - 19.
  3. Length. The tail is one item shorter, so the last day has no partner and drops off.
  4. Compare. The R.zip version needs a second R.map step; zipWith does it in one.

Browser & Runtime Support

R.zipWith() is a plain loop inside Ramda 0.1.0+. JavaScript arrays have no built-in zipWith; the closest native version is a.slice(0, n).map((x, i) => fn(x, b[i])) with n = Math.min(a.length, b.length), which works in every modern browser.

✓ Ramda 0.1.0+ · Any JS runtime

Ramda.js R.zipWith()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge, including older versions. Via npm it works in Node.js, Deno, and Bun.

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.zipWith() Universal

Bottom line: Safe in any project with Ramda (check with npm ls ramda). Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Deno, and Bun. These labs load [email protected].

Frequently Asked Questions

R.zipWith(fn, list1, list2) walks both lists by position and calls fn(list1[i], list2[i]) for each index. It returns a new list of the results. R.zipWith(R.add, [1, 2, 3], [10, 20, 30]) returns [11, 22, 33].
The result is cut to the shorter list, and the extra items are never passed to fn. R.zipWith(R.add, [1, 2, 3], [10, 20]) returns [11, 22]. No error is thrown.
R.zip always builds [a, b] pairs. R.zipWith lets you decide what each position becomes by calling your function. R.zip(a, b) gives the same result as R.zipWith((x, y) => [x, y], a, b).
No. Ramda calls fn with exactly two arguments, the item from list1 and the item from list2. If you need the position, use the native list1.map((x, i) => fn(x, list2[i], i)).
R.zipWith matches items by position, so [1, 2] and [10, 20] give 2 results. R.lift(R.add)([1, 2], [10, 20]) tries every combination and returns 4 results: [11, 21, 12, 22].
No. R.zipWith has been part of Ramda since v0.1.0 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.__ Placeholder

Leave a gap in a curried call and fill it in later.

R.__ 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