Skip to content

using defaults to solve disjunction #3444

Answered by mvdan
hansbogert asked this question in Q&A
Discussion options

You must be logged in to vote

This is how I would typically write what you want to do, by having the default on the disjunction between the two definitions: https://cuelang.org/play/?id=OVi9f4ylQBz#w=function&i=cue&f=eval&o=cue

As for why your original example isn't working as you might think, I'm actually not sure. Here is a simpler example showing an ambiguous result in a similar way:

#schema: f: *1 | 2
#one: f: 1
#two: f: 2
out: #schema & (#one | #two)

Interestingly enough, if I drop all f: fields, then the output is unambiguously 1. The ambiguity only appears with the nesting of a struct field.

Replies: 1 comment 1 reply

Comment options

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

Answer selected by hansbogert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants