Ramda.js R.or() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Logic

Definition

Ramda’s R.or() 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 truthy, otherwise the second. When both inputs are booleans, that is ordinary OR. Native || is an operator, so you cannot drop it into R.map or R.reduce. R.or is a function, arity 2, automatically curried, so R.or(false) is already a function of one value.

The official sample is the whole idea. Four boolean pairs: any true yields true; only false with false is false. Need AND of two values? That is R.and. Need OR of two predicate functions? That is R.either. Previous Logic helper is R.not. Next is R.either.

Syntax

Call R.or. Start with this line.

Ramda
R.or(a, b)
CallWhat it does
R.or(a, b)Primary signature.
R.or(...)Call the logic helper.

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

Library declarations
Ramda
R.or(a, b)

Parameters

ParameterDescription
aRequired. Any. Left-hand value. Returned as-is when it is truthy.
bRequired. Any. Right-hand value. Returned when a is falsy. Never evaluated as a function — it is just a value.

Return Value

Return ValueDescription
AnyThe 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, either, and anyPass.

Example 1 — Official Boolean Table

When both inputs are booleans, R.or is ordinary OR. Any true yields true; only false/false is false.

Ramda
R.or(true, true);
//=> true

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

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

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

How It Works

That is the docs sample from ramdajs.com. The source is a || b. Any true yields true; both must be false for false.

Example 2 — vs and, either, and anyPass

or and and take values. either and anyPass take functions, then you call the leftover.

Ramda
R.or(true, false);
//=> true

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

R.either(R.T, R.F)(0);
//=> true

R.anyPass([R.F, R.T])(0);
//=> true
Try It Yourself

How It Works

R.T always returns true. R.F always returns false. either ORs those two functions. anyPass ORs a list. or never calls a function leftover — it only combines values. Previous helper is R.not.

📈 Practical Patterns

Truthy leftovers that are not true, then map and reduce, then why R.or exists beside ||.

Example 3 — Truthy Leftovers Are Kept

The leftover is the same as JavaScript ||. A truthy first argument is returned as-is. A falsy first argument yields the second value.

Ramda
R.or(0, 5);
//=> 5

R.or(1, 5);
//=> 1

R.or('', 'hi');
//=> 'hi'

R.or('ok', 0);
//=> 'ok'
Try It Yourself

How It Works

1 and 'ok' are truthy, so they win even though they are not true. 0 and '' are falsy, so the second argument is returned. 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.

Ramda
R.or(false)(true);
//=> true

R.map(R.or(false), [true, false]);
//=> [true, false]

R.reduce(R.or, false, [false, false, true]);
//=> true

R.reduce(R.or, false, [false, false, false]);
//=> false
Try It Yourself

How It Works

Because or is arity 2, filling a leaves a function of one value for R.map. R.reduce(R.or, false, list) starts from false and ORs every item. You cannot pass the || operator into reduce.

Example 5 — R.or vs || vs either

The operator and the helper agree on values. either is for predicates. Passing functions into or does not call them.

Ramda
true || false;
//=> true

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

R.either(R.gt(R.__, 0), R.lt(R.__, 10))(5);
//=> true

typeof R.or(R.gt(R.__, 0), R.lt(R.__, 10));
//=> 'function'
Try It Yourself

How It Works

A function is truthy, so R.or(fnA, fnB) returns fnA without calling either. Use R.either when leftovers must run. Print typeof in the lab so the fourth line is the word function.

Browser Support

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

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

100% With Ramda 0.1.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.or() 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.or(a, b) returns a || b: the first argument if it is truthy, otherwise the second argument. When both inputs are booleans, that is ordinary OR. Added in v0.1.0. Type: a → b → a | b. Arity 2, curried.
R.or(true, true) is true. R.or(true, false) is true. R.or(false, true) is true. R.or(false, false) is false.
or ORs two values (like ||). and ANDs two values (like &&). either ORs exactly two predicate functions. anyPass ORs a list of predicate functions. Use or when you already have booleans or other values, not when you need to combine tests.
No. It returns the leftover of JavaScript ||. R.or(0, 5) is 5. R.or(1, 5) is 1. R.or('', 'hi') is 'hi'. Only boolean inputs yield a boolean leftover.
|| is an operator. R.or is a curried function, so R.or(false) waits for the second value and R.reduce(R.or, false, list) folds a list. You cannot pass || into map or reduce.
No. R.or is a stable Ramda logic helper from v0.1.0. It is not deprecated, experimental, or non-standard.

Continue to R.either()

Learn how to OR two predicate functions using Ramda R.either().

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