Ramda’s R.mergeRight() answers a one-level merge question: how do I copy two records into a new object so the second record wins when a key appears twice? You pass the left object, then the right object. You get a new object. Neither source is mutated.
The official sample is the whole idea. Left is { name: 'fred', age: 10 }. Right is { age: 40 }. The result keeps fred and uses age 40. The second official sample curries defaults: R.mergeRight({x: 0, y: 0}) applied to {y: 2} is {x: 0, y: 2}. Need the first record to win instead? That is R.mergeLeft. Need nested objects to mix? That is R.mergeDeepRight.
Syntax
Call R.mergeRight. Start with this line.
Ramda
R.mergeRight(l, r)
Call
What it does
R.mergeRight(l, r)
Primary signature.
R.mergeRight(...)
Call the object helper.
Prefer import { mergeRight } from "ramda" when you want a named import.
Library declarations
Ramda
R.mergeRight(l, r)
Parameters
Parameter
Description
l
Required. Object. The first record. Own keys that do not exist on the right are copied. Nested objects are not walked.
r
Required. Object. The second record. On a clash, this value is kept.
Return Value
Return Value
Description
Object
A new object with own properties from both sides. Clash values come from r. The source objects are not mutated.
Ramda Examples
📚 Getting Started
The official age overlay, then the official curried defaults helper.
Example 1 — Official age overlay
Right age wins. name exists only on the left and is kept.
Object.assign copies the nested object by reference into a new parent, then the right nested object replaces it. The original left object is not mutated.
Example 5 — Curry with pipe
Lock defaults first, then read the status field. The second object wins, so published stays published.
R.mergeRight(defaults) waits for the saved record. Clash fields come from saved. Empty title on the defaults object is overwritten.
Compatibility
Browser Support
R.mergeRight() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Ramda 0.26.0+ · Any JS runtime
Ramda.js R.mergeRight()
Load Ramda 0.26.0 or later via CDN or npm, then call R.mergeRight with two objects. No extra browser API is required.
100%With Ramda 0.26.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.mergeRight()Universal
Bottom line: Safe in any project that includes Ramda 0.26.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.mergeRight(l, r) returns a new object like { ...l, ...r }. Own keys from both records are kept. On a clash, the second object's value is used. Added in v0.26.0. Neither source object is mutated. The merge is shallow.
R.mergeRight({ name: 'fred', age: 10 }, { age: 40 }) is { name: 'fred', age: 40 }. name exists only on the first object and is kept. age exists on both, so right 40 wins. The docs also show const withDefaults = R.mergeRight({ x: 0, y: 0 }); withDefaults({ y: 2 }) is { x: 0, y: 2 }.
Both are shallow. mergeRight is { ...l, ...r }, so the second object wins. mergeLeft is { ...r, ...l }, so the first object wins.
mergeRight replaces a nested object as a whole. mergeDeepRight walks inside nested plain objects, so a left-only nested phone can still join while right email wins.
No. Arrays at the same key are a clash, so the right array replaces the left array. There is no deep walk.
No. R.mergeRight is a stable Ramda object helper from v0.26.0. It is not deprecated, experimental, or non-standard. Older R.merge behaved like this helper and was later renamed mergeRight.