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

Generate definition from a for loop #937

Answered by myitcv
tbruyelle asked this question in Q&A
Discussion options

You must be logged in to vote

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: 2 comments 4 replies

Comment options

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

@myitcv
Comment options

@tbruyelle
Comment options

@myitcv
Comment options

Answer selected by tbruyelle
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