Ramda’s R.where() answers a spec question: does this object pass every named predicate? You pass a spec object whose own values are functions, then the test object. You get a boolean. Extra keys on the test object do not matter. A missing spec key is still tested, with undefined. Native JavaScript would write several if checks. where names those checks once, stays data-last, and curries, so R.where(spec) is already a function of one object — ready for R.filter and R.find.
The official sample is the whole idea. Four predicates must all pass: a equals 'foo', b is not 'bar', x is greater than 10, y is less than 20. Only the first docs row succeeds. Need literals instead of functions? That is R.whereEq. Need any one predicate to pass? That is R.whereAny. Need one key only? That is R.propSatisfies. Previous Object helper is R.view. Next is R.whereAny.
Syntax
Call R.where. Start with this line.
Ramda
R.where(spec, testObj)
Call
What it does
R.where(spec, testObj)
Primary signature.
R.where(...)
Call the object helper.
Prefer import { where } from "ramda" when you want a named import.
Library declarations
Ramda
R.where(spec, testObj)
Parameters
Parameter
Description
spec
Required. Object. Own properties must be predicate functions. Each is called with testObj[key]. Inherited spec keys are skipped.
testObj
Required. Object. The record under test. Extra keys are ignored. A missing spec key reads as undefined.
Return Value
Return Value
Description
Boolean
true when every own spec predicate returns a truthy leftover. Otherwise false. Neither object is mutated. An empty spec yields true.
Ramda Examples
📚 Getting Started
The official Ramda object sample, then the same idea compared with whereEq and whereAny.
Example 1 — Official pred
Four predicates must all pass. Extra keys would be ignored. One failed field is enough to yield false.
b: R.complement(R.equals('bar')) means b must not be 'bar'. x must be strictly greater than 10, so 10 fails. y must be strictly less than 20, so 20 fails. That is the docs sample from ramdajs.com.
Example 2 — vs whereEq, whereAny, and propSatisfies
Same row. where needs functions and AND. whereEq uses literals. whereAny is OR. propSatisfies tests one key.
extra is ignored by all three spec helpers. whereAny is true because b matches even though a does not. Prefer whereEq when every spec leftover is a value. Prefer where when you need ranges, complements, or other functions.
📈 Practical Patterns
Extra keys, missing fields, an empty spec, then filter and find, then why literals belong on whereEq.
Example 3 — Extra Keys, Missing Keys, Empty Spec
Extra fields do not fail the spec. A missing field still runs the predicate with undefined. An empty spec never loops, so the leftover is true.
R.gte(R.__, 18)(undefined) is false, so a missing age fails. R.where({}, null) is also true, because the loop never reads the test object. A non-empty spec on null throws.
Example 4 — Curry, Filter, and Find
Fill the spec to get a predicate of one row. Keep matching tickets. Find the first match.
Because where is arity 2, filling spec leaves a function of one object for R.filter and R.find. Row 2 fails status. Row 3 fails score. That is the docs use case: declarative constraints for list helpers.
Example 5 — Literals Belong on whereEq
A number in the spec is not a predicate. Wrap it with R.equals, or switch to whereEq.
Before v0.13.0, R.where({a: 1}) treated non-functions as equality checks. That mixed style moved to R.whereEq. Today R.where({ a: 1 }, { a: 1 }) throws because 1 is not callable. The third line is a reminder: spec values must be functions.
Compatibility
Browser Support
R.where() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Ramda 0.1.1+ · Any JS runtime
Ramda.js R.where()
Load Ramda 0.1.1 or later via CDN or npm, then call R.where with a spec of predicates and a test object. No extra browser API is required.
100%With Ramda 0.1.1+
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.where()Universal
Bottom line: Safe in any project that includes Ramda 0.1.1 or later. Spec values must be functions from 0.13.0 onward. 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.where(spec, testObj) returns true when every own property on spec is a predicate that returns true for testObj of that same key. Extra keys on the test object are ignored. Added in v0.1.1. Since v0.13.0 every spec value must be a function.
const pred = R.where({ a: R.equals('foo'), b: R.complement(R.equals('bar')), x: R.gt(R.__, 10), y: R.lt(R.__, 20) }). pred({a:'foo', b:'xxx', x:11, y:19}) is true. The other four official rows are false.
where runs predicate functions and requires all of them to pass (AND). whereEq compares spec values with R.equals instead of calling functions. whereAny is the OR cousin: one passing predicate is enough.
The predicate still runs, with undefined. R.where({ age: R.gte(R.__, 18) }, {}) is false. An empty spec {} returns true, even for null, because no predicates run.
No. Spec values must be functions. R.where({ a: 1 }, { a: 1 }) throws because 1 is not callable. Use R.whereEq({ a: 1 }, obj) or wrap with R.equals.
No. R.where is a stable Ramda object helper from v0.1.1. It is not deprecated, experimental, or non-standard.