Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Questions about how to set multiple fields in a list with cue #1067

Answered by eonpatapon
cbrgm asked this question in Q&A
Discussion options

You must be logged in to vote

... 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.

// 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 (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).

users: {
	john: email:  "[email protected]"
	bob: email:   "[email protected]"
	alice: email: "[email protected]"
}

l1: [ for u, _ in users {u}]
l2: [ for u, _ in users

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@cbrgm
Comment options

Answer selected by cbrgm
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants