-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a Commented CUE demonstrating how to use list.FlattenN to expand a list's elements to different depths. Preview-Path: /docs/howto/use-the-built-in-function-list-flattenn-to-flatten-lists/ Signed-off-by: Jonathan Matthews <[email protected]> Change-Id: I97415642812fa137cd5c2dd4e6efadd3c5d80a3d
- Loading branch information
1 parent
50253be
commit 52e8869
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
content/docs/howto/use-the-built-in-function-list-flattenn-to-flatten-lists/en.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title: Using the built-in function "list.FlattenN" to flatten lists | ||
tags: | ||
- commented cue | ||
authors: | ||
- jpluscplusm | ||
toc_hide: true | ||
--- | ||
|
||
This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) | ||
demonstrates how to use the built-in function `list.FlattenN` to flatten a list | ||
by expanding its list elements down to a specified depth. | ||
|
||
{{{with code "en" "cc"}}} | ||
#location top bottom | ||
|
||
exec cue eval | ||
cmp stdout out | ||
-- file.cue -- | ||
package example | ||
|
||
import "list" | ||
|
||
// lSrc is a list (of lists (of lists ...)), defined below | ||
lSrc: [...] | ||
|
||
// eOne's first-level list elements are expanded | ||
eOne: list.FlattenN(lSrc, 1) | ||
// eTwo's first- and second-level list elements are expanded | ||
eTwo: list.FlattenN(lSrc, 2) | ||
// All of eNeg's list elements are expanded, no matter their depth | ||
eNeg: list.FlattenN(lSrc, -1) | ||
|
||
lSrc: [ | ||
1, 2, 3, | ||
["a", "b", "c"], | ||
[ | ||
[4, 5, 6], | ||
[ | ||
["d", "e", "f"], | ||
[[7, 8, 9]], | ||
], | ||
], | ||
[[[[["g", "h", "i"]]]]], | ||
] | ||
-- out -- | ||
lSrc: [1, 2, 3, ["a", "b", "c"], [[4, 5, 6], [["d", "e", "f"], [[7, 8, 9]]]], [[[[["g", "h", "i"]]]]]] | ||
eOne: [1, 2, 3, "a", "b", "c", [4, 5, 6], [["d", "e", "f"], [[7, 8, 9]]], [[[["g", "h", "i"]]]]] | ||
eTwo: [1, 2, 3, "a", "b", "c", 4, 5, 6, ["d", "e", "f"], [[7, 8, 9]], [[["g", "h", "i"]]]] | ||
eNeg: [1, 2, 3, "a", "b", "c", 4, 5, 6, "d", "e", "f", 7, 8, 9, "g", "h", "i"] | ||
{{{end}}} | ||
|
||
## Related content | ||
|
||
- The [`list`](https://pkg.go.dev/cuelang.org/go/pkg/list) built-in package |
18 changes: 18 additions & 0 deletions
18
content/docs/howto/use-the-built-in-function-list-flattenn-to-flatten-lists/gen_cache.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package site | ||
{ | ||
content: { | ||
docs: { | ||
howto: { | ||
"use-the-built-in-function-list-flattenn-to-flatten-lists": { | ||
page: { | ||
cache: { | ||
code: { | ||
cc: "uDB8YvMpfPhKTjlC0d1OMwsyU7fch7rZDptJJqZlji4=" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
content/docs/howto/use-the-built-in-function-list-flattenn-to-flatten-lists/page.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package site | ||
|
||
content: docs: howto: "use-the-built-in-function-list-flattenn-to-flatten-lists": {} |
54 changes: 54 additions & 0 deletions
54
...en/docs/howto/use-the-built-in-function-list-flattenn-to-flatten-lists/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: Using the built-in function "list.FlattenN" to flatten lists | ||
tags: | ||
- commented cue | ||
authors: | ||
- jpluscplusm | ||
toc_hide: true | ||
--- | ||
|
||
This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) | ||
demonstrates how to use the built-in function `list.FlattenN` to flatten a list | ||
by expanding its list elements down to a specified depth. | ||
|
||
{{< code-tabs >}} | ||
{{< code-tab name="file.cue" language="cue" area="top" >}} | ||
package example | ||
|
||
import "list" | ||
|
||
// lSrc is a list (of lists (of lists ...)), defined below | ||
lSrc: [...] | ||
|
||
// eOne's first-level list elements are expanded | ||
eOne: list.FlattenN(lSrc, 1) | ||
// eTwo's first- and second-level list elements are expanded | ||
eTwo: list.FlattenN(lSrc, 2) | ||
// All of eNeg's list elements are expanded, no matter their depth | ||
eNeg: list.FlattenN(lSrc, -1) | ||
|
||
lSrc: [ | ||
1, 2, 3, | ||
["a", "b", "c"], | ||
[ | ||
[4, 5, 6], | ||
[ | ||
["d", "e", "f"], | ||
[[7, 8, 9]], | ||
], | ||
], | ||
[[[[["g", "h", "i"]]]]], | ||
] | ||
{{< /code-tab >}} | ||
{{< code-tab name="TERMINAL" language="" type="terminal" area="bottom" >}} | ||
$ cue eval | ||
lSrc: [1, 2, 3, ["a", "b", "c"], [[4, 5, 6], [["d", "e", "f"], [[7, 8, 9]]]], [[[[["g", "h", "i"]]]]]] | ||
eOne: [1, 2, 3, "a", "b", "c", [4, 5, 6], [["d", "e", "f"], [[7, 8, 9]]], [[[["g", "h", "i"]]]]] | ||
eTwo: [1, 2, 3, "a", "b", "c", 4, 5, 6, ["d", "e", "f"], [[7, 8, 9]], [[["g", "h", "i"]]]] | ||
eNeg: [1, 2, 3, "a", "b", "c", 4, 5, 6, "d", "e", "f", 7, 8, 9, "g", "h", "i"] | ||
{{< /code-tab >}} | ||
{{< /code-tabs >}} | ||
|
||
## Related content | ||
|
||
- The [`list`](https://pkg.go.dev/cuelang.org/go/pkg/list) built-in package |