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)
Call
What 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
Parameter
Description
l
Required. Object. The first record. On a clash, this value is kept.
r
Required. Object. The second record. Own keys that do not exist on the left are copied. Nested objects are not walked.
Return Value
Return Value
Description
Object
A 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.
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.
R.mergeLeft(patch) waits for the saved record. title survives because it exists only on the right.
Compatibility
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 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.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.