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

Use existing spec-coerce library for coercions #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

WhittlesJr
Copy link

@WhittlesJr WhittlesJr commented Sep 19, 2019

Here's my proposal to resolve #1 .

The spec-coerce library seems to me to be the most complete attempt at leveraging specs for data coercion. However, the interface is a bit more stringent than what cyrus-config has been accustomed to. Essentially, :spec should only be provided as a qualified keyword to a registered spec. Bare predicates (like int?) don't work in the way that cyrus-config has been using them in its tests and documentation.

So, in addition to deleting the parsing logic from cyrus-config and using sc/coerce! in its place, this PR updates the tests and documentation with the required usage thereof.

Personally, I see this as a positive change, as specs should almost always be registered to keywords using s/def anyway. So it's enforcing good code practice to an extent. Furthermore, spec-coerce's model of providing custom coercion decomplects the spec from the coercion:

(s/def ::json-coll-of-int (s/coll-of ::c/int)) ;; The spec
(sc/def ::json-coll-of-int json/parse-string)  ;; The coercion

vs

;; Spec and coercion conflated into one thing
(s/def ::json-coll-of-intn (from-custom-parser json/parse-string (s/coll-of int?))) 

This change is also pending a PR I made to spec-coerce.

@WhittlesJr
Copy link
Author

Here's the aforementioned PR:

wilkerlucio/spec-coerce#26

@WhittlesJr WhittlesJr force-pushed the spec-coerce branch 6 times, most recently from 5356289 to 0082fe7 Compare September 23, 2019 15:27
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

Successfully merging this pull request may close these issues.

Troubles with spec's coercion
1 participant