Requires CUE v0.14.0 or later
CUE v0.14.0 introduced the structcmp
experiment,
which allows both forms of the ==
operator to compare structs.
The experiment needs to be enabled on a per-file basis, and behaves like this:
file.cue
@experiment(structcmp) // Enable the experiment.
package example
// The comparison operator can now compare
// concrete structs.
output: {
"a == a": a == a
"a == b": a == b
"a == c": a == c
"a == d": a == d
}
// The unary operator can now assert that one
// struct has the same concrete value as another.
a: ==b
a: foo: 1
b: foo: 1
c: {foo: 1, bar: 1}
d: foo: 2
TERMINAL
$ cue export -e output
{
"a == a": true,
"a == b": true,
"a == c": false,
"a == d": false
}
The ==
operator requires concrete operands,
otherwise evaluation fails:
file.cue
@experiment(structcmp)
package example
A: foo: 1
_B: foo: int
A: ==_B
C: A == _B
TERMINAL
$ cue export
A: invalid right-hand value to '==' (type struct): _B.foo: incomplete value int:
./file.cue:7:4
Related content
- Reference: cue help experiments