Ramda.js R.mergeLeft() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Ramda’s R.mergeLeft() answers a one-level merge question: how do I copy two records into a new object so the first 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 { age: 40 }. Right is { name: 'fred', age: 10 }. The result keeps fred and uses age 40. The second official sample curries a reset: R.mergeLeft({x: 0}) applied to {x: 5, y: 2} is {x: 0, y: 2}. Need the second record to win instead? That is R.mergeRight. Need nested objects to mix? That is R.mergeDeepLeft.

Syntax

Call R.mergeLeft. Start with this line.

Ramda
R.mergeLeft(l, r)
CallWhat it does
R.mergeLeft(l, r)Primary signature.
R.mergeLeft(...)Call the object helper.

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

Library declarations
Ramda
R.mergeLeft(l, r)

Parameters

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

Return Value

Return ValueDescription
ObjectA new object with own properties from both sides. Clash values come from l. The source objects are not mutated.

Ramda Examples

📚 Getting Started

The official age overlay, then the official curried reset.

Example 1 — Official age overlay

Left age wins. name exists only on the right and is kept.

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

How It Works

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

Example 2 — Official resetToDefault

A curried left patch resets x and still keeps y.

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

How It Works

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

📈 Practical Patterns

Opposite shallow winner, nested replace vs deep mix, then a status patch in a pipe.

Example 3 — vs R.mergeRight

Same two records. Flip which side wins on age.

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

R.mergeLeft(patch, person);
//=> { name: 'fred', age: 40 }
R.mergeRight(patch, person);
//=> { 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.mergeDeepLeft

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

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

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

How It Works

Object.assign copies the nested object by reference into a new parent, then the left nested object replaces it. The original left object is not mutated.

Example 5 — Curry with pipe

Lock a status patch first, then read that field. Both helpers are data-last.

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

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

How It Works

R.mergeLeft(patch) waits for the saved record. title survives because it exists only on the right.

Browser Support

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

Load Ramda 0.26.0 or later via CDN or npm, then call R.mergeLeft 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.mergeLeft() 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.mergeLeft(l, r) returns a new object like { ...r, ...l }. Own keys from both records are kept. On a clash, the first object's value is used. Added in v0.26.0. Neither source object is mutated. The merge is shallow.
R.mergeLeft({ age: 40 }, { name: 'fred', age: 10 }) is { name: 'fred', age: 40 }. name exists only on the second object and is kept. age exists on both, so left 40 wins. The docs also show const resetToDefault = R.mergeLeft({ x: 0 }); resetToDefault({ x: 5, y: 2 }) is { x: 0, y: 2 }.
Both are shallow. mergeLeft is { ...r, ...l }, so the first object wins. mergeRight is { ...l, ...r }, so the second object wins.
mergeLeft replaces a nested object as a whole. mergeDeepLeft walks inside nested plain objects, so a right-only nested phone can still join while left email wins.
No. Arrays at the same key are a clash, so the left array replaces the right array. There is no deep walk.
No. R.mergeLeft is a stable Ramda object helper from v0.26.0. It is not deprecated, experimental, or non-standard. Older R.merge is the cousin of mergeRight, not this helper.

Continue to R.mergeRight()

Learn how to shallow-merge two objects so the second record wins using Ramda R.mergeRight().

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