Ramda.js R.mergeRight() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

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)
CallWhat 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

ParameterDescription
lRequired. Object. The first record. Own keys that do not exist on the right are copied. Nested objects are not walked.
rRequired. Object. The second record. On a clash, this value is kept.

Return Value

Return ValueDescription
ObjectA 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.

Ramda
R.mergeRight({ name: 'fred', age: 10 }, { age: 40 });
//=> { name: 'fred', age: 40 }
Try It Yourself

How It Works

Copy the left object first, then overlay the right object. That is the docs example from ramdajs.com.

Example 2 — Official withDefaults

A curried left defaults object fills missing x and still lets y from the second object win.

Ramda
const withDefaults = R.mergeRight({ x: 0, y: 0 });
withDefaults({ y: 2 });
//=> { x: 0, y: 2 }
Try It Yourself

How It Works

This is the second official sample. The helper waits for the later record after you lock in the defaults.

📈 Practical Patterns

Opposite shallow winner, nested replace vs deep mix, then a defaults overlay in a pipe.

Example 3 — vs R.mergeLeft

Same two records. Flip which side wins on age.

Ramda
const person = { name: 'fred', age: 10 };
const patch = { age: 40 };

R.mergeRight(person, patch);
//=> { name: 'fred', age: 40 }
R.mergeLeft(person, patch);
//=> { age: 10, name: 'fred' }
Try It Yourself

How It Works

name is only on the person object, so both helpers keep fred. Only the clash field age changes.

Example 4 — vs R.mergeDeepRight

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

Ramda
const left = { name: 'fred', contact: { email: '[email protected]', phone: '555' } };
const right = { contact: { email: '[email protected]' } };

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

How It Works

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.

Ramda
const fillDefaults = R.mergeRight({ status: 'draft', title: '' });
const statusOf = R.pipe(
  R.mergeRight({ status: 'draft' }),
  R.prop('status')
);
const saved = { title: 'Notes', status: 'published' };

fillDefaults(saved);
//=> { status: 'published', title: 'Notes' }
statusOf(saved);
//=> 'published'
Try It Yourself

How It Works

R.mergeRight(defaults) waits for the saved record. Clash fields come from saved. Empty title on the defaults object is overwritten.

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 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.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.

Continue to R.mergeWith()

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

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