Ramda.js R.dec() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Math

Definition

Ramda’s R.dec() takes a number and returns that number minus one. The official docs sample is a single call: R.dec(42) → 41. Added in v0.9.0. See also R.inc.

Because it is a first-class function, you can drop it into pipelines instead of writing n => n - 1. Internally Ramda computes n - 1, so JavaScript’s subtraction rules apply — numeric strings coerce, and invalid values become NaN.

Syntax

Call R.dec. Start with this line.

Ramda
R.dec(n)
CallWhat it does
R.dec(n)Primary signature.
R.dec(...)Call the math helper.

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

Library declarations
Ramda
R.dec(n)

Parameters

ParameterDescription
nRequired. the value to decrement. Ramda computes n - 1.

Return Value

Return ValueDescription
*Returns a Number: n - 1.

Ramda Examples

📚 Getting Started

The official decrement, then map it over a list.

Example 1 — The Official Docs Example

From ramdajs.com/docs/#dec: R.dec(42) returns 41.

Ramda
R.dec(42);  //=> 41
R.dec(1);   //=> 0
R.dec(0);   //=> -1
R.dec(-4);  //=> -5
Try It Yourself

How It Works

R.dec returns n - 1. With 42 that is 41 — the official sample. Zero becomes -1. Negatives keep going down.

Example 2 — Point-Free Map

Pass R.dec to R.map — no arrow function needed.

Ramda
R.map(R.dec, [3, 2, 1]);
//=> [2, 1, 0]

R.pipe(R.dec, R.dec)(5);
//=> 3
Try It Yourself

How It Works

R.map wants a one-argument function. R.dec already is one, so each list item loses 1. R.pipe(R.dec, R.dec) subtracts 1 twice.

📈 Practical Patterns

Coercion vs increment, object fields, and R.useWith.

Example 3 — R.dec vs R.inc on Strings

Subtraction coerces numeric strings. The + in R.inc can concatenate.

Ramda
R.dec("10");   //=> 9
R.inc("10");   //=> "101"  (string + 1)
R.dec("foo");  //=> NaN
R.dec(null);   //=> -1     (null becomes 0)
Try It Yourself

How It Works

R.dec is implemented as n - 1, so "10" becomes the number 9. R.inc is n + 1, and + concatenates the string. Pass real numbers when you can.

Example 4 — Decrement an Object Field

R.evolve applies a function to a named property and returns a new object.

Ramda
var player = { name: "moe", lives: 3 };

R.evolve({ lives: R.dec }, player);
//=> { name: "moe", lives: 2 }
Try It Yourself

How It Works

R.evolve copies the object and runs R.dec on lives only. name is unchanged. The original player object is not mutated.

Example 5 — R.useWith and Math.pow

The Ramda useWith docs pair R.dec and R.inc as argument transformers.

Ramda
var powAround = R.useWith(Math.pow, [R.dec, R.inc]);

powAround(3, 4);   //=> 32   (2 ** 5)
powAround(3)(4);   //=> 32   (curried)
Try It Yourself

How It Works

R.useWith runs R.dec on the first argument and R.inc on the second, then calls Math.pow. 3 becomes 2, 4 becomes 5, and 2 ** 5 is 32 — the official useWith sample.

Browser Support

R.dec() is plain JavaScript subtraction — 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.9.0+ · Any JS runtime

Ramda.js R.dec()

Load Ramda via CDN or npm, then call R.dec(n). Because it only uses n - 1, 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.dec() 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.dec(n) returns n - 1. It is Ramda's unary decrement helper — the functional equivalent of subtracting one — so you can pass it to R.map, R.pipe, or R.evolve without writing a lambda.
R.dec(42) returns 41. That is the sample on ramdajs.com/docs/#dec. Added in v0.9.0. See also R.inc.
Yes. It has arity 1 and is automatically curried. Call R.dec(42) for a number. Calling R.dec() with no argument returns a function that waits for n.
R.dec(n) is n - 1. R.inc(n) is n + 1. Subtraction coerces numeric strings to numbers (R.dec('10') is 9). Addition with + can concatenate (R.inc('10') is '101'). Prefer R.dec / R.inc when you mean minus-one or plus-one.
R.subtract(a, b) is a curried binary helper for a - b. R.dec(n) always subtracts 1. R.subtract(n, 1) matches R.dec(n) when both arguments are numbers.
No. R.dec is a stable Ramda math helper from v0.9.0. It is not deprecated, experimental, or non-standard.

Continue to R.sum()

Total a whole list of numbers after you know how to decrement one value.

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