Skip to content
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

Is there a way to ensure the lengths of two list arguments match? #381

Closed
cueckoo opened this issue Jul 3, 2021 · 4 comments
Closed

Is there a way to ensure the lengths of two list arguments match? #381

cueckoo opened this issue Jul 3, 2021 · 4 comments

Comments

@cueckoo
Copy link
Collaborator

cueckoo commented Jul 3, 2021

Originally opened by @riceluxs1t in cuelang/cue#381

Foo :: {
l1: [...string]
l2: [...string]
}

I want to make sure that instances of Foo have equal numbers of strings specified for l1 and l2. Is this possible to express in cuelang?

@cueckoo cueckoo closed this as completed Jul 3, 2021
@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @verdverm in cuelang/cue#381 (comment)

We generally answer questions in Slack. You can join from this link: https://cuelang.org/community

You can with an extra field:

ex: {
  l1: [...string]
  l2: [...string]
  sameLength: len(l1) == len(l2)
  failWhenDifferent: true & sameLength
}

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @myitcv in cuelang/cue#381 (comment)

@verdverm the check field should really be a definition to avoid it being emitted:

ex: {
	l1: [...string]
	l1: ["test"]
	l2: [...string]
	l2: ["test"]
	sameLength :: len(l1) == len(l2)
	sameLength :: true
}

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @myitcv in cuelang/cue#381 (comment)

I'll close this issue because we've address the direct question. There is also plans for a constrain() built-in as part of the evaluator redesign in #338

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @verdverm in cuelang/cue#381 (comment)

@myitcv would hidden fields work equally as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant