Ramda’s R.and() answers a logic question: what is the leftover of JavaScript && for these two values? You pass a, then b. You get back a && b: the first argument if it is falsy, otherwise the second. When both inputs are booleans, that is ordinary AND. Native && is an operator, so you cannot drop it into R.map or R.reduce. R.and is a function, arity 2, automatically curried, so R.and(true) is already a function of one value.
The official sample is the whole idea. Four boolean pairs: only true with true is true. Need OR of two values? That is R.or. Need AND of two predicate functions? That is R.both. Need AND of a list of predicates? That is R.allPass. Previous Logic helper is R.allPass. Next is R.anyPass.
Syntax
Call R.and. Start with this line.
Ramda
R.and(a, b)
Call
What it does
R.and(a, b)
Primary signature.
R.and(...)
Call the logic helper.
Prefer import { and } from "ramda" when you want a named import.
Library declarations
Ramda
R.and(a, b)
Parameters
Parameter
Description
a
Required. Any. Left-hand value. Returned as-is when it is falsy (false, 0, '', null, undefined, NaN).
b
Required. Any. Right-hand value. Returned when a is truthy. Never evaluated as a function — it is just a value.
Return Value
Return Value
Description
Any
The leftover of a && b. Boolean only when both inputs are booleans. Neither argument is mutated.
Ramda Examples
📚 Getting Started
The official Ramda boolean table, then the same idea compared with or, both, and allPass.
Example 1 — Official Boolean Table
When both inputs are booleans, R.and is ordinary AND. Only true with true yields true.
R.T always returns true. R.F always returns false. both ANDs those two functions. allPass ANDs a list. and never calls a function leftover — it only combines values. Previous helper is R.allPass.
📈 Practical Patterns
Falsy leftovers that are not false, then map and reduce, then why R.and exists beside &&.
Example 3 — Falsy Leftovers Are Kept
The leftover is the same as JavaScript &&. A falsy first argument is returned as-is. A truthy first argument yields the second value.
0 and '' are falsy, so they win even though they are not false. 'ok' is truthy, so the leftover is the second argument 0. Labs print empty string as "" so the line is visible.
Example 4 — Curry, Map, and Reduce
Fill the first slot. Map that leftover over flags. Fold a list with R.reduce.
Because and is arity 2, filling a leaves a function of one value for R.map. R.reduce(R.and, true, list) starts from true and ANDs every item. You cannot pass the && operator into reduce.
Example 5 — R.and vs && vs both
The operator and the helper agree on values. both is for predicates. Passing functions into and does not call them.
A function is truthy, so R.and(fnA, fnB) returns fnB without calling either. Use R.both when leftovers must run. Print typeof in the lab so the fourth line is the word function.
Compatibility
Browser Support
R.and() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Ramda 0.1.0+ · Any JS runtime
Ramda.js R.and()
Load Ramda 0.1.0 or later via CDN or npm, then call R.and with two values. No extra browser API is required.
100%With Ramda 0.1.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.and()Universal
Bottom line: Safe in any project that includes Ramda 0.1.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.and(a, b) returns a && b: the first argument if it is falsy, otherwise the second argument. When both inputs are booleans, that is ordinary AND. Added in v0.1.0. Type: a → b → a | b. Arity 2, curried.
R.and(true, true) is true. R.and(true, false) is false. R.and(false, true) is false. R.and(false, false) is false.
and ANDs two values (like &&). or ORs two values (like ||). both ANDs two predicate functions. allPass ANDs a list of predicate functions. Use and when you already have booleans or other values, not when you need to combine tests.
No. It returns the leftover of JavaScript &&. R.and(0, 5) is 0. R.and(1, 5) is 5. R.and('', 'hi') is ''. Only boolean inputs yield a boolean leftover.
&& is an operator. R.and is a curried function, so R.and(true) waits for the second value and R.reduce(R.and, true, list) folds a list. You cannot pass && into map or reduce.
No. R.and is a stable Ramda logic helper from v0.1.0. It is not deprecated, experimental, or non-standard.