From 532d68b358743ba7462bc2229d502bcfc7b8e89d Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sun, 16 Jun 2024 21:17:14 -0400 Subject: feat(coll): New coll.Set and coll.Unset functions (#2118) Signed-off-by: Dave Henderson --- docs/content/functions/coll.md | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'docs/content') diff --git a/docs/content/functions/coll.md b/docs/content/functions/coll.md index 6448ac9b..a80d5a5f 100644 --- a/docs/content/functions/coll.md +++ b/docs/content/functions/coll.md @@ -706,3 +706,78 @@ $ gomplate -i '{{ $data := dict "foo" 1 "bar" 2 "baz" 3 }} {{ coll.Omit $keys $data }}' map[bar:2] ``` + +## `coll.Set`_(unreleased)_ +**Unreleased:** _This function is in development, and not yet available in released builds of gomplate._ + +**Alias:** `set` + +Sets the given key to the given value in the given map. + +The map is modified in place, and the modified map is returned. + +### Usage + +``` +coll.Set key value map +``` +``` +map | coll.Set key value +``` + +### Arguments + +| name | description | +|------|-------------| +| `key` | _(required)_ the key (string) to set | +| `value` | _(required)_ the value to set | +| `map` | _(required)_ the map to modify | + +### Examples + +```console +$ gomplate -i '{{ $data := dict "foo" 1 "bar" 2 }} +{{ coll.Set "baz" 3 $data }}' +map[bar:2 baz:3 foo:1] +``` +```console +$ gomplate -i '{{ dict "foo" 1 | coll.Set "bar" 2 }}' +map[bar:2 foo:1] +``` + +## `coll.Unset`_(unreleased)_ +**Unreleased:** _This function is in development, and not yet available in released builds of gomplate._ + +**Alias:** `unset` + +Deletes the element with the specified key in the given map. If there is no such element, the map is returned unchanged. + +The map is modified in place, and the modified map is returned. + +### Usage + +``` +coll.Unset key map +``` +``` +map | coll.Unset key +``` + +### Arguments + +| name | description | +|------|-------------| +| `key` | _(required)_ the key (string) to unset | +| `map` | _(required)_ the map to modify | + +### Examples + +```console +$ gomplate -i '{{ $data := dict "foo" 1 "bar" 2 "baz" 3 }} +{{ coll.Unset "bar" $data }}' +map[baz:3 foo:1] +``` +```console +$ gomplate -i '{{ dict "foo" 1 "bar" 2 | coll.Unset "bar" }}' +map[foo:1] +``` -- cgit v1.2.3