Open jpluscplusm opened 8 months ago
Having played around with the code a fair bit, I actually prefer this:
import "list"
people: [
{name: "bob"},
{name: true},
{name: 1}
] & list.MaxItems(len(_uniqueNames))
_uniqueNames: {
for person in people { "\(person.name)": _ }
}
I prefer it because of the fact that people
directly references _uniqueNames
thus making it easy to discover, from people
where other constraints exist.
Also, using string interpolation means that it works with more than just strings. But, string interpolation throws away type information, which is bad, so eg this will fail:
people: [
{name: "1"},
{name: 1}
]
which is saddening.
incorporating some feedback from @mvdan , perhaps this is nicer:
import "list"
people: [
{name: "bob"},
{name: true},
{name: 1}
]
people: [...{name!: _}] & list.MaxItems(len(_uniqueNames))
_uniqueNames: {
for person in people { "\(person.name)": _ }
}
(and of course that _
can be changed to string
or whatever if required).
(relates to https://github.com/cue-lang/cue/issues/3538)
From a slack thread: https://cuelang.slack.com/archives/CLT3ULF6C/p1708094593391999?thread_ts=1708093684.648429&cid=CLT3ULF6C (not persisted here as the thread is wider than just this doc)
Original Slack thread
... or maybe this, which allows a set of specific fields to be checked whilst ignoring others:
The thread this came from was perf-related, so perhaps some tests at scale on the above 2 options might be useful to help decide the approach to be documented.