Skip to content

Generate definition from a for loop #937

Answered by cueckoo
cueckoo asked this question in Q&A
Discussion options

You must be logged in to vote

Original reply by @myitcv in cuelang/cue#937 (comment)

You can't currently declare definitions in this way, but you can make them part of an "outer" definition:

package x

#def: {
	let list = [ {name: "def1", args: 1}, {name: "def2", args: 2}]

	for _, v in list {
		"\(v.name)": {
			args: v.args
		}
	}
}
$ cue eval
#def: {
    def1: {
        args: 1
    }
    def2: {
        args: 2
    }
}

Replies: 1 comment 4 replies

Comment options

cueckoo
Jul 3, 2021
Collaborator Author

You must be logged in to vote
4 replies
@cueckoo
Comment options

cueckoo Jul 3, 2021
Collaborator Author

@cueckoo
Comment options

cueckoo Jul 3, 2021
Collaborator Author

@cueckoo
Comment options

cueckoo Jul 3, 2021
Collaborator Author

@cueckoo
Comment options

cueckoo Jul 3, 2021
Collaborator Author

Answer selected by cueckoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant