This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-04
Channels
- # beginners (8)
- # boot (20)
- # cider (8)
- # cljs-dev (263)
- # cljsjs (8)
- # cljsrn (20)
- # clojure (151)
- # clojure-argentina (1)
- # clojure-belgium (7)
- # clojure-dev (18)
- # clojure-italy (25)
- # clojure-spec (34)
- # clojure-uk (15)
- # clojurescript (89)
- # component (45)
- # core-async (27)
- # cursive (16)
- # datomic (53)
- # emacs (40)
- # figwheel (3)
- # hoplon (62)
- # jobs (1)
- # jobs-discuss (7)
- # luminus (8)
- # lumo (60)
- # off-topic (3)
- # parinfer (1)
- # precept (1)
- # protorepl (15)
- # re-frame (37)
- # reagent (7)
- # ring (3)
- # ring-swagger (73)
- # slack-help (1)
- # specter (19)
- # sql (4)
- # test-check (10)
- # uncomplicate (2)
- # unrepl (14)
- # untangled (52)
- # vim (5)
- # yada (42)
how do you properly spec a structure where the contents depend on type of one of the fields? E.g.
(def m {:standard/source :the-source, :standard/content {:standard.content/details {... specific to :the-source ...}})
I’d like to make a spec for :standard.content/details
based on :the-source
I can’t see the way out except for having :standard.content/details
renamed to :the-source/details
- is there any?
Sounds like a job for multi-spec
is it just me or does (s/keys :req [(or ::foo ::bar)])
default generator always generate both ::foo
and ::bar
rather than one or the other, and both?
I appreciate there are other ways to write this by moving the or over two keys specs
thanks
(s/def ::test (s/conformer (fn [q] q) (fn [q] (apply list q))))
(s/def ::test2 (s/map-of keyword? ::test))
(println (s/unform ::test [:a :b :c]))
(println (s/unform ::test2 {:some-key [:a :b :c]}))
The first unform works but not the second. Can anyone help?shouldn’t it be {::test [:a :b :c]}
forgive me it’s map-of
… seems strange then that it doesn’t work.
I also tried (println (s/unform ::test2 (s/conform ::test2 {:test [:a :b :c]})))
just in case.
Sorry, I'll rename that keyword to avoid confusion.
@danielstockton it's already been fixed in the latest spec version
I'm on alpha17, has it been released?
Ok, will do, thanks.
nevermind, this seems to be a different bug than the one I was thinking about (https://dev.clojure.org/jira/browse/CLJ-2076)
It looks pretty similar.
Me too, I think I need cljs.spec
Yes, I updated to the latest cljs and it works. Thanks!
I think I may have found another bug in conform/unform:
(s/def ::join-key (s/or :prop keyword? :ident ::ident))
(s/def ::join (s/map-of ::join-key ::query))
(s/def ::query-expr
(s/or :prop keyword?
:join ::join))
(s/def ::query
(s/or :query (s/and (s/conformer #(if (vector? %)
%
:clojure.spec/invalid)
list)
(s/+ ::query-expr))
:not-query nil?))
(println (s/conform ::join {:a [:b]}))
(println (s/unform ::join (s/conform ::join {:a [:b]})))
Uncaught Error: nth not supported on this type cljs.core/Keyword
It seems to be due to ::join-key
in map-of, if I replace that with keyword?
then it works.Oh no, sorry. I need to read the documentation better. There is an option to conform keys for map-of.
Perhaps it shouldn't throw an error though?
If the key isn't conformed, unform could just return it as is.
Hi all. Has anyone come up with an elegant way of specifying :args
to a zero-arity function?
(s/fdef f
:args empty? ; kinda cryptic, no?
:ret map?)
empty?
kinda does what I need I think because it'd end up applying an empty list of args to the function, but that seems a little cryptic.Maybe I'll create ::none
somewhere in my codebase to return an empty collection (s/coll-of any? :count 0 :into [])
.
@jcf (s/cat)
?