Ramda.js R.both() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Logic

Definition

Ramda’s R.both() answers a logic question: do these two tests both pass for the same arguments? You pass two functions. You get back one function. Call that leftover with a value (or several values). Native JavaScript would write f(x) && g(x). both names that AND once, curries it, and short-circuits like &&. Drop the leftover into R.filter and R.find.

The official sample is the whole idea. gt10 checks greater than 10. lt20 checks less than 20. Together they accept 15 and reject 30. Need OR of two functions? That is R.either. Need AND of a list that can grow? That is R.allPass. Need AND of two values, not two functions? That is R.and. Previous Logic helper is R.anyPass. Next is R.complement.

Syntax

Call R.both. Start with this line.

Ramda
R.both(f, g)
CallWhat it does
R.both(f, g)Primary signature.
R.both(...)Call the logic helper.

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

Library declarations
Ramda
R.both(f, g)

Parameters

ParameterDescription
fRequired. Function. First function. Called with the same arguments you later pass to the leftover. A falsy leftover skips g.
gRequired. Function. Second function. Runs only when f is truthy. Accepts Ramda's placeholder R.__.

Return Value

Return ValueDescription
FunctionA curried leftover. It returns f(…) && g(…). That can be a boolean, or any leftover JavaScript && would keep (string, number, object).

Ramda Examples

📚 Getting Started

The official Ramda 10–20 range sample, then the same idea compared with either, allPass, and and.

Example 1 — Official Greater Than 10 and Less Than 20

Both functions see the same number. It must be greater than 10 and less than 20. One miss is enough to yield false.

Ramda
const gt10 = R.gt(R.__, 10);
const lt20 = R.lt(R.__, 20);
const f = R.both(gt10, lt20);

f(15);
//=> true

f(30);
//=> false
Try It Yourself

How It Works

15 passes gt10 and lt20. 30 passes gt10 but fails lt20, so AND is false. That is the docs sample from ramdajs.com. R.__ holds the first slot of gt and lt so each leftover waits for one number.

Example 2 — vs either, allPass, and and

Same 15. both and allPass are AND. either is OR. and never calls a function — it only combines two values.

Ramda
const gt10 = R.gt(R.__, 10);
const lt20 = R.lt(R.__, 20);

R.both(gt10, lt20)(15);
//=> true

R.either(gt10, lt20)(5);
//=> true

R.allPass([gt10, lt20])(15);
//=> true

R.and(true, false);
//=> false
Try It Yourself

How It Works

either is true for 5 because lt20 still passes. allPass with two tests matches both. R.and is a different question: combine two already-known values with &&.

📈 Practical Patterns

Non-boolean leftovers from the official second sample, then filter and find, then curry and a placeholder.

Example 3 — Non-Boolean Leftovers

both uses &&, so the leftover is not always true or false. A falsy first function skips the second.

Ramda
R.both(R.identity, R.always(true))(false);
//=> false

R.both(R.always(false), R.identity)('ABC');
//=> false

R.both(R.always(true), R.identity)('ABC');
//=> 'ABC'
Try It Yourself

How It Works

The docs say the leftover is the first function if it is falsy, otherwise the second function. false never calls the second side. true && 'ABC' keeps 'ABC'. That is ordinary JavaScript &&.

Example 4 — Filter and Find

Build one leftover from two field tests. Keep matching tickets. Find the first match.

Ramda
const pred = R.both(
  R.propEq('open', 'status'),
  R.propEq('blue', 'team')
);

const rows = [
  { id: 1, status: 'open', team: 'blue' },
  { id: 2, status: 'done', team: 'blue' },
  { id: 3, status: 'open', team: 'red' }
];

R.filter(pred, rows);
//=> [{ id: 1, status: 'open', team: 'blue' }]

R.find(pred, rows);
//=> { id: 1, status: 'open', team: 'blue' }
Try It Yourself

How It Works

Filling both functions leaves a function of one object for R.filter and R.find. Row 2 fails status. Row 3 fails team. The same tests with anyPass would keep all three.

Example 5 — Curry and Placeholder

Fill the first function, wait for the second, then wait for the value. A placeholder can skip the first slot.

Ramda
const gt10 = R.gt(R.__, 10);
const lt20 = R.lt(R.__, 20);

R.both(gt10)(lt20)(15);
//=> true

R.both(R.__, lt20)(gt10)(15);
//=> true

R.both(gt10, lt20)(10);
//=> false
Try It Yourself

How It Works

Arity 2 means R.both(gt10) waits for g. The docs note it takes a placeholder, so R.both(R.__, lt20) waits for f. 10 is not greater than 10, so the last call is false.

Browser Support

R.both() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.

✓ Ramda 0.12.0+ · Any JS runtime

Ramda.js R.both()

Load Ramda 0.12.0 or later via CDN or npm, then call R.both with two functions. No extra browser API is required.

100% With Ramda 0.12.0+
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.both() Universal

Bottom line: Safe in any project that includes Ramda 0.12.0 or later. Use a CDN build such as ramda.min.js in the browser or install ramda from npm for Node. These labs use [email protected].

Frequently Asked Questions

R.both(f, g) takes two functions and returns one new function. That leftover calls f and g with the same arguments and returns f(...) && g(...). It is AND for exactly two functions. Added in v0.12.0. Type: (*… → Boolean) → (*… → Boolean) → (*… → Boolean). Arity 2, curried.
gt10 = R.gt(R.__, 10); lt20 = R.lt(R.__, 20); f = R.both(gt10, lt20). f(15) is true. f(30) is false. The leftover is the first function if it is falsy, otherwise the second function. R.both(R.always(true), R.identity)('ABC') is 'ABC'.
both ANDs exactly two functions. either ORs exactly two functions. allPass ANDs a list of functions (use it when the list can grow). and ANDs two values, not two functions.
No. It uses JavaScript &&, so the leftover can be any value. The first falsy leftover from f is returned without calling g. If f is truthy, g's leftover is returned. R.both(R.always(true), R.identity)('ABC') is 'ABC'.
No. && short-circuits. If f returns a falsy leftover, g is not called. Put the cheaper test first when one side is expensive.
No. R.both is a stable Ramda logic helper from v0.12.0. It is not deprecated, experimental, or non-standard.

Continue to R.complement()

Learn how to flip a predicate with Ramda R.complement().

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