question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modify deepMerge behavior on arrays

See original GitHub issue

At present, when one runs deepMerge on 2 arrays, only the argument contents remains in the resulting array, the contents of calling array is lost:

import io.circe.Json, io.circe.literal._

val a1: Json = json"""[{"id": 1}, {"id": 2}, {"id": 3}]"""
val a2: Json = json"""[{"id": 4}, {"id": 5}, {"id": 6}]"""

a1.deepMerge(a2)
res4: Json = [{"id" : 4}, {"id" : 5}, {"id" : 6}]

This behavior is documented. However, could we consider changing it for arrays, and make it do the simple concatenation, like [{"id": 1}, {"id": 2}, {"id": 3}, {"id" : 4}, {"id" : 5}, {"id" : 6}]? I’d say, the current behavior is not completely intuitive.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
redarqascommented, Jul 10, 2018

A concatenation mode could be useful

0reactions
jcallincommented, Mar 1, 2022

Any reason why #1275 was closed and not merged? This would be super useful

Read more comments on GitHub >

github_iconTop Results From Across the Web

deepmerge - npm
Merging creates a new object, so that neither x or y is modified. Note: By default, arrays are merged by concatenating them.
Read more >
How to deep merge instead of shallow merge? - Stack Overflow
Performs a deep merge of objects and returns new object. Does not modify * objects (immutable) and merges arrays via concatenation.
Read more >
Creating and editing data - Puppet
A deep merge combines the keys and values of any number of hashes to return a merged hash. It contains an array of...
Read more >
Data Deep Merge — Eleventy
mergewith to combine Arrays and deep merge Objects, rather than a simple top-level merge using Object.assign . Read more at Issue #147. As...
Read more >
Lodash Documentation
Arguments. array (Array): The array to modify. values (Array): The values to remove. ... are iterated like arrays. To avoid this behavior use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found