Skip to content

Commit

Permalink
docs: update documentation for new coll.Pick/Omit slice support (#2070)
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Henderson <[email protected]>
  • Loading branch information
hairyhenderson authored May 12, 2024
1 parent ab982b5 commit 607d4a6
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions docs/content/functions/coll.md
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ map[foo:1 bar:5 baz:4]

Given a map, returns a new map with any entries that have the given keys.

All keys are converted to strings.
The keys can either be separate arguments, or a slice (since v4.0.0).

This is the inverse of [`coll.Omit`](#coll-omit).

Expand All @@ -649,7 +649,7 @@ map | coll.Pick keys...

| name | description |
|------|-------------|
| `keys...` | _(required)_ the keys to match |
| `keys...` | _(required)_ the keys (strings) to match |
| `map` | _(required)_ the map to pick from |

### Examples
Expand All @@ -659,12 +659,18 @@ $ gomplate -i '{{ $data := dict "foo" 1 "bar" 2 "baz" 3 }}
{{ coll.Pick "foo" "baz" $data }}'
map[baz:3 foo:1]
```
```console
$ gomplate -i '{{ $data := dict "foo" 1 "bar" 2 "baz" 3 }}
{{ $keys := coll.Slice "foo" "baz" }}
{{ coll.Pick $keys $data }}'
map[baz:3 foo:1]
```

## `coll.Omit`

Given a map, returns a new map without any entries that have the given keys.

All keys are converted to strings.
The keys can either be separate arguments, or a slice (since v4.0.0).

This is the inverse of [`coll.Pick`](#coll-pick).

Expand All @@ -684,7 +690,7 @@ map | coll.Omit keys...

| name | description |
|------|-------------|
| `keys...` | _(required)_ the keys to match |
| `keys...` | _(required)_ the keys (strings) to match |
| `map` | _(required)_ the map to omit from |

### Examples
Expand All @@ -694,3 +700,9 @@ $ gomplate -i '{{ $data := dict "foo" 1 "bar" 2 "baz" 3 }}
{{ coll.Omit "foo" "baz" $data }}'
map[bar:2]
```
```console
$ gomplate -i '{{ $data := dict "foo" 1 "bar" 2 "baz" 3 }}
{{ $keys := coll.Slice "foo" "baz" }}
{{ coll.Omit $keys $data }}'
map[bar:2]
```

0 comments on commit 607d4a6

Please sign in to comment.