Skip to content

Is there a better way to inject a default list value than what I've come up with so far? #399

Answered by cueckoo
cueckoo asked this question in General
Discussion options

You must be logged in to vote

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

Probably the simplest way to do this for now is as follows:

package x

#a: {
	#vals: [...{foo: string}]
	res: [{foo: "bar"}] + #vals
}

b: (#a & {#vals: [{foo: "baz"}]}).res

This has the added advantage that when CUE supports embedded scalars the res field can be dropped and this example would become:

package x

#a: {
	#vals: [...{foo: string}]
	[{foo: "bar"}] + #vals
}

b: #a & {#vals: [{foo: "baz"}]}

(with some variation because the concatenation of lists might well change to be defined in terms of list comprehensions).

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
Labels
None yet
1 participant