Ramda.js R.either() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Logic

Definition

Ramda’s R.either() answers a logic question: does at least one of these two tests 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). either names that OR 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. even checks even. 101 is odd, but it is greater than 10, so it passes. 8 is not greater than 10, but it is even, so it also passes. Need AND of two functions? That is R.both. Need OR of a list that can grow? That is R.anyPass. Need OR of two values, not two functions? That is R.or. Previous Logic helper is R.defaultTo. Next is R.ifElse.

Syntax

Call R.either. Start with this line.

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

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

Library declarations
Ramda
R.either(f, g)

Parameters

ParameterDescription
fRequired. Function. First function. Called with the same arguments you later pass to the leftover. A truthy leftover skips g.
gRequired. Function. Second function. Runs only when f is falsy. 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 greater-than-10 or even sample, then the same idea compared with both, anyPass, and or.

Example 1 — Official Greater Than 10 or Even

Both functions see the same number. One pass is enough. 101 is odd but greater than 10. 8 is not greater than 10 but even.

Ramda
const gt10 = x => x > 10;
const even = x => x % 2 === 0;
const f = R.either(gt10, even);

f(101);
//=> true

f(8);
//=> true
Try It Yourself

How It Works

101 passes gt10, so even is never needed. 8 fails gt10 and still passes because it is even. That is the docs sample from ramdajs.com. 7 would fail both tests.

Example 2 — vs both, anyPass, and or

101 is odd. either is still true. both is false. anyPass is the list form of OR. or never calls a function — it only combines two values.

Ramda
const gt10 = x => x > 10;
const even = x => x % 2 === 0;

R.either(gt10, even)(101);
//=> true

R.both(gt10, even)(101);
//=> false

R.anyPass([gt10, even])(8);
//=> true

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

How It Works

both needs both tests, so 101 (odd) is false. anyPass with two tests matches either. R.or is a different question: combine two already-known values with ||.

📈 Practical Patterns

Non-boolean leftovers from JavaScript ||, then filter and find, then curry and a placeholder.

Example 3 — Non-Boolean Leftovers

either uses ||, so the leftover is not always true or false. A truthy first function skips the second.

Ramda
R.either(R.identity, R.always(true))('ABC');
//=> 'ABC'

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

R.either(R.always(0), R.always(42))(null);
//=> 42
Try It Yourself

How It Works

The docs say the leftover is the first function if it is truthy, otherwise the second function. 'ABC' || true keeps 'ABC' and skips the second side. 0 || 42 keeps 42. That is ordinary JavaScript ||.

Example 4 — Filter and Find

Build one leftover from two field tests. Keep tickets that are open or on team blue. Find the first match.

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

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

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

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

How It Works

Filling the two functions leaves a function of one object for R.filter and R.find. Row 1 matches status. Row 2 matches team. Row 3 matches neither. The same tests with both would keep none of these three rows.

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 = x => x > 10;
const even = x => x % 2 === 0;

R.either(gt10)(even)(8);
//=> true

R.either(R.__, even)(gt10)(101);
//=> true

R.either(gt10, even)(7);
//=> false
Try It Yourself

How It Works

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

Browser Support

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

Load Ramda 0.12.0 or later via CDN or npm, then call R.either 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.either() 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.either(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 OR for exactly two functions. Added in v0.12.0. Type: (*… → Boolean) → (*… → Boolean) → (*… → Boolean). Arity 2, curried.
gt10 = x => x > 10; even = x => x % 2 === 0; f = R.either(gt10, even). f(101) is true because 101 is greater than 10. f(8) is true because 8 is even. One pass is enough. 7 would be false: not greater than 10 and not even.
either ORs exactly two functions. both ANDs exactly two functions. anyPass ORs a list of functions (use it when the list can grow). or ORs two values, not two functions.
No. It uses JavaScript ||, so the leftover can be any value. The first truthy leftover from f is returned without calling g. If f is falsy, g's leftover is returned. R.either(R.identity, R.always(true))('ABC') is 'ABC'.
No. || short-circuits. If f returns a truthy leftover, g is not called. Put the cheaper test first when one side is expensive.
No. R.either is a stable Ramda logic helper from v0.12.0. It is not deprecated, experimental, or non-standard.

Continue to R.ifElse()

Learn how to pick a branch with Ramda R.ifElse().

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