Ramda.js R.mergeDeepRight() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Ramda’s R.mergeDeepRight() answers a nested-merge question: how do I combine two records so inner objects mix, while the second record still wins when a field is not two objects? 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 has name, age: 10, and contact.email of [email protected]. Right has age: 40 and a different nested email. The result keeps fred, age 40, and the baa address. Need the first record to win instead? That is R.mergeDeepLeft. Need a shallow overlay? That is R.mergeRight. Need a custom clash rule? That is R.mergeDeepWith or R.mergeDeepWithKey.

Syntax

Call R.mergeDeepRight. Start with this line.

Ramda
R.mergeDeepRight(lObj, rObj)
CallWhat it does
R.mergeDeepRight(lObj, rObj)Primary signature.
R.mergeDeepRight(...)Call the object helper.

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

Library declarations
Ramda
R.mergeDeepRight(lObj, rObj)

Parameters

ParameterDescription
lObjRequired. Object. The first record. Own keys that do not exist on the right are copied. Nested objects still merge.
rObjRequired. Object. The second record. On a clash that is not two nested objects, this value is kept.

Return Value

Return ValueDescription
ObjectA new object with own properties from both sides. Nested plain objects are merged recursively. The source objects are not mutated.

Ramda Examples

📚 Getting Started

The official nested merge, then the same inputs with mergeDeepLeft so the first record wins.

Example 1 — Official fred

Right age and nested email win. name exists only on the left and is kept.

Ramda
R.mergeDeepRight(
  { name: 'fred', age: 10, contact: { email: '[email protected]' } },
  { age: 40, contact: { email: '[email protected]' } }
);
//=> { name: 'fred', age: 40, contact: { email: '[email protected]' } }
Try It Yourself

How It Works

age is two numbers, so right 40 is kept. contact is two objects, so it recurses, then right email is kept. That is the docs example from ramdajs.com.

Example 2 — vs R.mergeDeepLeft

Same two records. Flip which side wins on a clash.

Ramda
const left = { name: 'fred', age: 10, contact: { email: '[email protected]' } };
const right = { age: 40, contact: { email: '[email protected]' } };

R.mergeDeepRight(left, right);
//=> { name: 'fred', age: 40, contact: { email: '[email protected]' } }
R.mergeDeepLeft(left, right);
//=> { name: 'fred', age: 10, contact: { email: '[email protected]' } }
Try It Yourself

How It Works

name is only on the left, so both helpers keep fred. Only the clash fields change: age and nested email.

📈 Practical Patterns

Shallow vs deep, extra nested keys from both sides, then a curried defaults overlay in a pipe.

Example 3 — vs R.mergeRight

Shallow merge replaces the whole contact. Deep merge keeps right email and still copies left-only city.

Ramda
const left = { name: 'fred', contact: { email: '[email protected]', city: 'Paris' } };
const right = { age: 40, contact: { email: '[email protected]' } };

R.mergeRight(left, right);
//=> { name: 'fred', contact: { email: '[email protected]' }, age: 40 }
R.mergeDeepRight(left, right);
//=> { name: 'fred', contact: { email: '[email protected]', city: 'Paris' }, age: 40 }
Try It Yourself

How It Works

R.mergeRight is Object.assign({}, left, right) in spirit: one level only. Deep merge is the helper to pick when nested extras on the left still matter.

Example 4 — Nested Keys from Both Sides

Right name and twitter win. Left-only city and role are still kept. Sources stay unchanged.

Ramda
const left = { user: { name: 'Ada', city: 'London' }, role: 'lead' };
const right = { user: { name: 'Grace', twitter: '@grace' }, active: true };
const merged = R.mergeDeepRight(left, right);

merged;
//=> { user: { name: 'Grace', city: 'London', twitter: '@grace' }, role: 'lead', active: true }
left;
//=> { user: { name: 'Ada', city: 'London' }, role: 'lead' }
right;
//=> { user: { name: 'Grace', twitter: '@grace' }, active: true }
Try It Yourself

How It Works

Recursion only copies nested objects into a new object. The original left.user and right.user objects are not assigned to.

Example 5 — Curry with pipe

Fix defaults first, then read a nested flag. User dark mode wins; default font stays.

Ramda
const defaults = { theme: { dark: false, font: 'sans' }, lang: 'en' };
const applyUser = R.mergeDeepRight(defaults);
const darkFlag = R.pipe(
  R.mergeDeepRight(defaults),
  R.path(['theme', 'dark'])
);
const user = { theme: { dark: true } };

applyUser(user);
//=> { theme: { dark: true, font: 'sans' }, lang: 'en' }
darkFlag(user);
//=> true
Try It Yourself

How It Works

R.mergeDeepRight(defaults) waits for the user object. Nested font from defaults survives because it exists only on the left.

Browser Support

R.mergeDeepRight() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.

✓ Ramda 0.24.0+ · Any JS runtime

Ramda.js R.mergeDeepRight()

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

100% With Ramda 0.24.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.mergeDeepRight() Universal

Bottom line: Safe in any project that includes Ramda 0.24.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.mergeDeepRight(lObj, rObj) returns a new object with own properties from both records. Nested plain objects are merged recursively. On a clash that is not two objects, the right value is kept. Added in v0.24.0. Neither source object is mutated.
R.mergeDeepRight({ name: 'fred', age: 10, contact: { email: '[email protected]' } }, { age: 40, contact: { email: '[email protected]' } }) is { name: 'fred', age: 40, contact: { email: '[email protected]' } }. Right age and nested email win. name exists only on the left and is kept.
Both deep-merge nested objects. mergeDeepRight keeps the second object's value on a clash. mergeDeepLeft keeps the first object's value. Keys that exist on only one side are always kept.
mergeRight is shallow: a nested contact object from the right replaces the whole left contact. mergeDeepRight walks into both contact objects, so right email can win while a left-only city is still copied.
No. Ramda treats a value as nested only when both sides are plain objects ([object Object]). Arrays, dates, and other types are a clash, so the right array replaces the left array.
No. R.mergeDeepRight is a stable Ramda object helper from v0.24.0. It is not deprecated, experimental, or non-standard.

Continue to R.mergeDeepWith()

Learn how to deep-merge two objects with a custom clash function using Ramda R.mergeDeepWith().

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