This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-20
Channels
- # announcements (42)
- # babashka (70)
- # beginners (152)
- # chlorine-clover (19)
- # cider (14)
- # clj-kondo (23)
- # clojars (15)
- # clojure (86)
- # clojure-denmark (1)
- # clojure-dev (5)
- # clojure-europe (57)
- # clojure-france (145)
- # clojure-hungary (2)
- # clojure-italy (5)
- # clojure-nl (7)
- # clojure-spec (35)
- # clojure-sweden (2)
- # clojure-uk (58)
- # clojurebridge (1)
- # clojured (1)
- # clojurescript (50)
- # core-typed (9)
- # cursive (10)
- # data-science (11)
- # datascript (4)
- # datomic (25)
- # emacs (8)
- # fulcro (49)
- # graalvm (7)
- # graphql (6)
- # joker (1)
- # juxt (2)
- # kaocha (1)
- # off-topic (22)
- # other-lisps (1)
- # pathom (20)
- # re-frame (3)
- # reagent (11)
- # reitit (2)
- # remote-jobs (1)
- # shadow-cljs (44)
- # spacemacs (2)
- # sql (17)
- # tree-sitter (2)
- # vim (8)
- # vrac (2)
hmm…
I’m wanting to spec some data that is coming from a 3rd party library, the Ataraxy router.
It always uses the namespaced keyword :ataraxy/result
to contain the parsed parameters for the route; however because ataraxy is configured on a route by route basis; the exact data structure differs, yet the ring request map always contains the same namespaced keyword.
It strikes me that this is an unfortunate mistake; in that the same global keyword is being used to name different data.
What is the best way to spec such a thing?
I’m thinking a multispec is really the only option, that could dispatch on the first
argument. :ataraxy/result
is a vector of the form [:route/id ,,,route-params,,,]
or I suppose I could coerce it into something else first 😞
actually thinking it’s better to just spec the functions after it, that don’t depend on the :ataraxy/result
key.
you could just do something like (s/cat :route-id ::route-id :params (s/* any))
but it depends a lot what route-params is
if it's kwargs, then keys* would work great
my data looks like {::type "foobar" ::a ... ::b ... ::c ...} I want different s/keys validation based on the value of ::type whats the feature i'm looking for
(s/keys*) would automatically handle all registered specs for the tail of that
you can definitely use multi-spec for this if that makes sense
I don't understand enough what you're doing
what does :default mean?
(s/def ::tag #{:a :b :c :d})
(s/def ::example-key keyword?)
(s/def ::different-key keyword?)
(defmulti tagmm :tag)
(defmethod tagmm :a [_] (s/keys :req-un [::tag ::example-key]))
(defmethod tagmm :default [_] (s/keys :req-un [::tag ::different-key]))
(s/def ::example (s/multi-spec tagmm :tag))
(gen/sample (s/gen ::example))
here's the exampleoh, you mean multi-method default
the multimethod returns specs so you need to return a spec that always fails
so probably more (constantly false) would work
a set of no values :)
a q out of curiosity more than anything else:
(spec/valid? (spec/coll-of char? :min-count 1 :max-count 20) "abc")
doesn't work (and a straightforward impl would underperform anyway?)
are there spec-related libraries offering a coll-of
-like API that efficiently works on strings?
I just like coll-of
's API, in that it doesn't resemble regex