Skip to content

Commit

Permalink
docs/howto: use list.Concat
Browse files Browse the repository at this point in the history
This adds a Commented CUE guide demonstrating how to use list.Concat to
concatenate lists.

Preview-Path: /docs/howto/use-the-built-in-function-list-concat-to-concatenate-lists/
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I482a2a8669841b96069e87b74e68a7c3f01ee878
Dispatch-Trailer: {"type":"trybot","CL":1174726,"patchset":17,"ref":"refs/changes/26/1174726/17","targetBranch":"alpha"}
  • Loading branch information
jpluscplusm authored and cueckoo committed Jan 24, 2024
1 parent 5641e2e commit b3c484e
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: Using the built-in function "list.Concat" to concatenate 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.Concat`](https://pkg.go.dev/cuelang.org/go/pkg/list#Concat)
to concatenate a list of lists.

{{{with code "en" "cc"}}}
exec cue export -e output
cmp stdout out
-- file.cue --
package example

import "list"

// list.Concat concatenates lists in the order
// they are provided, including re-processing
// repeated references.
output: list.Concat([listA, listB, listC, listB])

listA: [1, 2, 3, 4]
listB: ["hello", "world"]
listC: [{
a: 10
b: "10"
}, {
a: 11
b: "11"
}, {
a: 12
b: "12"
}]
-- out --
[
1,
2,
3,
4,
"hello",
"world",
{
"a": 10,
"b": "10"
},
{
"a": 11,
"b": "11"
},
{
"a": 12,
"b": "12"
},
"hello",
"world"
]
{{{end}}}

## Related content

- The [`list`](https://pkg.go.dev/cuelang.org/go/pkg/list) built-in package
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-concat-to-concatenate-lists": {
page: {
cache: {
code: {
cc: "C/lyu4iZepLe25cdtwys4yqUHAgG/bwTCED+emeN8u0="
}
}
}
}
}
}
}
}
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-concat-to-concatenate-lists": {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: Using the built-in function "list.Concat" to concatenate 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.Concat`](https://pkg.go.dev/cuelang.org/go/pkg/list#Concat)
to concatenate a list of lists.

{{< code-tabs >}}
{{< code-tab name="file.cue" language="cue" area="top-left" >}}
package example

import "list"

// list.Concat concatenates lists in the order
// they are provided, including re-processing
// repeated references.
output: list.Concat([listA, listB, listC, listB])

listA: [1, 2, 3, 4]
listB: ["hello", "world"]
listC: [{
a: 10
b: "10"
}, {
a: 11
b: "11"
}, {
a: 12
b: "12"
}]
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="" type="terminal" area="top-right" >}}
$ cue export -e output
[
1,
2,
3,
4,
"hello",
"world",
{
"a": 10,
"b": "10"
},
{
"a": 11,
"b": "11"
},
{
"a": 12,
"b": "12"
},
"hello",
"world"
]
{{< /code-tab >}}
{{< /code-tabs >}}

## Related content

- The [`list`](https://pkg.go.dev/cuelang.org/go/pkg/list) built-in package

0 comments on commit b3c484e

Please sign in to comment.