Ramda.js R.subtract() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Math

Definition

Ramda’s R.subtract() subtracts its second argument from its first. It returns a - b, but curried. The official docs sample is R.subtract(10, 8) → 2. Added in v0.1.0. See also R.add.

Because subtraction is not commutative, the docs show both placeholder styles: R.subtract(R.__, 5) for “minus five,” and R.subtract(90) for “ninety minus this” (a complementary angle).

Syntax

Call R.subtract. Start with this line.

Ramda
R.subtract(a, b)
CallWhat it does
R.subtract(a, b)Primary signature.
R.subtract(...)Call the math helper.

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

Library declarations
Ramda
R.subtract(a, b)

Parameters

ParameterDescription
aRequired. the minuend (the value you subtract from). First argument.
bRequired. the subtrahend (the amount you subtract). Second argument.

Return Value

Return ValueDescription
*Returns a Number: Number(a) - Number(b).

Ramda Examples

📚 Getting Started

The official 10 - 8 sample, then the official minus5 helper.

Example 1 — The Official Docs Example

From ramdajs.com/docs/#subtract: R.subtract(10, 8) returns 2.

Ramda
R.subtract(10, 8);  //=> 2
R.subtract(8, 10);  //=> -2
R.subtract(10)(8);  //=> 2 (curried)
R.subtract(0, 5);   //=> -5
Try It Yourself

How It Works

R.subtract returns a - b. 10 - 8 is 2 — the official sample. Swapping to 8 - 10 gives -2, which is why argument order matters.

Example 2 — Official minus5 with R.__

The docs build a reusable minus-five function by filling the subtrahend and waiting for the minuend.

Ramda
var minus5 = R.subtract(R.__, 5);

minus5(17);  //=> 12
minus5(5);   //=> 0

// Without the placeholder, R.subtract(5) waits for the second number:
R.subtract(5)(17);  //=> 5 - 17  (not minus five)
Try It Yourself

How It Works

R.__ says “skip this slot.” R.subtract(R.__, 5) stores the amount 5 and waits for a. Plain R.subtract(5) stores the minuend instead, so R.subtract(5)(17) is 5 - 17, not minus five.

📈 Practical Patterns

Official complementary angles, mapping a minus helper, and pairwise differences.

Example 3 — Official Complementary Angle

Fix the first argument at 90 to get 90 - n.

Ramda
var complementaryAngle = R.subtract(90);

complementaryAngle(30);  //=> 60
complementaryAngle(72);  //=> 18
complementaryAngle(90);  //=> 0
Try It Yourself

How It Works

R.subtract(90) is a function that still needs b. Calling it with 30 computes 90 - 30, which is 60 — the official complementary-angle sample. Two angles that add to 90° are complementary; this helper finds the other one.

Example 4 — Point-Free Map with minus5

Drop the official minus5 helper into R.map to subtract 5 from every item.

Ramda
var minus5 = R.subtract(R.__, 5);

R.map(minus5, [10, 15, 20]);
//=> [5, 10, 15]
Try It Yourself

How It Works

minus5 is a one-argument function, exactly the shape R.map wants. Each list item becomes the minuend; the subtrahend stays 5.

Example 5 — Pairwise Difference with R.zipWith

Subtract matching items from two lists. Numeric strings coerce because both sides pass through Number().

Ramda
R.zipWith(R.subtract, [10, 20, 30], [1, 5, 8]);
//=> [9, 15, 22]

R.subtract("10", 8);  //=> 2
Try It Yourself

How It Works

R.zipWith calls R.subtract on each pair: 10-1, 20-5, 30-8. Unlike R.inc, which concatenates strings, R.subtract wraps both sides in Number() — so "10" - 8 is 2.

Browser Support

R.subtract() 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.1.0+ · Any JS runtime

Ramda.js R.subtract()

Load Ramda via CDN or npm, then call R.subtract(a, b). Because it only uses Number(a) - Number(b), 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.subtract() 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.subtract(a, b) returns a - b. It is Ramda's curried subtraction helper — the functional equivalent of the - operator — so it can be partially applied and dropped into point-free pipelines. Both arguments are wrapped in Number() first.
R.subtract(10, 8) returns 2. The docs also show const minus5 = R.subtract(R.__, 5) with minus5(17) returning 12, and const complementaryAngle = R.subtract(90) with complementaryAngle(30) returning 60. Added in v0.1.0. See also R.add.
Yes. R.subtract has arity 2 and is automatically curried, so R.subtract(10, 8) and R.subtract(10)(8) both return 2. Calling it with one argument returns a function that waits for the second number.
R.__ is Ramda's placeholder. R.subtract(R.__, 5) fills the second argument (the amount to subtract) and waits for the first. That is how the official minus5 helper works: minus5(17) is 17 - 5.
R.subtract returns a - b and is not commutative: R.subtract(10, 8) is 2, while R.subtract(8, 10) is -2. R.add returns a + b and does not care about order. Both wrap arguments in Number().
No. R.subtract is a stable Ramda math helper from v0.1.0. It is not deprecated, experimental, or non-standard.

Review R.add()

Addition and subtraction are a pair — add after you know how to take a difference.

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