2018-05-12 18:39:29 +02:00
|
|
|
---
|
2020-08-15 03:51:06 +02:00
|
|
|
layout: "language"
|
2018-12-20 05:35:11 +01:00
|
|
|
page_title: "merge - Functions - Configuration Language"
|
2018-05-12 18:39:29 +02:00
|
|
|
sidebar_current: "docs-funcs-collection-merge"
|
|
|
|
description: |-
|
2020-02-05 19:45:49 +01:00
|
|
|
The merge function takes an arbitrary number maps or objects, and returns a
|
|
|
|
single map or object that contains a merged set of elements from all
|
|
|
|
arguments.
|
2018-05-12 18:39:29 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
# `merge` Function
|
|
|
|
|
2020-02-05 19:45:49 +01:00
|
|
|
`merge` takes an arbitrary number of maps or objects, and returns a single map
|
2020-02-14 03:27:35 +01:00
|
|
|
or object that contains a merged set of elements from all arguments.
|
2018-05-12 18:39:29 +02:00
|
|
|
|
2020-02-05 19:45:49 +01:00
|
|
|
If more than one given map or object defines the same key or attribute, then
|
|
|
|
the one that is later in the argument sequence takes precedence. If the
|
|
|
|
argument types do not match, the resulting type will be an object matching the
|
|
|
|
type structure of the attributes after the merging rules have been applied.
|
2018-05-12 18:39:29 +02:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```
|
2020-02-05 19:45:49 +01:00
|
|
|
> merge({a="b", c="d"}, {e="f", c="z"})
|
2018-05-12 18:39:29 +02:00
|
|
|
{
|
|
|
|
"a" = "b"
|
|
|
|
"c" = "z"
|
|
|
|
"e" = "f"
|
|
|
|
}
|
|
|
|
```
|
2020-02-05 19:45:49 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
> merge({a="b"}, {a=[1,2], c="z"}, {d=3})
|
|
|
|
{
|
|
|
|
"a" = [
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
]
|
|
|
|
"c" = "z"
|
|
|
|
"d" = 3
|
|
|
|
}
|
|
|
|
```
|