Ramda.js R.transduce() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.transduce(xf, step, acc, list) sends each item through a recipe of steps (the transducer xf, such as map → filter → take), then combines the survivors with step, starting from acc (official Ramda docs). It does the work of several list functions plus R.reduce in one pass, with no in-between arrays.

Added in v0.12.0: R.transduce is stable — not deprecated, experimental, or non-standard. Warning: only functions that work as transducers (like map, filter, take) can go in the recipe; R.sort or R.reverse throw.

Syntax

Call R.transduce. Start with this line.

Ramda
R.transduce(xf, step, acc, list) (curried, 4 arguments) Type (c → c) → ((a, b) → a) → a → [b] → a
CallWhat it does
R.transduce(xf, step, acc, list) (curried, 4 arguments) Type (c → c) → ((a, b) → a) → a → [b] → aPrimary signature.
R.transduce(...)Call the list helper.

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

Library declarations
Ramda
R.transduce(xf, step, acc, list) (curried, 4 arguments) Type (c → c) → ((a, b) → a) → a → [b] → a

Parameters

ParameterDescription
xfRequired. The transducer: one stage like R.map(fn), or several joined with R.compose
stepRequired. Combines (acc, item) into the next accumulator
accRequired. The starting value; also the result if no items get through
listOptional. An array or other iterable; omit it to get a reusable function

Return Value

Return ValueDescription
*The value returned by R.transduce().

Ramda Examples

Example 1 — Official Samples

Add 1 and keep two items, then find the first odd number in 0–99 — both samples from the Ramda docs.

Ramda
const transducer = R.compose(R.map(R.add(1)), R.take(2));
console.log(R.transduce(transducer, R.flip(R.append), [], [1, 2, 3, 4]));   // [2, 3]

const isOdd = x => x % 2 !== 0;
const firstOdd = R.compose(R.filter(isOdd), R.take(1));
console.log(R.transduce(firstOdd, R.flip(R.append), [], R.range(0, 100)));  // [1]
Try It Yourself

How It Works

  1. Recipe 1. R.map(R.add(1)) adds 1, then R.take(2) lets only two items through: [2, 3].
  2. Step. R.flip(R.append) adds each surviving item to the end of the [] accumulator.
  3. Recipe 2. R.filter(isOdd) skips 0, lets 1 through, and R.take(1) is then full.
  4. Early stop. Only 0 and 1 are read out of 100 numbers — the rest are never touched.

Example 2 — Stage Order Changes the Result

Sum with R.add, and swap the two stages to see that the left stage runs first.

Ramda
const nums = [1, 2, 3, 4, 5, 6];
const isEven = x => x % 2 === 0;
const times10 = x => x * 10;

const filterFirst = R.compose(R.filter(isEven), R.map(times10));
const mapFirst = R.compose(R.map(times10), R.filter(isEven));

console.log(R.transduce(filterFirst, R.add, 0, nums));   // 120
console.log(R.transduce(mapFirst, R.add, 0, nums));      // 210
Try It Yourself

How It Works

  1. Filter first. Only 2, 4, 6 pass, then become 20, 40, 60; R.add sums them to 120.
  2. Map first. Every number becomes 10–60 first, and all of those are even, so the sum is 210.
  3. Left to right. With transducers, R.compose runs its left stage first — unlike normal R.compose.
  4. Sum step. R.add with a start of 0 turns the survivors into one number instead of a list.

Example 3 — Active Users to Names

Filter records and pull out a field in one pass.

Ramda
const users = [
  { name: 'Ada', active: true },
  { name: 'Bob', active: false },
  { name: 'Cy', active: true }
];

const activeNames = R.compose(
  R.filter(R.propEq(true, 'active')),
  R.map(R.prop('name'))
);

console.log(R.transduce(activeNames, R.flip(R.append), [], users));   // ['Ada', 'Cy']
Try It Yourself

How It Works

  1. Filter. R.propEq(true, 'active') lets Ada and Cy through and drops Bob.
  2. Map. R.prop('name') turns each surviving record into its name.
  3. One pass. Each user is filtered and mapped before the next user is read, so no filtered copy of users is made.
  4. Collect. R.flip(R.append) builds the final list ['Ada', 'Cy'].

Example 4 — Stop Early on a Big List

Count how many squares are computed with a transducer versus plain map then take.

Ramda
const nums = R.range(1, 1001);   // 1 to 1000
let calls = 0;
const square = x => { calls += 1; return x * x; };

const xf = R.compose(R.map(square), R.take(3));
console.log(R.transduce(xf, R.flip(R.append), [], nums));   // [1, 4, 9]
console.log(calls);                                         // 3

calls = 0;
console.log(R.take(3, R.map(square, nums)));                // [1, 4, 9]
console.log(calls);                                         // 1000
Try It Yourself

How It Works

  1. Counter. square adds 1 to calls every time it runs.
  2. Transducer. After three items pass, R.take(3) is full and stops the walk — only 3 squares are computed.
  3. Plain version. R.map squares all 1000 numbers first, then R.take throws 997 away.
  4. Same answer. Both give [1, 4, 9]; the transducer just does far less work.

Example 5 — One Recipe, Three Results

Reuse the same transducer with R.into and with different steps.

Ramda
const nums = [1, 2, 3, 4];
const xf = R.compose(R.map(R.add(1)), R.take(2));

console.log(R.transduce(xf, R.flip(R.append), [], nums));   // [2, 3]
console.log(R.into([], xf, nums));                          // [2, 3]
console.log(R.transduce(xf, R.add, 0, nums));               // 5
Try It Yourself

How It Works

  1. Recipe. xf only says “add 1, keep two” — it does not decide where results go.
  2. Array. R.transduce with R.flip(R.append) and [] collects [2, 3].
  3. Shortcut. R.into([], xf, nums) does the same without writing the step.
  4. Sum. Swapping the step to R.add with 0 turns the same survivors into 2 + 3 = 5.

Browser & Runtime Support

R.transduce() has been in Ramda since v0.12.0. Transducers are plain JavaScript objects and loops, so they work wherever Ramda loads.

✓ Ramda 0.12.0+ · Any JS runtime

Ramda.js R.transduce()

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

100% With Ramda 0.12+
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.transduce() Universal

Bottom line: Safe in any project on Ramda 0.12 or newer. Arrays work in every runtime; iterating Sets and other iterables needs an engine with Symbol.iterator (all modern browsers and Node). These labs load [email protected].

Frequently Asked Questions

R.transduce(xf, step, acc, list) sends each item through a composed recipe of steps such as R.map, R.filter, and R.take, then combines the survivors with step, starting from acc. The official sample R.transduce(R.compose(R.map(R.add(1)), R.take(2)), R.flip(R.append), [], [1, 2, 3, 4]) returns [2, 3].
A transducer is a reusable processing recipe, built by composing transducer-capable functions like R.map(fn), R.filter(pred), and R.take(n). It describes what to do with each item but not where the results go; R.transduce or R.into supplies that.
With transducers, R.compose(R.map(f), R.filter(g)) applies f first, then g, to each item. Each transducer wraps the next one, so the left-most step sees the item first. This is the opposite of how R.compose reads for ordinary functions.
The step receives (accumulator, item), but R.append takes (item, list). R.flip swaps the two arguments so the item is appended to the accumulator. Passing R.append directly returns a broken nested array instead of an error.
R.into(acc, xf, list) is a shortcut that picks the right way to add items to an array, string, or object for you. R.transduce makes you pass the step function, so it can produce anything, such as a sum with R.add or the largest value with R.max.
No. R.transduce has been part of Ramda since v0.12.0 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.transpose()

Turn rows into columns in a list of lists.

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