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)
Call
What 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
Parameter
Description
f
Required. Function. First function. Called with the same arguments you later pass to the leftover. A falsy leftover skips g.
g
Required. Function. Second function. Runs only when f is truthy. Accepts Ramda's placeholder R.__.
Return Value
Return Value
Description
Function
A 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.
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.
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.
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.
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.
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.
Compatibility
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 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.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.