Ramda’s R.whereEq() answers a spec question: does this object hold the same values as this spec, in R.equals terms? You pass a spec of values, then the test object. You get a boolean. Extra keys on the test object do not matter. A missing spec key is undefined, so it only matches if the spec leftover equals undefined. Native JavaScript would write several === checks. whereEq names those checks once, uses deep equality, stays data-last, and curries, so R.whereEq(spec) is already a function of one object — ready for R.filter and R.find.
The official sample is the whole idea. The spec is {a: 1, b: 2}. A row with only a fails. A row with both keys passes. A row with extra c still passes. A row whose b is 1 fails. Need ranges or complements? That is R.where. Need any one field to match? That is R.whereAny. Need one key versus a constant? That is R.propEq. Previous Object helper is R.whereAny. This is the last helper in Ramda’s Object category.
Syntax
Call R.whereEq. Start with this line.
Ramda
R.whereEq(spec, testObj)
Call
What it does
R.whereEq(spec, testObj)
Primary signature.
R.whereEq(...)
Call the object helper.
Prefer import { whereEq } from "ramda" when you want a named import.
Library declarations
Ramda
R.whereEq(spec, testObj)
Parameters
Parameter
Description
spec
Required. Object. Own properties are expected leftovers. Each is compared with testObj[key] via R.equals. Inherited spec keys are skipped because R.map walks...
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 leftover equals the matching test field. 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 where and whereAny.
Example 1 — Official pred
Every spec leftover must equal the matching field. Extra keys would be ignored. One mismatch is enough to yield false.
The spec asks for a: 1 and b: 2. A missing b is undefined, so row 1 fails. Extra c is ignored, so row 3 still passes. That is the docs sample from ramdajs.com.
Example 2 — vs where, whereAny, and propEq
Same row. whereEq and where are AND. whereAny is OR. propEq tests one key against a constant.
extra is ignored. whereEq and where agree here because wrapping values in R.equals is exactly what whereEq does. whereAny is true because b matches even though a does not. In Ramda 0.30, propEq is value then name.
📈 Practical Patterns
Extra keys, missing fields, nested R.equals, then filter and find, then why a function leftover is not called.
Example 3 — Extra Keys, Missing Keys, Nested Equals
Extra fields do not fail the spec. A missing field is undefined. Nested leftovers match by value. An empty spec never loops, so the leftover is true.
R.equals({ ok: true }, { ok: true }) is true even when the nested objects are different references. R.whereEq({}, null) is also true, because the mapped spec is empty and where 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 whereEq is arity 2, filling spec leaves a function of one object for R.filter and R.find. Row 2 fails status. Row 3 fails team. That is the docs use case: declarative constraints for list helpers.
Example 5 — Functions Belong on where
A function leftover is compared with R.equals, not called. Ranges and complements belong on where.
whereEq maps each leftover through R.equals, then calls where. A function leftover becomes R.equals(fn), which compares the function to 11 and yields false. Use R.where when the leftover must run.
Compatibility
Browser Support
R.whereEq() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Ramda 0.14.0+ · Any JS runtime
Ramda.js R.whereEq()
Load Ramda 0.14.0 or later via CDN or npm, then call R.whereEq with a spec of values and a test object. No extra browser API is required.
100%With Ramda 0.14.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.whereEq()Universal
Bottom line: Safe in any project that includes Ramda 0.14.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.whereEq(spec, testObj) returns true when every own spec key matches testObj of that same key in R.equals terms. Extra keys on the test object are ignored. It is where after mapping each spec leftover through R.equals. Added in v0.14.0.
const pred = R.whereEq({ a: 1, b: 2 }). pred({a:1}) is false. pred({a:1, b:2}) is true. pred({a:1, b:2, c:3}) is true. pred({a:1, b:1}) is false.
whereEq compares spec values with R.equals (AND). where runs predicate functions (AND). whereAny runs predicate functions but needs only one pass (OR).
That field is undefined, so it matches only if the spec leftover equals undefined. R.whereEq({ a: 1 }, {}) is false. An empty spec {} returns true, even for null, because no keys need to match.
You can, but they are compared with R.equals, not called. R.whereEq({ score: R.gt(R.__, 10) }, { score: 11 }) is false. Use R.where when leftovers must be predicates.
No. R.whereEq is a stable Ramda object helper from v0.14.0. It is not deprecated, experimental, or non-standard.