R.reduceBy(valueFn, acc, keyFn, list)groups a list by a key and reduces each group to one value, all in a single pass. keyFn names the group for every item, and valueFn(groupAcc, item) updates that group’s value (official Ramda docs). Think of it as R.groupBy and R.reduce combined.
Stable since v0.20.0:R.reduceBy is not deprecated, experimental, or non-standard. It is the general tool behind R.groupBy, R.countBy, and R.indexBy.
Syntax
Call R.reduceBy. Start with this line.
Ramda
R.reduceBy(valueFn, acc, keyFn, list) or R.reduceBy(valueFn, acc, keyFn)(list)
Call
What it does
R.reduceBy(valueFn, acc, keyFn, list) or R.reduceBy(valueFn, acc, keyFn)(list)
Primary signature.
R.reduceBy(...)
Call the list helper.
Prefer import { reduceBy } from "ramda" when you want a named import.
Library declarations
Ramda
R.reduceBy(valueFn, acc, keyFn, list) or R.reduceBy(valueFn, acc, keyFn)(list)
Parameters
Parameter
Description
valueFn
Required. Called as valueFn(groupAcc, item); returns the group's new value
acc
Required. Starting value for each new group (copied per group)
keyFn
Required. Returns the group name for an item; non-strings become string keys
list
Optional. The array to walk; omit it to get a reusable function
Return Value
Return Value
Description
*
A new object of { key: foldedValue }; the input is never changed
Ramda Examples
Example 1 — Official Names by Grade
The sample from the Ramda docs: group students by grade and keep only their names.
Pipeline.R.pipe passes the filtered list straight into totalByType.
Compatibility
Browser & Runtime Support
R.reduceBy() is plain JavaScript inside Ramda 0.20.0+. It uses no browser API, so support depends only on loading Ramda. (Native Object.groupBy only groups, and needs Chrome/Edge 117+, Firefox 119+, Safari 17.4+, or Node.js 21+.)
✓ Ramda 0.20.0+ · Any JS runtime
Ramda.js R.reduceBy()
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.20+ loaded
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.reduceBy()Universal
Bottom line: Safe in any project with Ramda 0.20.0 or later (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.reduceBy(valueFn, acc, keyFn, list) puts each item into a group named by keyFn(item), then folds every group into one value with valueFn(groupAcc, item). Each group starts from its own copy of acc. The result is an object of key to folded value.
R.groupBy always collects the original items into arrays. R.reduceBy lets you turn each group into anything: a sum, a count, a maximum, or a list of names. In fact, Ramda builds R.groupBy, R.countBy, and R.indexBy on top of R.reduceBy.
An empty object {}. No items means no keys, so the seed acc is never used. R.reduceBy(R.add, 0, R.identity, null) also returns {}. This differs from R.reduce, which returns the seed itself.
No. Every new key starts from a fresh shallow copy of acc, so a seed of [] or {} is never shared between groups or between calls. Nested objects inside the seed are still shared, so returning new values with concat or assoc is the safest habit.
Keys appear in the order each group is first seen, except integer-like keys such as '1' and '10', which JavaScript always lists in ascending order. The official sample returns B, F, A because Abby (B) comes first.
No. R.reduceBy has been a stable Ramda list function since v0.20.0. It is not deprecated, experimental, or non-standard.