summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2019-10-10 22:21:59 -0400
committerDave Henderson <dhenderson@gmail.com>2019-10-10 23:09:04 -0400
commit73fc71c4b09d77522ee90f2253fe04486e423a95 (patch)
treea391c3a61c183d2f17b08b9e2ee9c898270e4eff /docs
parent64edc4ff89c5d6cc831842f4e612509e7db1d350 (diff)
New flatten/coll.Flatten function
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/content/functions/coll.md36
1 files changed, 36 insertions, 0 deletions
diff --git a/docs/content/functions/coll.md b/docs/content/functions/coll.md
index 869d95a7..6ce9645b 100644
--- a/docs/content/functions/coll.md
+++ b/docs/content/functions/coll.md
@@ -326,6 +326,42 @@ $ gomplate -i '{{ slice 1 2 3 2 3 4 1 5 | uniq }}'
[1 2 3 4 5]
```
+## `coll.Flatten`
+
+**Alias:** `flatten`
+
+Flatten a nested list. Defaults to completely flattening all nested lists,
+but can be limited with `depth`.
+
+_Note that this function does not change the given list; it always produces a new one._
+
+### Usage
+
+```go
+coll.Flatten [depth] list
+```
+```go
+list | coll.Flatten [depth]
+```
+
+### Arguments
+
+| name | description |
+|------|-------------|
+| `depth` | _(optional)_ maximum depth of nested lists to flatten. Omit or set to `-1` for infinite depth. |
+| `list` | _(required)_ the input list |
+
+### Examples
+
+```console
+$ gomplate -i '{{ "[[1,2],[],[[3,4],[[[5],6],7]]]" | jsonArray | flatten }}'
+[1 2 3 4 5 6 7]
+```
+```console
+$ gomplate -i '{{ coll.Flatten 2 ("[[1,2],[],[[3,4],[[[5],6],7]]]" | jsonArray) }}'
+[1 2 3 4 [[5] 6] 7]
+```
+
## `coll.Reverse`
**Alias:** `reverse`