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

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

Answered by myitcv
gogommartin asked this question in General
Discussion options

You must be logged in to vote

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

Comment options

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

@mpvl
Comment options

@mpvl
Comment options

@seh
Comment options

Answer selected by gogommartin
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
Labels
None yet
5 participants