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

cast_xyz functions in language reference are confusing #1405

Closed
tsandall opened this issue May 3, 2019 · 3 comments · Fixed by #1528
Closed

cast_xyz functions in language reference are confusing #1405

tsandall opened this issue May 3, 2019 · 3 comments · Fixed by #1528
Assignees

Comments

@tsandall
Copy link
Member

tsandall commented May 3, 2019

Users frequently think they should use the cast_xyz functions to convert from one type to another however the cast functions have somewhat inconsistent behaviour:

func accepts returns
cast_null any null or error if input is not null
cast_boolean any boolean or error if input is not boolean
cast_string any string or error if input is not string
cast_set any set or error if input is not set or array
cast_array any array or error if input is not set or array
cast_object any object or error if input is not object

cast_number is not defined.

I don't think these functions are worth the confusion they introduce. We should remove them from the docs and deprecate them.

@tsandall tsandall self-assigned this Jun 27, 2019
tsandall added a commit to tsandall/opa that referenced this issue Jun 27, 2019
Fixes open-policy-agent#1405

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
tsandall added a commit that referenced this issue Jun 27, 2019
Fixes #1405

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
@GBrawl
Copy link
Contributor

GBrawl commented Mar 20, 2020

Hey @tsandall, I'm currently using the cast_set function to cast an array to a set so I can perform functions like intersection. Can you tell me what the alternative is now that cast_set is deprecated?

@tsandall
Copy link
Member Author

@GBrawl you can you write a simple comprehension that converts the array into a set:

a_set := {x | x := arr[_]}

@GBrawl
Copy link
Contributor

GBrawl commented Mar 20, 2020

That works well, thanks!

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

Successfully merging a pull request may close this issue.

2 participants