@merge(...treelikes)

Returns a tree that is the result of merging the indicated trees.

If you have two trees:

$ cat tree1.yaml
a: The letter A
b: The letter B
c: This will be overwritten when merged
$ cat tree2.yaml
c: The letter C
d: The letter D
e: The letter E

You can merge them into a single tree:

$ ori @merge tree1.yaml, tree2.yaml
a: The letter A
b: The letter B
c: The letter C
d: The letter D
e: The letter E

The keys of the merged tree are the unique keys of the constituent trees in the order the trees are given.

When asked for a key, the merged tree asks each of the constituent trees in reverse order for that key. If a tree returns a defined value for that key, that value is used. In this example, getting c returns the result from tree2.yaml, because that is the first tree (in reverse order) that defines a value for c.

g a The letter A ->a a b The letter B ->b b c The letter C ->c c d The letter D ->d d e The letter E ->e e
Merged tree

The Origami language also supports a spread operator that can perform the same kind of merge using ... three periods or the ellipsis character:

$ ori { ...tree1.yaml, ...tree2.yaml }
a: The letter A
b: The letter B
c: The letter C
d: The letter D
e: The letter E

The merge operation is shallow; for a deep merge operation, see @deepMerge.