-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support a must() builtin #575
Comments
Original reply by @mpvl in cuelang/cue#575 (comment) I vote for |
Original reply by @jlongtine in cuelang/cue#575 (comment) I like |
Original reply by @extemporalgenome in cuelang/cue#575 (comment) I have been thinking about this issue as well, particularly around how That said, I wonder if the self-referential Pretend that strings.Contains, strings.Count, etc, accepted only explicit parameters (so we could express "receiver is contained by" using the same function in which we currently only express "receiver contains").
Pretend the author of the above intends the first However, since #Foo binds to the receiver, this really means that any matching concrete string must contain fewer than 7 occurrences of itself, which is certainly true, but not very useful to express. If we had a special symbol to refer to the receiver, we'd avoid this hypothetical issue, and potentially reduce reader confusion ("is this an unresolvable circular reference? I thought those were disallowed?"). Using the original example, perhaps we could have a notation for referring to the receiver, such as
Perhaps this is also worth a special symbol, for example
or an explicit form without a magic identifier:
(where x is a local binding for the receiver) |
Original reply by @bttk in cuelang/cue#575 (comment) I was surprised to learn that this is not what alias was used for:
|
Original reply by @myitcv in cuelang/cue#575 (comment) @bttk you can't use an alias in the following example:
The use of implicit parameters is missing from the spec, which I've raised as cuelang/cue#863 The intention of |
Original reply by @verdverm in cuelang/cue#575 (comment) @bttk There is an excellent write up on several related constructs (alias, let, hidden fields) here: cuelang/cue#699 (comment) |
Original reply by @myitcv in cuelang/cue#575 (comment) Good memory, @verdverm 😄 |
Tentatively marking this as v0.7.0 (so as not to delay v0.6.0). This has been a high priority feature request for some time, but has never fully made the cut. However, if we add up all the requirements that generally point this direction, there is significant value in addressing this sooner rather than later. |
Edited previous comment with change in milestone. |
Originally opened by @myitcv in cuelang/cue#575
This has come up various times on Slack, noting here for posterity (and so it can be referenced)
The name
must()
was also thrown into the 🚲 shed.Is your feature request related to a problem? Please describe.
Sometimes it is necessary to declare arbitrary constraints on a field.
Taking one such example from Slack, where we try to define
#Foo
as astring
that must contain a numeric value greater than5
:Describe the solution you'd like
As above.
Describe alternatives you've considered
The current alternative is to declare additional (hidden) definitions that express the constraint:
Contrast the proposed
constrain()
builtin which allows the constraint to be declared on the field itself, which is much clearer for the author, reader and user.Additional context
n/a
The text was updated successfully, but these errors were encountered: