R.mapAccumRight(fn, acc, list) is a map and a reduce in one, walking from the last item to the first. It carries a running value (acc) and builds a new item for every position (official Ramda docs). It returns [finalAcc, newList], and the new list keeps the original order.
Added in v0.10.0:R.mapAccumRight is stable — not deprecated, experimental, or non-standard. Warning: v0.26.0 changed the callback to (acc, value) returning [acc, value]; code written for the old (value, acc) order gives wrong results with no error.
Start carry.acc = 1 is the “+1” added to the rightmost digit.
Each digit.9 + 1 = 10 keeps digit 0 and carries 1; 1 + 1 = 2 carries 0.
Result. The final acc is the carry left over: 0 for 199, 1 for 999.
Overflow. When a carry remains, R.prepend adds it in front: 999 + 1 = [1, 0, 0, 0].
Compatibility
Browser & Runtime Support
R.mapAccumRight() has been in Ramda since v0.10.0; the current (acc, value) callback order dates from v0.26.0. It is a plain loop, so it works wherever Ramda loads.
✓ Ramda 0.26.0+ · Any JS runtime
Ramda.js R.mapAccumRight()
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.26+
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
R.mapAccumRight()Universal
Bottom line: Safe in any project on Ramda 0.26 or newer; results are identical in 0.30 and 0.32. On older Ramda, swap the callback arguments. The destructuring in these examples needs an ES2015+ engine (all modern browsers and Node). These labs load [email protected].
Frequently Asked Questions
R.mapAccumRight(fn, acc, list) walks the list from the last item to the first, carrying a running value. For each item, fn(acc, item) returns [newAcc, newItem]. The result is [finalAcc, newList]. The official sample with (a, b) => [b + a, b + a], 5, and ['1', '2', '3', '4'] returns ['12345', ['12345', '2345', '345', '45']].
Both take the same callback and return [finalAcc, newList]. R.mapAccum walks left to right, so each output depends on the items before it. R.mapAccumRight walks right to left, so each output depends on the items after it. With (acc, x) => [acc + x, acc + x] on [1, 2, 3, 4], mapAccum gives [1, 3, 6, 10] and mapAccumRight gives [10, 9, 7, 4].
Ramda writes each new item back at the same index as the item it came from. Only the processing order is right to left; the positions in the returned list match the input.
Before v0.26.0, the callback received (value, acc) and returned [value, acc], and the whole result was [list, acc]. Since v0.26.0, the callback receives (acc, value) and returns [acc, value], and the result is [acc, list], matching R.mapAccum. Older tutorials using the old order give wrong results without an error.
Use R.reduceRight when you only need one final value. Use R.mapAccumRight when you also want a value for every position, such as a running total from the right or a carry digit for each column.
No. R.mapAccumRight has been part of Ramda since v0.10.0 and is stable. It is not deprecated, experimental, or non-standard.