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

Behavior for specs defined as set literals #7

Closed
vemv opened this issue May 19, 2018 · 3 comments
Closed

Behavior for specs defined as set literals #7

vemv opened this issue May 19, 2018 · 3 comments

Comments

@vemv
Copy link
Contributor

vemv commented May 19, 2018

Hi, thanks for the library!

Given this spec:

(spec/def ::orientation #{:north :south :east :west})

...spec-coerce cannot coerce "north" into :north.

Is that expected behavior?

One trickier case would be (spec/def ::foo #{:north 1 "s"}). OTOH such an heterogeneous set would be probably universally bad - spec/or should be used instead.

Cheers - Victor

@wilkerlucio
Copy link
Owner

Hello @vemv.

From sets, it's tricky like you said, but there is one way out, you can compose the spec like this:

(s/def ::orientation (s/and keyword? #{:north :south :east :west}))

This way the coerce will use the keyword? first to do the coercion, what you think?

@vemv
Copy link
Contributor Author

vemv commented May 19, 2018

Tried out, works for me!

Thank you.

Feel free to close the issue

@wilkerlucio
Copy link
Owner

Cool.

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

2 participants