Ramda Logic Methods
About This Index
This page is the Ramda Logic index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn the Ramda overview on /ramdajs. Use this page when you need a logic API such as R.and(), R.ifElse(), or R.when().
Start with R.and(), R.or(), and R.not()—then R.ifElse() and R.when() for branching in pipelines.
How to Call a Logic Method
Import R (or a named helper)—combine values, predicates, or branches with data last:
const R = require("ramda");
R.and(true, false); // false
R.or(null, "ok"); // "ok"
R.not(true); // false
const isEven = n => n % 2 === 0;
const gt10 = n => n > 10;
R.both(isEven, gt10)(12); // true
R.allPass([isEven, gt10])(12); // true
R.ifElse(isEven, R.inc, R.dec)(3); // 2
R.when(isEven, R.inc)(4); // 5
R.defaultTo(0, null); // 0 Ramda Logic Methods Table
All Logic method guides in this Ramda tutorial series (19 tutorials).
Getting Started
6 methodsValue-level boolean helpers and the first two-predicate combiners in a Ramda tutorial.
| Method | Description | Tutorial |
|---|---|---|
R.and() | Return the first falsy value, or the second value when both are truthy. Works on values, not predicates. | Try it |
R.or() | Return the first truthy value, or the second when the first is falsy. Works on values. | Try it |
R.not() | Invert a boolean or truthy/falsy value directly. | Try it |
R.xor() | Exclusive OR for two values. True when exactly one side is truthy. | Try it |
R.both() | AND exactly two predicates. Think of it as the two-predicate cousin of R.allPass(). | Try it |
R.either() | OR exactly two predicates. True when either predicate passes. | Try it |
Predicate Combiners
3 methodsBuild bigger checks from smaller predicate functions — allPass, anyPass, complement.
| Method | Description | Tutorial |
|---|---|---|
R.allPass() | Combine many predicates with AND. Returns one predicate that passes only when every test passes. | Try it |
R.anyPass() | Combine many predicates with OR. One passing predicate is enough. | Try it |
R.complement() | Invert a predicate result. Build a not-version of an existing test function. | Try it |
Branching & Flow
5 methodsChoose branches, conditionally transform values, or loop until a condition passes.
| Method | Description | Tutorial |
|---|---|---|
R.cond() | Run predicate/result pairs in order and use the first branch that matches. | Try it |
R.ifElse() | Choose one of two functions based on a predicate result. | Try it |
R.when() | Run a transform only when the predicate is true. | Try it |
R.unless() | Run a transform only when the predicate is false. | Try it |
R.until() | Repeat a function until the predicate becomes true. | Try it |
Fallbacks
1 methodProvide safe default values when incoming data is null, undefined, or NaN.
| Method | Description | Tutorial |
|---|---|---|
R.defaultTo() | Provide a fallback when the value is null, undefined, or NaN. | Try it |
Emptiness Checks
2 methodsTest whether arrays, strings, or objects are empty or not empty.
| Method | Description | Tutorial |
|---|---|---|
R.isEmpty() | Check whether a list, string, or object is empty. | Try it |
R.isNotEmpty() | Check whether a list, string, or object has content. | Try it |
Property Predicate Helpers
2 methodsRun predicates against one property or a nested path inside an object.
| Method | Description | Tutorial |
|---|---|---|
R.pathSatisfies() | Run a predicate on a nested property found by a path. | Try it |
R.propSatisfies() | Run a predicate on one named property of an object. | Try it |
Frequently Asked Questions
Start with R.and()
Open the and guide—syntax, examples, and FAQs.
16 people found this page helpful
