Skip to content

feat: merge function#438

Merged
stefan-gorules merged 3 commits intomasterfrom
feat/merge-function
Mar 15, 2026
Merged

feat: merge function#438
stefan-gorules merged 3 commits intomasterfrom
feat/merge-function

Conversation

@stefan-gorules
Copy link
Copy Markdown
Contributor

@stefan-gorules stefan-gorules commented Mar 11, 2026

Summary

  • Add merge function for combining arrays or objects
  • Add mergeDeep function for recursively combining nested objects

merge

Combines an array of arrays or an array of objects into a single result.

Arrays — concatenates all arrays into one:

merge([[1, 2], [3, 4], [5]]) // [1, 2, 3, 4, 5]

Objects — combines all objects, last value wins for duplicate keys:

merge([{a: 1}, {b: 2}, {c: 3}]) // {a: 1, b: 2, c: 3}
merge([{a: 1, b: 2}, {b: 3, c: 4}]) // {a: 1, b: 3, c: 4}

mergeDeep

Recursively merges an array of objects. Unlike merge, nested objects are combined rather than replaced, and nested arrays are concatenated.

Nested objects — recursively merged:

mergeDeep([{a: {x: 1}}, {a: {y: 2}}]) // {a: {x: 1, y: 2}}
mergeDeep([{a: {b: {c: 1}}}, {a: {b: {d: 2}}}]) // {a: {b: {c: 1, d: 2}}}

Nested arrays — concatenated:

mergeDeep([{tags: [1, 2]}, {tags: [3, 4]}]) // {tags: [1, 2, 3, 4]}

Scalar values — last value wins:

mergeDeep([{a: 1}, {a: 2}]) // {a: 2}

@stefan-gorules stefan-gorules merged commit 53f3b5a into master Mar 15, 2026
54 checks passed
@stefan-gorules stefan-gorules deleted the feat/merge-function branch March 15, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants