Ramda.js R.sum() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Math

Definition

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)
CallWhat 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

ParameterDescription
listRequired. an array of numbers. Ramda adds every item together.

Return Value

Return ValueDescription
*Returns a Number: the sum of all items.

Ramda Examples

📚 Getting Started

The official 121 sample, then the reduce equivalent.

Example 1 — The Official Docs Example

From ramdajs.com/docs/#sum: R.sum([2, 4, 6, 8, 100, 1]) returns 121.

Ramda
R.sum([2, 4, 6, 8, 100, 1]);  //=> 121
R.sum([2, 3, 4]);             //=> 9
R.sum([10]);                  //=> 10
R.sum([]);                    //=> 0
Try It Yourself

How It Works

2 + 4 + 6 + 8 + 100 + 1 is 121 — the official sample. A one-item list is that item. An empty list leaves the starter value 0.

Example 2 — Same as R.reduce(R.add, 0)

The docs point to R.reduce. Sum is that fold with an add step and starter 0.

Ramda
R.sum([2, 3, 4]);
//=> 9

R.reduce(R.add, 0, [2, 3, 4]);
//=> 9

R.add(2, 3);
//=> 5
Try It Yourself

How It Works

R.sum is the named shortcut for reducing a list with add. R.add(2, 3) is only two numbers — use it when you do not have an array.

📈 Practical Patterns

Zeros vs product, pluck pipelines, and building a mean from sum.

Example 3 — A Zero Does Not Wipe the Sum

A 0 in the list adds nothing. Product still becomes 0.

Ramda
R.sum([2, 0, 5]);       //=> 7
R.product([2, 0, 5]);   //=> 0
R.sum([2, -3, 4]);      //=> 3
Try It Yourself

How It Works

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.

Ramda
var players = [
  { name: "Ada", score: 10 },
  { name: "Lin", score: 20 },
  { name: "Sam", score: 30 }
];

R.pipe(R.pluck("score"), R.sum)(players);
//=> 60
Try It Yourself

How It Works

R.pluck("score") builds [10, 20, 30]. R.sum totals that list to 60. Both steps are unary, so they drop into R.pipe with no lambdas.

Example 5 — Average from Sum, Plus Empty Identity

R.converge can divide a sum by a length — the same idea as R.mean. An empty list still sums to 0.

Ramda
var average = R.converge(R.divide, [R.sum, R.length]);

average([2, 7, 9]);  //=> 6
R.mean([2, 7, 9]);   //=> 6
R.sum([]);           //=> 0
Try It Yourself

How It Works

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.

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All 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.

Continue to R.product()

Learn list multiplication after you know how to add every number.

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