This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-11
Channels
- # announcements (8)
- # beginners (17)
- # boot (1)
- # cider (20)
- # cljdoc (7)
- # cljs-dev (14)
- # clojure (62)
- # clojure-dev (16)
- # clojure-hamburg (1)
- # clojure-russia (2)
- # clojure-spec (22)
- # clojure-uk (15)
- # clojurebridge (1)
- # clojurescript (23)
- # core-async (4)
- # core-logic (17)
- # cursive (2)
- # datomic (4)
- # duct (1)
- # figwheel-main (40)
- # fulcro (15)
- # leiningen (1)
- # off-topic (27)
- # re-frame (3)
- # shadow-cljs (9)
- # specter (3)
- # sql (59)
this spec used to work in 0.1.x (s/explain (s/and map? (s/+ (s/or :pair (s/cat :key keyword? :value boolean?)))) {:foo true})
but with 0.2.168 it fails predicate: (or (nil? %) (sequential? %))
I use that spec to conform some hash-map's key/value
but it looks like new clojure.spec use sequential? for s/+ therefore doesn't allow hash-maps
what should I do?
that spec is actually used to describe a flexible dsl composed of vectors and hash-maps (the dsl itself is used as part of om.next queries)
I can't think of any viable workaround
also, is there any reason clojure.spec use sequential?
there instead of coll?
which is almost identical except that it returns true for sets and maps?
@myguidingstar Why not just use (s/map-of keyword? boolean?)
(it took me a while to read your spec -- what does s/or
even mean with just one named branch?)
I wrote a post that covers this https://blog.taylorwood.io/2017/10/04/clojure-spec-boolean.html
@seancorfield yup, that s/or
is for named branch
I need to tag the key and value, hence the use of s/cat
so s/map-of
doesn't work for me
that spec's purpose is to used with s/conform
, kinda like a dsl parser, not just to check validation
@myguidingstar I wonder if (s/and map? seq (s/+ ...))
would make it so what you need?
I have specd a domain entity in my application and have to read instances encoded as JSON where the keys are without namespaces. What's the recommended way to validate and convert the JSON encoded instances to the internal representation?
@beta1036 I wrote a little library that uses spec to automatically qualify/unqualify domain entities. Given that JSON uses string keys, you’ll have to walk/keywordize-keys
first on your map as this library currently only works with keyword keys.
https://github.com/cjsauer/disqualified/blob/master/README.md
Correct. qualify-map
only translates unqualified keys into qualified keys. It doesn't do any conforming of its own. The source code is less than 50 lines in total if you'd like some inspiration for your own implementation:
https://github.com/cjsauer/disqualified/blob/master/src/cjsauer/disqualified.cljc#L32-L47
I've had a look. I'm afraid in order to extend it to my use case (embedded maps, collections, conjunctions, etc.) I'd have to re-implement a lot of spec. handling or
this way seems to be particularly tricky.
@beta1036 I wrote a little library that uses spec to automatically qualify/unqualify domain entities. Given that JSON uses string keys, you’ll have to walk/keywordize-keys
first on your map as this library currently only works with keyword keys.
https://github.com/cjsauer/disqualified/blob/master/README.md