Questions about how to set multiple fields in a list with cue #1067
-
Hello, I have a quick question about the following cue snippet. Given is a list with projects and configurations for the stages Dev, Int and Prd.
Furthermore, there is a global config that combines all three configs as a list. For the global config I would like to define the namespace once with cue and set it in each element in the list. After a bit of trial and error I have found that it either works like this:
or with this:
Did I understand correctly that Can anyone tell me when it is better to work with Sorry if this should be basics, I just started to learn a little bit about cue today. :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
// An open list of strings
// if not set it will default to an empty list
l1: [...string]
// A list of 2 strings
l2: [string, string]
// A list of at least one string
l3: [string, ...string] List comprehensions ( users: {
john: email: "[email protected]"
bob: email: "[email protected]"
alice: email: "[email protected]"
}
l1: [ for u, _ in users {u}]
l2: [ for u, _ in users {u}]
l3: [ for u, _ in users {u}]
You can also define a list of any value with: l: [..._] Which is the same as: l: [...] About your use-case it works it both cases thanks to unification. l1: MyList & [...{a: "foo"}]
l2: MyList & [for x in MyList { a: "bar" }] In the For this use-case I think the |
Beta Was this translation helpful? Give feedback.
-
This discussion has been migrated to cue-lang/cue#1067. For more details about CUE's migration to a new home, please see cue-lang/cue#1078. |
Beta Was this translation helpful? Give feedback.
...
just indicates that the list length can be as long as you want. We call this an open list, like structs can be open or closed. You can see this as a constrain.List comprehensions (
for
expressions) are used to create a list of values in a field. The result of the expression must conform to the constrain defined on this field (if any).