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)
Call
What 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
Parameter
Description
a
Required. Any. Left-hand value. Returned as-is when it is truthy.
b
Required. Any. Right-hand value. Returned when a is falsy. 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, 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.
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.
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.
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.
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.
Compatibility
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 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.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.