Ramda’s R.sum() takes a list of numbers and adds them all together. The official docs sample is R.sum([2, 4, 6, 8, 100, 1]) → 121. Added in v0.1.0. See also R.reduce.
Internally Ramda reduces with R.add starting from 0. That is why an empty list is 0, a one-item list returns that item, and a zero in the list just adds nothing.
Syntax
Call R.sum. Start with this line.
Ramda
R.sum(list)
Call
What it does
R.sum(list)
Primary signature.
R.sum(...)
Call the math helper.
Prefer import { sum } from "ramda" when you want a named import.
Library declarations
Ramda
R.sum(list)
Parameters
Parameter
Description
list
Required. an array of numbers. Ramda adds every item together.
Return Value
Return Value
Description
*
Returns a Number: the sum of all items.
Ramda Examples
📚 Getting Started
The official 121 sample, then the reduce equivalent.
Adding zero is a no-op, so the rest of the list still totals. Product treats zero as a wipe. Negatives subtract from the running total: 2 + -3 + 4 is 3.
Example 4 — Sum of an Object Field
Pluck a numeric property, then add the resulting list.
R.converge runs R.sum and R.length on the same list, then divides. That is 18 / 3 → 6. Reduce-with-add starts at 0, so no items leaves 0 — unlike R.mean([]), which is NaN.
Compatibility
Browser Support
R.sum() is plain JavaScript addition over a list — it runs anywhere Ramda loads: every modern browser plus Node.js. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Ramda 0.1.0+ · Any JS runtime
Ramda.js R.sum()
Load Ramda via CDN or npm, then call R.sum(list). Because it only adds numbers, behavior is identical across engines.
100%With Ramda loaded
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
R.sum()Universal
Bottom line: Safe in any project that includes Ramda. Use a CDN build such as ramda.min.js in the browser or install ramda from npm for Node.
Frequently Asked Questions
R.sum(list) adds together every number in a list and returns that single total. It is Ramda's unary list-sum helper, so you can pass it to R.pipe or R.pluck pipelines without writing a lambda.
R.sum([2, 4, 6, 8, 100, 1]) returns 121. That is the sample on ramdajs.com/docs/#sum. Added in v0.1.0. See also R.reduce.
Yes. It has arity 1 and is automatically curried. Call R.sum([2, 4, 6]) for a number. Calling R.sum() with no argument returns a function that waits for the list.
R.sum([]) returns 0 — the additive identity. Internally it is R.reduce(R.add, 0, list), and reducing with no items leaves the starter value 0. Contrast with R.product([]) which is 1, and R.mean([]) which is NaN.
R.add(a, b) takes two numbers. R.sum(list) adds every item in an array. R.sum([2, 3, 4]) is the same as R.reduce(R.add, 0, [2, 3, 4]).
No. R.sum is a stable Ramda math helper from v0.1.0. It is not deprecated, experimental, or non-standard.