You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello @ikitommi , I found a nice ticket open (#111 ) and I wanted to give it a shot. This is a simplified implementation of unwrapping specs created from data-specs. I used multimethods to dispatch to common spec operators, but the current solution is not exhaustive therefore might have some possibilities not covered, need to check this out.
Some drawbacks.
The current solution is only working in clj basically because I can't get the function out of symbols in cljs (this situation again). I run the test in cljs and got the following error message for the simpler specs I wrote:
FAIL in (unspecing) (:)
simpler possible specs
expected: (= boolean? (ds/unspec (ds/spec {:name:spec-tools.data-spec-test/t1, :spec boolean?})))
actual: (not (= #object[cljs$core$boolean_QMARK_] cljs.core/boolean?))
As seems like cljs compile the boolean? function to a js object and I get a Symbol back from resolve macro in cljs.
There is also a minor drawback when clojure.specs are used as keys in the data-spec, for example:
As we can see the ::age keyword was transformed to a full form as clojure.core/post-int? therefore when I use (ds/unspec (ds/spec {:name ::test :spec ::age})) ;;=> #function[clojure.core/pos-int?]
It works, but is not the same as recovering the full qualified keyword that defined the pos-int? in the first place.
TODO: I would like to present this rationale for the solution to see if is viable in the long run, as well as discuss the unspec arity [I don't see why not only receive the spec itself, idk what kind of parameters would be nice to have as well]. After, I need to implement, ds/opt and ds/req over map keys.
Could not lose the opportunity to write a property-based test for the data-spec->spec->data-spec round trip. I found lots of corner cases in my first commit. Now should make changes to this code with a base solution as starting point.
I still don't totally get how a specific portion of a spec will be converted. The current solution has lots of hacks that I can probably clean up, the fact of existing so many ways to check and or create a spec is already complicated to me, s/spec?, st/spec?, fn?, s/get-spec, create-spec, if none works, try parse/parse-spec rsrsrs maybe this is part of the problem you were talking about at the malli presentation or maybe I am just not familiar enough yet :)
2020-04-09 EDIT: From my side, this is now ready to merge. If the drawbacks mentioned above is fine for you.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello @ikitommi , I found a nice ticket open (#111 ) and I wanted to give it a shot. This is a simplified implementation of unwrapping specs created from data-specs. I used multimethods to dispatch to common spec operators, but the current solution is not exhaustive therefore might have some possibilities not covered, need to check this out.
Some drawbacks.
cljbasically because I can't get the function out of symbols incljs(this situation again). I run the test in cljs and got the following error message for the simpler specs I wrote:As seems like cljs compile the
boolean?function to a js object and I get aSymbolback fromresolvemacro in cljs.As we can see the
::agekeyword was transformed to a full form asclojure.core/post-int?therefore when I use(ds/unspec (ds/spec {:name ::test :spec ::age})) ;;=> #function[clojure.core/pos-int?]It works, but is not the same as recovering the full qualified keyword that defined the pos-int? in the first place.
TODO: I would like to present this rationale for the solution to see if is viable in the long run, as well as discuss the
unspecarity [I don't see why not only receive the spec itself, idk what kind of parameters would be nice to have as well]. After, I need to implement,ds/optandds/reqover map keys.Thanks!